2013-08-09 19:23:46 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
|
2014-02-13 18:46:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-08-09 19:23:46 +04:00
|
|
|
#include "mozilla/layers/GrallocTextureClient.h"
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
|
|
|
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
|
|
|
|
#include "gfx2DGlue.h"
|
2014-02-13 18:46:59 +04:00
|
|
|
#include "gfxASurface.h"
|
|
|
|
#include "gfxImageSurface.h" // for gfxImageSurface
|
|
|
|
#include "GrallocImages.h"
|
2013-08-09 19:23:46 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-31 13:06:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2013-08-09 19:23:46 +04:00
|
|
|
using namespace android;
|
|
|
|
|
2013-09-12 18:50:28 +04:00
|
|
|
class GraphicBufferLockedTextureClientData : public TextureClientData {
|
|
|
|
public:
|
|
|
|
GraphicBufferLockedTextureClientData(GraphicBufferLocked* aBufferLocked)
|
|
|
|
: mBufferLocked(aBufferLocked)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(GrallocTextureClientData);
|
|
|
|
}
|
|
|
|
|
|
|
|
~GraphicBufferLockedTextureClientData()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GrallocTextureClientData);
|
|
|
|
MOZ_ASSERT(!mBufferLocked, "Forgot to unlock the GraphicBufferLocked?");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DeallocateSharedData(ISurfaceAllocator*) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
mBufferLocked = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<GraphicBufferLocked> mBufferLocked;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GrallocTextureClientData : public TextureClientData {
|
|
|
|
public:
|
|
|
|
GrallocTextureClientData(GrallocBufferActor* aActor)
|
|
|
|
: mGrallocActor(aActor)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(GrallocTextureClientData);
|
|
|
|
}
|
|
|
|
|
|
|
|
~GrallocTextureClientData()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GrallocTextureClientData);
|
|
|
|
MOZ_ASSERT(!mGrallocActor, "Forgot to unlock the GraphicBufferLocked?");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DeallocateSharedData(ISurfaceAllocator* allocator) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
// We just need to wrap the actor in a SurfaceDescriptor because that's what
|
|
|
|
// ISurfaceAllocator uses as input, we don't care about the other parameters.
|
|
|
|
SurfaceDescriptor sd = SurfaceDescriptorGralloc(nullptr, mGrallocActor,
|
2013-12-31 13:06:12 +04:00
|
|
|
IntSize(0, 0),
|
|
|
|
false, false);
|
2013-09-12 18:50:28 +04:00
|
|
|
allocator->DestroySharedSurface(&sd);
|
|
|
|
mGrallocActor = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrallocBufferActor* mGrallocActor;
|
|
|
|
};
|
|
|
|
|
|
|
|
TextureClientData*
|
|
|
|
GrallocTextureClientOGL::DropTextureData()
|
|
|
|
{
|
|
|
|
if (mBufferLocked) {
|
|
|
|
TextureClientData* result = new GraphicBufferLockedTextureClientData(mBufferLocked);
|
|
|
|
mBufferLocked = nullptr;
|
|
|
|
mGrallocActor = nullptr;
|
|
|
|
mGraphicBuffer = nullptr;
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
TextureClientData* result = new GrallocTextureClientData(mGrallocActor);
|
|
|
|
mGrallocActor = nullptr;
|
|
|
|
mGraphicBuffer = nullptr;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
GrallocTextureClientOGL::GrallocTextureClientOGL(GrallocBufferActor* aActor,
|
|
|
|
gfx::IntSize aSize,
|
2014-03-18 01:35:20 +04:00
|
|
|
gfx::BackendType aMoz2dBackend,
|
2013-08-09 19:23:46 +04:00
|
|
|
TextureFlags aFlags)
|
2014-03-18 01:35:20 +04:00
|
|
|
: BufferTextureClient(nullptr, gfx::SurfaceFormat::UNKNOWN, aMoz2dBackend, aFlags)
|
2013-08-09 19:23:46 +04:00
|
|
|
, mMappedBuffer(nullptr)
|
|
|
|
{
|
|
|
|
InitWith(aActor, aSize);
|
|
|
|
MOZ_COUNT_CTOR(GrallocTextureClientOGL);
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:06:06 +04:00
|
|
|
GrallocTextureClientOGL::GrallocTextureClientOGL(ISurfaceAllocator* aAllocator,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
2014-03-18 01:35:20 +04:00
|
|
|
gfx::BackendType aMoz2dBackend,
|
2014-01-10 17:06:06 +04:00
|
|
|
TextureFlags aFlags)
|
2014-03-18 01:35:20 +04:00
|
|
|
: BufferTextureClient(aAllocator, aFormat, aMoz2dBackend, aFlags)
|
2013-08-09 19:23:46 +04:00
|
|
|
, mMappedBuffer(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(GrallocTextureClientOGL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GrallocTextureClientOGL::~GrallocTextureClientOGL()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GrallocTextureClientOGL);
|
2013-09-12 18:50:35 +04:00
|
|
|
if (ShouldDeallocateInDestructor()) {
|
|
|
|
// If the buffer has never been shared we must deallocate it or it would
|
|
|
|
// leak.
|
2014-01-21 22:53:48 +04:00
|
|
|
if (!mBufferLocked) {
|
2013-09-12 18:50:35 +04:00
|
|
|
// We just need to wrap the actor in a SurfaceDescriptor because that's what
|
|
|
|
// ISurfaceAllocator uses as input, we don't care about the other parameters.
|
|
|
|
SurfaceDescriptor sd = SurfaceDescriptorGralloc(nullptr, mGrallocActor,
|
2013-12-31 13:06:12 +04:00
|
|
|
IntSize(0, 0),
|
|
|
|
false, false);
|
2014-01-10 17:06:06 +04:00
|
|
|
|
|
|
|
ISurfaceAllocator* allocator = GetAllocator();
|
|
|
|
allocator->DestroySharedSurface(&sd);
|
2013-09-12 18:50:35 +04:00
|
|
|
}
|
|
|
|
}
|
2013-08-09 19:23:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GrallocTextureClientOGL::InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(!IsAllocated());
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-08-09 19:23:46 +04:00
|
|
|
mGrallocActor = aActor;
|
|
|
|
mGraphicBuffer = aActor->GetGraphicBuffer();
|
|
|
|
mSize = aSize;
|
|
|
|
}
|
|
|
|
|
2013-09-12 18:50:28 +04:00
|
|
|
void
|
|
|
|
GrallocTextureClientOGL::SetGraphicBufferLocked(GraphicBufferLocked* aBufferLocked)
|
|
|
|
{
|
|
|
|
mBufferLocked = aBufferLocked;
|
|
|
|
}
|
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-08-09 19:23:46 +04:00
|
|
|
if (!IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aOutDescriptor = NewSurfaceDescriptorGralloc(nullptr, mGrallocActor, mSize);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:46:59 +04:00
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::UpdateSurface(gfxASurface* aSurface)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
MOZ_ASSERT(!IsImmutable());
|
|
|
|
MOZ_ASSERT(IsValid());
|
|
|
|
if (!IsValid() || !IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-19 06:36:58 +04:00
|
|
|
RefPtr<DrawTarget> dt = GetAsDrawTarget();
|
|
|
|
RefPtr<SourceSurface> source = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, aSurface);
|
2014-02-13 18:46:59 +04:00
|
|
|
|
2014-03-19 06:36:58 +04:00
|
|
|
dt->CopySurface(source, IntRect(IntPoint(), GetSize()), IntPoint());
|
2014-02-13 18:46:59 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-25 08:23:41 +04:00
|
|
|
void
|
|
|
|
GrallocTextureClientOGL::SetReleaseFenceHandle(FenceHandle aReleaseFenceHandle)
|
|
|
|
{
|
|
|
|
if (mBufferLocked) {
|
|
|
|
mBufferLocked->SetReleaseFenceHandle(aReleaseFenceHandle);
|
|
|
|
} else {
|
|
|
|
mReleaseFenceHandle = aReleaseFenceHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-27 05:01:15 +04:00
|
|
|
void
|
|
|
|
GrallocTextureClientOGL::WaitReleaseFence()
|
|
|
|
{
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
|
|
|
if (mReleaseFenceHandle.IsValid()) {
|
|
|
|
android::sp<Fence> fence = mReleaseFenceHandle.mFence;
|
|
|
|
#if ANDROID_VERSION == 17
|
|
|
|
fence->waitForever(1000, "GrallocTextureClientOGL::Lock");
|
|
|
|
// 1000 is what Android uses. It is warning timeout ms.
|
|
|
|
// This timeous is removed since ANDROID_VERSION 18.
|
|
|
|
#else
|
|
|
|
fence->waitForever("GrallocTextureClientOGL::Lock");
|
|
|
|
#endif
|
|
|
|
mReleaseFenceHandle = FenceHandle();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::Lock(OpenMode aMode)
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2014-01-24 18:25:04 +04:00
|
|
|
if (!IsValid() || !IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-13 18:46:59 +04:00
|
|
|
|
|
|
|
if (mMappedBuffer) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-25 08:23:41 +04:00
|
|
|
|
2014-03-27 05:01:15 +04:00
|
|
|
WaitReleaseFence();
|
2014-02-25 08:23:41 +04:00
|
|
|
|
2014-02-13 18:46:59 +04:00
|
|
|
uint32_t usage = 0;
|
|
|
|
if (aMode & OPEN_READ) {
|
|
|
|
usage |= GRALLOC_USAGE_SW_READ_OFTEN;
|
|
|
|
}
|
|
|
|
if (aMode & OPEN_WRITE) {
|
|
|
|
usage |= GRALLOC_USAGE_SW_WRITE_OFTEN;
|
|
|
|
}
|
|
|
|
int32_t rv = mGraphicBuffer->lock(usage, reinterpret_cast<void**>(&mMappedBuffer));
|
2013-08-09 19:23:46 +04:00
|
|
|
if (rv) {
|
2014-02-13 18:46:59 +04:00
|
|
|
mMappedBuffer = nullptr;
|
2013-08-09 19:23:46 +04:00
|
|
|
NS_WARNING("Couldn't lock graphic buffer");
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 20:20:11 +04:00
|
|
|
return BufferTextureClient::Lock(aMode);
|
2013-08-09 19:23:46 +04:00
|
|
|
}
|
2014-01-07 20:20:11 +04:00
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
void
|
|
|
|
GrallocTextureClientOGL::Unlock()
|
|
|
|
{
|
2014-01-07 20:20:11 +04:00
|
|
|
BufferTextureClient::Unlock();
|
2014-02-13 18:46:59 +04:00
|
|
|
mDrawTarget = nullptr;
|
|
|
|
if (mMappedBuffer) {
|
|
|
|
mMappedBuffer = nullptr;
|
|
|
|
mGraphicBuffer->unlock();
|
|
|
|
}
|
2013-08-09 19:23:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t*
|
|
|
|
GrallocTextureClientOGL::GetBuffer() const
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-08-09 19:23:46 +04:00
|
|
|
NS_WARN_IF_FALSE(mMappedBuffer, "Trying to get a gralloc buffer without getting the lock?");
|
|
|
|
return mMappedBuffer;
|
|
|
|
}
|
|
|
|
|
2014-02-13 18:46:59 +04:00
|
|
|
static gfx::SurfaceFormat
|
|
|
|
SurfaceFormatForPixelFormat(android::PixelFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aFormat) {
|
|
|
|
case PIXEL_FORMAT_RGBA_8888:
|
|
|
|
return gfx::SurfaceFormat::R8G8B8A8;
|
|
|
|
case PIXEL_FORMAT_BGRA_8888:
|
|
|
|
return gfx::SurfaceFormat::B8G8R8A8;
|
|
|
|
case PIXEL_FORMAT_RGBX_8888:
|
|
|
|
return gfx::SurfaceFormat::R8G8B8X8;
|
|
|
|
case PIXEL_FORMAT_RGB_565:
|
|
|
|
return gfx::SurfaceFormat::R5G6B5;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown gralloc pixel format");
|
|
|
|
}
|
|
|
|
return gfx::SurfaceFormat::R8G8B8A8;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<gfx::DrawTarget>
|
|
|
|
GrallocTextureClientOGL::GetAsDrawTarget()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsValid());
|
|
|
|
MOZ_ASSERT(mMappedBuffer, "Calling TextureClient::GetAsDrawTarget without locking :(");
|
|
|
|
|
|
|
|
if (mDrawTarget) {
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat format = SurfaceFormatForPixelFormat(mGraphicBuffer->getPixelFormat());
|
|
|
|
long pixelStride = mGraphicBuffer->getStride();
|
|
|
|
long byteStride = pixelStride * BytesPerPixel(format);
|
|
|
|
mDrawTarget = gfxPlatform::GetPlatform()->CreateDrawTargetForData(GetBuffer(),
|
|
|
|
mSize,
|
|
|
|
byteStride,
|
|
|
|
mFormat);
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
GrallocTextureClientOGL::GetAsSurface()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsValid());
|
|
|
|
MOZ_ASSERT(mMappedBuffer, "Calling TextureClient::GetAsSurface without locking :(");
|
|
|
|
|
|
|
|
gfx::SurfaceFormat format = SurfaceFormatForPixelFormat(mGraphicBuffer->getPixelFormat());
|
|
|
|
long pixelStride = mGraphicBuffer->getStride();
|
|
|
|
long byteStride = pixelStride * BytesPerPixel(format);
|
|
|
|
nsRefPtr<gfxImageSurface> surface =
|
|
|
|
new gfxImageSurface(GetBuffer(),
|
|
|
|
gfxIntSize(mSize.width, mSize.height),
|
|
|
|
byteStride,
|
|
|
|
SurfaceFormatToImageFormat(mFormat));
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
bool
|
2013-12-05 22:39:22 +04:00
|
|
|
GrallocTextureClientOGL::AllocateForSurface(gfx::IntSize aSize,
|
|
|
|
TextureAllocationFlags)
|
2013-08-09 19:23:46 +04:00
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-08-09 19:23:46 +04:00
|
|
|
|
|
|
|
uint32_t format;
|
2014-02-13 18:46:59 +04:00
|
|
|
uint32_t usage = android::GraphicBuffer::USAGE_SW_READ_OFTEN |
|
|
|
|
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
|
|
|
|
android::GraphicBuffer::USAGE_HW_TEXTURE;
|
2013-08-09 19:23:46 +04:00
|
|
|
|
|
|
|
switch (mFormat) {
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::R8G8B8A8:
|
2014-02-13 18:46:59 +04:00
|
|
|
format = android::PIXEL_FORMAT_RGBA_8888;
|
2013-08-09 19:23:46 +04:00
|
|
|
break;
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::B8G8R8A8:
|
2014-02-13 18:46:59 +04:00
|
|
|
format = android::PIXEL_FORMAT_RGBA_8888;
|
|
|
|
mFlags |= TEXTURE_RB_SWAPPED;
|
2013-08-09 19:23:46 +04:00
|
|
|
break;
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::R8G8B8X8:
|
2013-08-09 19:23:46 +04:00
|
|
|
format = android::PIXEL_FORMAT_RGBX_8888;
|
|
|
|
break;
|
2014-02-13 18:46:59 +04:00
|
|
|
case gfx::SurfaceFormat::B8G8R8X8:
|
|
|
|
format = android::PIXEL_FORMAT_RGBX_8888;
|
|
|
|
mFlags |= TEXTURE_RB_SWAPPED;
|
|
|
|
break;
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::R5G6B5:
|
2013-08-09 19:23:46 +04:00
|
|
|
format = android::PIXEL_FORMAT_RGB_565;
|
|
|
|
break;
|
2014-02-13 18:46:59 +04:00
|
|
|
case gfx::SurfaceFormat::A8:
|
|
|
|
NS_WARNING("gralloc does not support gfx::SurfaceFormat::A8");
|
|
|
|
return false;
|
2013-08-09 19:23:46 +04:00
|
|
|
default:
|
|
|
|
NS_WARNING("Unsupported surface format");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AllocateGralloc(aSize, format, usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-08-30 18:24:05 +04:00
|
|
|
GrallocTextureClientOGL::AllocateForYCbCr(gfx::IntSize aYSize, gfx::IntSize aCbCrSize, StereoMode aStereoMode)
|
2013-08-09 19:23:46 +04:00
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-08-09 19:23:46 +04:00
|
|
|
return AllocateGralloc(aYSize,
|
|
|
|
HAL_PIXEL_FORMAT_YV12,
|
|
|
|
android::GraphicBuffer::USAGE_SW_READ_OFTEN);
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:06:06 +04:00
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::AllocateForGLRendering(gfx::IntSize aSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsValid());
|
|
|
|
|
|
|
|
uint32_t format;
|
|
|
|
uint32_t usage = android::GraphicBuffer::USAGE_HW_RENDER |
|
|
|
|
android::GraphicBuffer::USAGE_HW_TEXTURE;
|
|
|
|
|
|
|
|
switch (mFormat) {
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::R8G8B8A8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8A8:
|
2014-01-10 17:06:06 +04:00
|
|
|
format = android::PIXEL_FORMAT_RGBA_8888;
|
|
|
|
break;
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::R8G8B8X8:
|
|
|
|
case gfx::SurfaceFormat::B8G8R8X8:
|
2014-01-10 17:06:06 +04:00
|
|
|
// there is no android BGRX format?
|
|
|
|
format = android::PIXEL_FORMAT_RGBX_8888;
|
|
|
|
break;
|
2014-01-10 23:06:16 +04:00
|
|
|
case gfx::SurfaceFormat::R5G6B5:
|
2014-01-10 17:06:06 +04:00
|
|
|
format = android::PIXEL_FORMAT_RGB_565;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Unsupported surface format");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AllocateGralloc(aSize, format, usage);
|
|
|
|
}
|
|
|
|
|
2013-08-09 19:23:46 +04:00
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::AllocateGralloc(gfx::IntSize aSize,
|
|
|
|
uint32_t aAndroidFormat,
|
|
|
|
uint32_t aUsage)
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2014-01-10 17:06:06 +04:00
|
|
|
ISurfaceAllocator* allocator = GetAllocator();
|
2013-08-09 19:23:46 +04:00
|
|
|
|
|
|
|
MaybeMagicGrallocBufferHandle handle;
|
|
|
|
PGrallocBufferChild* actor =
|
2013-12-20 20:46:28 +04:00
|
|
|
allocator->AllocGrallocBuffer(aSize,
|
2013-08-09 19:23:46 +04:00
|
|
|
aAndroidFormat,
|
|
|
|
aUsage,
|
|
|
|
&handle);
|
|
|
|
if (!actor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
GrallocBufferActor* gba = static_cast<GrallocBufferActor*>(actor);
|
|
|
|
gba->InitFromHandle(handle.get_MagicGrallocBufferHandle());
|
|
|
|
|
|
|
|
sp<GraphicBuffer> graphicBuffer = gba->GetGraphicBuffer();
|
|
|
|
if (!graphicBuffer.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (graphicBuffer->initCheck() != NO_ERROR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGrallocActor = gba;
|
|
|
|
mGraphicBuffer = graphicBuffer;
|
|
|
|
mSize = aSize;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::IsAllocated() const
|
|
|
|
{
|
|
|
|
return !!mGraphicBuffer.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GrallocTextureClientOGL::Allocate(uint32_t aSize)
|
|
|
|
{
|
|
|
|
// see Bug 908196
|
|
|
|
MOZ_CRASH("This method should never be called.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
GrallocTextureClientOGL::GetBufferSize() const
|
|
|
|
{
|
|
|
|
// see Bug 908196
|
|
|
|
MOZ_CRASH("This method should never be called.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namesapace layers
|
|
|
|
} // namesapace mozilla
|
|
|
|
|
|
|
|
#endif // MOZ_WIDGET_GONK
|