mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
95ae6701be
- Bug 1061525 - Part 1: Add support for planar MacIOSurfaces. r=BenWa (fc5a088be) - Bug 1061525 - Part 2: Make MacIOSurfaceTextureHostOGL understand planar MacIOSurfaces. r=jrmuizel (c4d50d77a) - Bg 1061525 - Part 3: Add shaders for NV12 to OGLShaderProgram. r=BenWa (9f8016472) - Bug 1061525 - Part 4: Add an NV12 effect, and implement it for CompositorOGL. r=nical (750037323) - Bug 1061525 - Part 5: Make the OSX video decoders output NV12 format MacIOSurfaces. r=jya (925c3f729) - Bug 1061525 - Part 6: Add readback code for converting NV12 MacIOSurfaces into RGB. r=nical (3e32a24b6) - Bug 1061525 - Part 7: Add software backed NV12 images support. r=mattwoodrow (71e98e1e6) - Bug 1146644 - Don't assert compiling a for-loop with a const loop-variable declaration. r=shu (c785e7a17) - Bug 1168666 - Update assertions to allow export specs to contain batch exports r=waldo (2740daa74) - Bug 1168474 - Remove assorted arity-checks that are easily done another way (or not at all). r=shu (76d3efe41) - Bug 1167823 - Remove dead code for checking whether a parse tree node has side effects. r=shu (a45be013c) - add back missing PNK_POD PNK_POWASSIGN in side effect checks (9b2a4317b) - Bug 1072898 - Part 2: Enable reftest for non-accelerated layers. r=mattwoodrow (26dedc262) - Bug 1201183 - handle font family name OOM error. r=nfroyd (dc6c72ba9)
104 lines
3.5 KiB
C++
104 lines
3.5 KiB
C++
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "MacIOSurfaceImage.h"
|
|
#include "mozilla/layers/CompositableClient.h"
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
|
#include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
|
|
#include "YCbCrUtils.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::layers;
|
|
using namespace mozilla::gfx;
|
|
|
|
TextureClient*
|
|
MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient)
|
|
{
|
|
if (!mTextureClient) {
|
|
mTextureClient = MacIOSurfaceTextureClientOGL::Create(aClient->GetForwarder(),
|
|
TextureFlags::DEFAULT,
|
|
mSurface);
|
|
}
|
|
return mTextureClient;
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
MacIOSurfaceImage::GetAsSourceSurface()
|
|
{
|
|
RefPtr<DataSourceSurface> dataSurface;
|
|
mSurface->Lock();
|
|
size_t bytesPerRow = mSurface->GetBytesPerRow();
|
|
size_t ioWidth = mSurface->GetDevicePixelWidth();
|
|
size_t ioHeight = mSurface->GetDevicePixelHeight();
|
|
|
|
SurfaceFormat format = mSurface->GetFormat() == SurfaceFormat::NV12 ? SurfaceFormat::B8G8R8X8 : SurfaceFormat::B8G8R8A8;
|
|
|
|
dataSurface = Factory::CreateDataSourceSurface(IntSize(ioWidth, ioHeight), format);
|
|
if (NS_WARN_IF(!dataSurface)) {
|
|
return nullptr;
|
|
}
|
|
|
|
DataSourceSurface::MappedSurface mappedSurface;
|
|
if (!dataSurface->Map(DataSourceSurface::WRITE, &mappedSurface))
|
|
return nullptr;
|
|
|
|
if (mSurface->GetFormat() == SurfaceFormat::NV12) {
|
|
if (mSurface->GetDevicePixelWidth() > PlanarYCbCrImage::MAX_DIMENSION ||
|
|
mSurface->GetDevicePixelHeight() > PlanarYCbCrImage::MAX_DIMENSION) {
|
|
return nullptr;
|
|
}
|
|
|
|
/* Extract and separate the CbCr planes */
|
|
size_t cbCrStride = mSurface->GetBytesPerRow(1);
|
|
size_t cbCrWidth = mSurface->GetDevicePixelWidth(1);
|
|
size_t cbCrHeight = mSurface->GetDevicePixelHeight(1);
|
|
|
|
nsAutoArrayPtr<uint8_t> cbPlane(new uint8_t[cbCrWidth * cbCrHeight]);
|
|
nsAutoArrayPtr<uint8_t> crPlane(new uint8_t[cbCrWidth * cbCrHeight]);
|
|
|
|
uint8_t* src = (uint8_t*)mSurface->GetBaseAddressOfPlane(1);
|
|
uint8_t* cbDest = cbPlane;
|
|
uint8_t* crDest = crPlane;
|
|
|
|
for (size_t i = 0; i < cbCrHeight; i++) {
|
|
uint8_t* rowSrc = src + cbCrStride * i;
|
|
for (size_t j = 0; j < cbCrWidth; j++) {
|
|
*cbDest = *rowSrc;
|
|
cbDest++;
|
|
rowSrc++;
|
|
*crDest = *rowSrc;
|
|
crDest++;
|
|
rowSrc++;
|
|
}
|
|
}
|
|
|
|
/* Convert to RGB */
|
|
PlanarYCbCrData data;
|
|
data.mYChannel = (uint8_t*)mSurface->GetBaseAddressOfPlane(0);
|
|
data.mYStride = mSurface->GetBytesPerRow(0);
|
|
data.mYSize = IntSize(mSurface->GetDevicePixelWidth(0), mSurface->GetDevicePixelHeight(0));
|
|
data.mCbChannel = cbPlane;
|
|
data.mCrChannel = crPlane;
|
|
data.mCbCrStride = cbCrWidth;
|
|
data.mCbCrSize = IntSize(cbCrWidth, cbCrHeight);
|
|
data.mPicSize = data.mYSize;
|
|
|
|
ConvertYCbCrToRGB(data, SurfaceFormat::B8G8R8X8, IntSize(ioWidth, ioHeight), mappedSurface.mData, mappedSurface.mStride);
|
|
} else {
|
|
unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress();
|
|
|
|
for (size_t i = 0; i < ioHeight; ++i) {
|
|
memcpy(mappedSurface.mData + i * mappedSurface.mStride,
|
|
ioData + i * bytesPerRow,
|
|
ioWidth * 4);
|
|
}
|
|
}
|
|
|
|
dataSurface->Unmap();
|
|
mSurface->Unlock();
|
|
|
|
return dataSurface.forget();
|
|
}
|