mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
8f529f64f5
- Bug 932865 - Add ThreadHangStats for collecting background hang telemetry; r=vladan (2f08a076b)
- Bug 932865 - Add way for telemetry to iterate over active threads; r=froydnj (535615d3d)
- Bug 1128768: Part 3 - Update BHR to allow for hang annotations; r=vladan (0b880a667)
- Bug 935092 - Add ThreadStackHelper to get a thread's pesudo-stack; r=BenWa (1422cfe4d)
- Bug 942488 - Don't report pseudo-stacks without SPS profiler. r=nchen (e160a7a08)
- Bug 946817 - Don't assert mPseudoStack on B2G. r=BenWa (9f846df3b)
- Bug 951431 - Don't get stacks during profiler runs on Linux; r=BenWa (15036e907)
- Bug 978262 - Ignore duplicate frames when getting BHR stack. r=froydnj (964721b1b)
- Bug 985155 - Add signal trampoline on ARM Linux to work around kernel bug. r=snorp (cb8a7846c)
- Bug 995730 - Convert xpcom/threads/ to Gecko style. r=froydnj (fe150404e)
- Bug 1013326 - Distinguish chrome and content scripts in pseudostack; r=snorp (81273c977)
- Bug 1023461 - Remove temporary stack buffer in ThreadStackHelper; r=snorp (cf5a717c2)
- Bug 1023461 - Record filename and line number for chrome JS entries; r=snorp (10c89808f)
- Bug 1022456 - Fix modelines in xpcom/{base,glue,io,string,threads}/. (48dbc0416)
- Bug 1016441 - Switch to using real-time signal in ThreadStackHelper; (2c5f818be)
- Bug 1016629 - b. Use RAII class to assign mStackToFill; r=snorp (769eae130)
- Bug 1016629 - c. Add define for ThreadStackHelper pseudostack support; r=snorp (67def0d2f)
- Bug 1016629 - d. Add and implement GetNativeStack method in ThreadStackHelper; r=snorp r=jseward (46c52f2be)
- Bug 1016629 - e. Implement platform-specific code for filling in context; r=snorp r=jseward (e6a66858b)
- Bug 1016629 - g. Avoid ASan flag when copying stack; r=snorp (0159628b5)
- Bug 1045176 - Unbreak build on non-SPS platforms after bug 1016629. (f1d60d838)
- Bug 1047123 - ThreadStackHelper should use UniquePtr<uint8_t[]>, not ScopedDeleteArray. r=jchen (0e4af313c)
- Bug 1049161 - Fix ThreadStackHelper thread handle permissions on Windows; r=snorp (c05172b1c)
- Bug 1050185 - Make ThreadStackHelper::FillThreadContext Valgrind-friendly. r=nchen (368725774)
- Bug 1050440 - Remove repeated js::RunScript frames in ThreadStackHelper (2a79600b3)
- Bug 1046841 - Fix more style violations in previously touched .cpp files in xpcom/. r=froydnj (02afe2493)
- Bug 1069694 - Remove or move around functions in OldDebugAPI. r=shu (177197302)
- Bug 1069694 - Remove OldDebugAPI from the browser. r=shu (b8c917d42)
- Bug 1100911 - For MacOS builds running on Valgrind, make ThreadStackHelper::GetStack be a no-op. r=nchen. (d99c02e16)
- Bug 1091758 - Report full paths for most chrome scripts; r=snorp (2b72e7878)
- Bug 1109291 - Include better paths for hanging chrome scripts in profile extensions directory; r=snorp r=bsmedberg (1997b9532)
- Bug 1113416 - Don't read stack labels inside hang monitor sighandler; r=nfroyd r=snorp (9688f6069)
- bug 1146027 - more final r=froydnj (7b0f295e5)
- Bug 1164090 - Check for Windows path separator in BHR file name; r=snorp (f014b4d78)
- Bug 1169034 - include <cstdlib> in ThreadStackHelper.cpp to declare correct overload for std::abs; r=jseward (874d4447e)
- Bug 1182996 - Fix and add missing namespace comments. rs=ehsan (054fc00b2)
- Bug 932865 - Collect thread hang stats in BackgroundHangMonitor; (ac80c8e9f)
- minor anticipated fixes to get it compiling (2bd701d15)
575 lines
14 KiB
C++
575 lines
14 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 "ImageContainer.h"
|
|
#include <string.h> // for memcpy, memset
|
|
#include "GLImages.h" // for SurfaceTextureImage
|
|
#include "gfx2DGlue.h"
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
|
#include "gfxUtils.h" // for gfxUtils
|
|
#include "mozilla/RefPtr.h" // for already_AddRefed
|
|
#include "mozilla/ipc/CrossProcessMutex.h" // for CrossProcessMutex, etc
|
|
#include "mozilla/layers/CompositorTypes.h"
|
|
#include "mozilla/layers/ImageBridgeChild.h" // for ImageBridgeChild
|
|
#include "mozilla/layers/ImageClient.h" // for ImageClient
|
|
#include "nsISupportsUtils.h" // for NS_IF_ADDREF
|
|
#include "YCbCrUtils.h" // for YCbCr conversions
|
|
#ifdef MOZ_WIDGET_GONK
|
|
#include "GrallocImages.h"
|
|
#endif
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_CAMERA) && defined(MOZ_WEBRTC)
|
|
#include "GonkCameraImage.h"
|
|
#endif
|
|
#include "gfx2DGlue.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "mozilla/CheckedInt.h"
|
|
|
|
#ifdef XP_MACOSX
|
|
#include "mozilla/gfx/QuartzSupport.h"
|
|
#include "MacIOSurfaceImage.h"
|
|
#endif
|
|
|
|
#ifdef XP_WIN
|
|
#include "gfxD2DSurface.h"
|
|
#include "gfxWindowsPlatform.h"
|
|
#include <d3d10_1.h>
|
|
#include "D3D9SurfaceImage.h"
|
|
#include "D3D11ShareHandleImage.h"
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
namespace layers {
|
|
|
|
using namespace mozilla::ipc;
|
|
using namespace android;
|
|
using namespace mozilla::gfx;
|
|
|
|
Atomic<int32_t> Image::sSerialCounter(0);
|
|
|
|
already_AddRefed<Image>
|
|
ImageFactory::CreateImage(ImageFormat aFormat,
|
|
const gfx::IntSize &,
|
|
BufferRecycleBin *aRecycleBin)
|
|
{
|
|
nsRefPtr<Image> img;
|
|
#ifdef MOZ_WIDGET_GONK
|
|
if (aFormat == ImageFormat::GRALLOC_PLANAR_YCBCR) {
|
|
img = new GrallocImage();
|
|
return img.forget();
|
|
}
|
|
if (aFormat == ImageFormat::OVERLAY_IMAGE) {
|
|
img = new OverlayImage();
|
|
return img.forget();
|
|
}
|
|
#endif
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_CAMERA) && defined(MOZ_WEBRTC)
|
|
if (aFormat == ImageFormat::GONK_CAMERA_IMAGE) {
|
|
img = new GonkCameraImage();
|
|
return img.forget();
|
|
}
|
|
#endif
|
|
if (aFormat == ImageFormat::PLANAR_YCBCR) {
|
|
img = new PlanarYCbCrImage(aRecycleBin);
|
|
return img.forget();
|
|
}
|
|
if (aFormat == ImageFormat::CAIRO_SURFACE) {
|
|
img = new CairoImage();
|
|
return img.forget();
|
|
}
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
if (aFormat == ImageFormat::SURFACE_TEXTURE) {
|
|
img = new SurfaceTextureImage();
|
|
return img.forget();
|
|
}
|
|
#endif
|
|
if (aFormat == ImageFormat::EGLIMAGE) {
|
|
img = new EGLImageImage();
|
|
return img.forget();
|
|
}
|
|
#ifdef XP_MACOSX
|
|
if (aFormat == ImageFormat::MAC_IOSURFACE) {
|
|
img = new MacIOSurfaceImage();
|
|
return img.forget();
|
|
}
|
|
#endif
|
|
#ifdef XP_WIN
|
|
if (aFormat == ImageFormat::D3D11_SHARE_HANDLE_TEXTURE) {
|
|
img = new D3D11ShareHandleImage();
|
|
return img.forget();
|
|
}
|
|
if (aFormat == ImageFormat::D3D9_RGB32_TEXTURE) {
|
|
img = new D3D9SurfaceImage();
|
|
return img.forget();
|
|
}
|
|
#endif
|
|
return nullptr;
|
|
}
|
|
|
|
BufferRecycleBin::BufferRecycleBin()
|
|
: mLock("mozilla.layers.BufferRecycleBin.mLock")
|
|
{
|
|
}
|
|
|
|
void
|
|
BufferRecycleBin::RecycleBuffer(uint8_t* aBuffer, uint32_t aSize)
|
|
{
|
|
MutexAutoLock lock(mLock);
|
|
|
|
if (!mRecycledBuffers.IsEmpty() && aSize != mRecycledBufferSize) {
|
|
mRecycledBuffers.Clear();
|
|
}
|
|
mRecycledBufferSize = aSize;
|
|
mRecycledBuffers.AppendElement(aBuffer);
|
|
}
|
|
|
|
uint8_t*
|
|
BufferRecycleBin::GetBuffer(uint32_t aSize)
|
|
{
|
|
MutexAutoLock lock(mLock);
|
|
|
|
if (mRecycledBuffers.IsEmpty() || mRecycledBufferSize != aSize)
|
|
return new uint8_t[aSize];
|
|
|
|
uint32_t last = mRecycledBuffers.Length() - 1;
|
|
uint8_t* result = mRecycledBuffers[last].forget();
|
|
mRecycledBuffers.RemoveElementAt(last);
|
|
return result;
|
|
}
|
|
|
|
ImageContainer::ImageContainer(int flag)
|
|
: mReentrantMonitor("ImageContainer.mReentrantMonitor"),
|
|
mPaintCount(0),
|
|
mPreviousImagePainted(false),
|
|
mImageFactory(new ImageFactory()),
|
|
mRecycleBin(new BufferRecycleBin()),
|
|
mCompositionNotifySink(nullptr),
|
|
mImageClient(nullptr)
|
|
{
|
|
if (flag == ENABLE_ASYNC && ImageBridgeChild::IsCreated()) {
|
|
// the refcount of this ImageClient is 1. we don't use a RefPtr here because the refcount
|
|
// of this class must be done on the ImageBridge thread.
|
|
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(CompositableType::IMAGE).take();
|
|
MOZ_ASSERT(mImageClient);
|
|
}
|
|
}
|
|
|
|
ImageContainer::~ImageContainer()
|
|
{
|
|
if (IsAsync()) {
|
|
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
|
|
}
|
|
}
|
|
|
|
already_AddRefed<Image>
|
|
ImageContainer::CreateImage(ImageFormat aFormat)
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
if (aFormat == ImageFormat::OVERLAY_IMAGE) {
|
|
if (mImageClient && mImageClient->GetTextureInfo().mCompositableType != CompositableType::IMAGE_OVERLAY) {
|
|
// If this ImageContainer is async but the image type mismatch, fix it here
|
|
if (ImageBridgeChild::IsCreated()) {
|
|
ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
|
|
mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(CompositableType::IMAGE_OVERLAY).take();
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
if (mImageClient) {
|
|
nsRefPtr<Image> img = mImageClient->CreateImage(aFormat);
|
|
if (img) {
|
|
return img.forget();
|
|
}
|
|
}
|
|
return mImageFactory->CreateImage(aFormat, mScaleHint, mRecycleBin);
|
|
}
|
|
|
|
void
|
|
ImageContainer::SetCurrentImageInternal(Image *aImage)
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
mActiveImage = aImage;
|
|
CurrentImageChanged();
|
|
}
|
|
|
|
void
|
|
ImageContainer::ClearCurrentImage()
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
SetCurrentImageInternal(nullptr);
|
|
}
|
|
|
|
void
|
|
ImageContainer::SetCurrentImage(Image *aImage)
|
|
{
|
|
if (!aImage) {
|
|
ClearAllImages();
|
|
return;
|
|
}
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
if (IsAsync()) {
|
|
ImageBridgeChild::DispatchImageClientUpdate(mImageClient, this);
|
|
}
|
|
SetCurrentImageInternal(aImage);
|
|
}
|
|
|
|
void
|
|
ImageContainer::ClearAllImages()
|
|
{
|
|
if (IsAsync()) {
|
|
// Let ImageClient release all TextureClients.
|
|
ImageBridgeChild::FlushAllImages(mImageClient, this, false);
|
|
return;
|
|
}
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
SetCurrentImageInternal(nullptr);
|
|
}
|
|
|
|
void
|
|
ImageContainer::ClearAllImagesExceptFront()
|
|
{
|
|
if (IsAsync()) {
|
|
// Let ImageClient release all TextureClients except front one.
|
|
ImageBridgeChild::FlushAllImages(mImageClient, this, true);
|
|
}
|
|
}
|
|
|
|
void
|
|
ImageContainer::SetCurrentImageInTransaction(Image *aImage)
|
|
{
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
NS_ASSERTION(!mImageClient, "Should use async image transfer with ImageBridge.");
|
|
|
|
SetCurrentImageInternal(aImage);
|
|
}
|
|
|
|
bool ImageContainer::IsAsync() const {
|
|
return mImageClient != nullptr;
|
|
}
|
|
|
|
uint64_t ImageContainer::GetAsyncContainerID() const
|
|
{
|
|
NS_ASSERTION(IsAsync(),"Shared image ID is only relevant to async ImageContainers");
|
|
if (IsAsync()) {
|
|
return mImageClient->GetAsyncID();
|
|
} else {
|
|
return 0; // zero is always an invalid AsyncID
|
|
}
|
|
}
|
|
|
|
bool
|
|
ImageContainer::HasCurrentImage()
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
return !!mActiveImage.get();
|
|
}
|
|
|
|
already_AddRefed<Image>
|
|
ImageContainer::LockCurrentImage()
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
nsRefPtr<Image> retval = mActiveImage;
|
|
return retval.forget();
|
|
}
|
|
|
|
already_AddRefed<gfx::SourceSurface>
|
|
ImageContainer::LockCurrentAsSourceSurface(gfx::IntSize *aSize, Image** aCurrentImage)
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
if (aCurrentImage) {
|
|
nsRefPtr<Image> activeImage(mActiveImage);
|
|
activeImage.forget(aCurrentImage);
|
|
}
|
|
|
|
if (!mActiveImage) {
|
|
return nullptr;
|
|
}
|
|
|
|
*aSize = mActiveImage->GetSize();
|
|
return mActiveImage->GetAsSourceSurface();
|
|
}
|
|
|
|
void
|
|
ImageContainer::UnlockCurrentImage()
|
|
{
|
|
}
|
|
|
|
already_AddRefed<gfx::SourceSurface>
|
|
ImageContainer::GetCurrentAsSourceSurface(gfx::IntSize *aSize)
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
if (!mActiveImage)
|
|
return nullptr;
|
|
*aSize = mActiveImage->GetSize();
|
|
return mActiveImage->GetAsSourceSurface();
|
|
}
|
|
|
|
gfx::IntSize
|
|
ImageContainer::GetCurrentSize()
|
|
{
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
if (!mActiveImage) {
|
|
return gfx::IntSize(0, 0);
|
|
}
|
|
|
|
return mActiveImage->GetSize();
|
|
}
|
|
|
|
PlanarYCbCrImage::PlanarYCbCrImage(BufferRecycleBin *aRecycleBin)
|
|
: Image(nullptr, ImageFormat::PLANAR_YCBCR)
|
|
, mBufferSize(0)
|
|
, mOffscreenFormat(gfxImageFormat::Unknown)
|
|
, mRecycleBin(aRecycleBin)
|
|
{
|
|
}
|
|
|
|
PlanarYCbCrImage::~PlanarYCbCrImage()
|
|
{
|
|
if (mBuffer) {
|
|
mRecycleBin->RecycleBuffer(mBuffer.forget(), mBufferSize);
|
|
}
|
|
}
|
|
|
|
size_t
|
|
PlanarYCbCrImage::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
// Ignoring:
|
|
// - mData - just wraps mBuffer
|
|
// - Surfaces should be reported under gfx-surfaces-*:
|
|
// - mSourceSurface
|
|
// - Base class:
|
|
// - mImplData is not used
|
|
// Not owned:
|
|
// - mRecycleBin
|
|
size_t size = mBuffer.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
// Could add in the future:
|
|
// - mBackendData (from base class)
|
|
|
|
return size;
|
|
}
|
|
|
|
uint8_t*
|
|
PlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
|
|
{
|
|
return mRecycleBin->GetBuffer(aSize);
|
|
}
|
|
|
|
static void
|
|
CopyPlane(uint8_t *aDst, const uint8_t *aSrc,
|
|
const gfx::IntSize &aSize, int32_t aStride, int32_t aSkip)
|
|
{
|
|
int32_t height = aSize.height;
|
|
int32_t width = aSize.width;
|
|
|
|
MOZ_RELEASE_ASSERT(width <= aStride);
|
|
|
|
if (!aSkip) {
|
|
// Fast path: planar input.
|
|
memcpy(aDst, aSrc, height * aStride);
|
|
} else {
|
|
for (int y = 0; y < height; ++y) {
|
|
const uint8_t *src = aSrc;
|
|
uint8_t *dst = aDst;
|
|
// Slow path
|
|
for (int x = 0; x < width; ++x) {
|
|
*dst++ = *src++;
|
|
src += aSkip;
|
|
}
|
|
aSrc += aStride;
|
|
aDst += aStride;
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
PlanarYCbCrImage::CopyData(const Data& aData)
|
|
{
|
|
// update buffer size
|
|
// Use uint32_t throughout to match AllocateBuffer's param and mBufferSize
|
|
const auto checkedSize =
|
|
CheckedInt<uint32_t>(aData.mCbCrStride) * aData.mCbCrSize.height * 2 +
|
|
CheckedInt<uint32_t>(aData.mYStride) * aData.mYSize.height;
|
|
|
|
if (!checkedSize.isValid())
|
|
return;
|
|
|
|
const auto size = checkedSize.value();
|
|
|
|
// get new buffer
|
|
mBuffer = AllocateBuffer(size);
|
|
if (!mBuffer)
|
|
return;
|
|
|
|
// update buffer size
|
|
mBufferSize = size;
|
|
|
|
mData = aData;
|
|
mData.mYChannel = mBuffer;
|
|
mData.mCbChannel = mData.mYChannel + mData.mYStride * mData.mYSize.height;
|
|
mData.mCrChannel = mData.mCbChannel + mData.mCbCrStride * mData.mCbCrSize.height;
|
|
mData.mYSkip = mData.mCbSkip = mData.mCrSkip = 0;
|
|
|
|
CopyPlane(mData.mYChannel, aData.mYChannel,
|
|
aData.mYSize, aData.mYStride, aData.mYSkip);
|
|
CopyPlane(mData.mCbChannel, aData.mCbChannel,
|
|
aData.mCbCrSize, aData.mCbCrStride, aData.mCbSkip);
|
|
CopyPlane(mData.mCrChannel, aData.mCrChannel,
|
|
aData.mCbCrSize, aData.mCbCrStride, aData.mCrSkip);
|
|
|
|
mSize = aData.mPicSize;
|
|
}
|
|
|
|
void
|
|
PlanarYCbCrImage::SetData(const Data &aData)
|
|
{
|
|
CopyData(aData);
|
|
}
|
|
|
|
gfxImageFormat
|
|
PlanarYCbCrImage::GetOffscreenFormat()
|
|
{
|
|
return mOffscreenFormat == gfxImageFormat::Unknown ?
|
|
gfxPlatform::GetPlatform()->GetOffscreenFormat() :
|
|
mOffscreenFormat;
|
|
}
|
|
|
|
void
|
|
PlanarYCbCrImage::SetDataNoCopy(const Data &aData)
|
|
{
|
|
mData = aData;
|
|
mSize = aData.mPicSize;
|
|
}
|
|
|
|
uint8_t*
|
|
PlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
|
|
{
|
|
// get new buffer
|
|
mBuffer = AllocateBuffer(aSize);
|
|
if (mBuffer) {
|
|
// update buffer size
|
|
mBufferSize = aSize;
|
|
}
|
|
return mBuffer;
|
|
}
|
|
|
|
already_AddRefed<gfx::SourceSurface>
|
|
PlanarYCbCrImage::GetAsSourceSurface()
|
|
{
|
|
if (mSourceSurface) {
|
|
RefPtr<gfx::SourceSurface> surface(mSourceSurface);
|
|
return surface.forget();
|
|
}
|
|
|
|
gfx::IntSize size(mSize);
|
|
gfx::SurfaceFormat format = gfx::ImageFormatToSurfaceFormat(GetOffscreenFormat());
|
|
gfx::GetYCbCrToRGBDestFormatAndSize(mData, format, size);
|
|
if (mSize.width > PlanarYCbCrImage::MAX_DIMENSION ||
|
|
mSize.height > PlanarYCbCrImage::MAX_DIMENSION) {
|
|
NS_ERROR("Illegal image dest width or height");
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<gfx::DataSourceSurface> surface = gfx::Factory::CreateDataSourceSurface(size, format);
|
|
if (NS_WARN_IF(!surface)) {
|
|
return nullptr;
|
|
}
|
|
|
|
gfx::ConvertYCbCrToRGB(mData, format, size, surface->GetData(), surface->Stride());
|
|
|
|
mSourceSurface = surface;
|
|
|
|
return surface.forget();
|
|
}
|
|
|
|
CairoImage::CairoImage()
|
|
: Image(nullptr, ImageFormat::CAIRO_SURFACE)
|
|
{}
|
|
|
|
CairoImage::~CairoImage()
|
|
{
|
|
}
|
|
|
|
TextureClient*
|
|
CairoImage::GetTextureClient(CompositableClient *aClient)
|
|
{
|
|
if (!aClient) {
|
|
return nullptr;
|
|
}
|
|
|
|
CompositableForwarder* forwarder = aClient->GetForwarder();
|
|
RefPtr<TextureClient> textureClient = mTextureClients.Get(forwarder->GetSerial());
|
|
if (textureClient) {
|
|
return textureClient;
|
|
}
|
|
|
|
RefPtr<SourceSurface> surface = GetAsSourceSurface();
|
|
MOZ_ASSERT(surface);
|
|
if (!surface) {
|
|
return nullptr;
|
|
}
|
|
|
|
|
|
// XXX windows' TextureClients do not hold ISurfaceAllocator,
|
|
// recycler does not work on windows.
|
|
#ifndef XP_WIN
|
|
|
|
// XXX only gonk ensure when TextureClient is recycled,
|
|
// TextureHost is not used by CompositableHost.
|
|
#ifdef MOZ_WIDGET_GONK
|
|
RefPtr<TextureClientRecycleAllocator> recycler =
|
|
aClient->GetTextureClientRecycler();
|
|
if (recycler) {
|
|
textureClient =
|
|
recycler->CreateOrRecycleForDrawing(surface->GetFormat(),
|
|
surface->GetSize(),
|
|
gfx::BackendType::NONE,
|
|
aClient->GetTextureFlags());
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
if (!textureClient) {
|
|
// gfx::BackendType::NONE means default to content backend
|
|
textureClient = aClient->CreateTextureClientForDrawing(surface->GetFormat(),
|
|
surface->GetSize(),
|
|
gfx::BackendType::NONE,
|
|
TextureFlags::DEFAULT);
|
|
}
|
|
if (!textureClient) {
|
|
return nullptr;
|
|
}
|
|
MOZ_ASSERT(textureClient->CanExposeDrawTarget());
|
|
if (!textureClient->Lock(OpenMode::OPEN_WRITE_ONLY)) {
|
|
return nullptr;
|
|
}
|
|
|
|
TextureClientAutoUnlock autoUnolck(textureClient);
|
|
{
|
|
// We must not keep a reference to the DrawTarget after it has been unlocked.
|
|
DrawTarget* dt = textureClient->BorrowDrawTarget();
|
|
if (!dt) {
|
|
return nullptr;
|
|
}
|
|
dt->CopySurface(surface, IntRect(IntPoint(), surface->GetSize()), IntPoint());
|
|
}
|
|
|
|
mTextureClients.Put(forwarder->GetSerial(), textureClient);
|
|
return textureClient;
|
|
}
|
|
|
|
} // namespace layers
|
|
} // namespace mozilla
|