mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 05:11:03 +00:00
a057fcd85b
- Bug 1201329 - Use AlignedStorage2 instead of char[] for IPDL union members. r=billm (420db1710) - Bug 1146214 - Remove unused set fence functions. r=nical (148188894) - Bug 1146214 - Combine FenceHandle and FenceHandleFromChild. r=nical (9d33cdedc) - Bug 1147894 - Remove the redundant OpUpdateTexture IPDL message. r=sotaro (c3b037c92) - Bug 1146214 - Implement fence delivery. Combine ipc messages and remove reply fence delivery message. r=nical (cd115f0db) - Bug 1146214 - Remove the unused code after refactoring. r=nical (2582f1dfa) - Bug 1146214 - Rename some functions after refactoring. r=nical (fd7655c71) - Bug 1150381 - [LayerScope]: Don't showing the same texture in the same frame on LayerScope. r=chiajung (7a5310113) - Bug 1162395 - [LayerScope]: No need to read and send the texture when the same texture id contains in a frame. r=cku (2c67a0994) - Bug 1168015 - Dump source image from graphic buffer directly on B2G. r=kamidphish, r=hshih (108f3dd5a) - Bug 1158575: Support using GDI rendering for opaque surfaces when using cross-process layers. r=jrmuizel (8913ea2ff) - Bug 1155498 - Use FdObj to replace FenceHandle's android fence. r=sotaro (ac0f66f02) - Bug 1155498 - Part 2 - Use new FenceHandle to handle the fence in TextureHost. r=sotaro (8c3cd6427) - Bug 1152370 part 1 - Add android aosp VirtualDisplaySurface r=mwu (795674527) - Bug 1152370 part 2 - Add DisplaySurface r=mwu (f4e7cb123) - Bug 1151936 - Update GLContextEGL's EGLSurface override handling r=jgilbert (a1a72947b) - Bug 1154313 - Move sUsingHwc to gfxPrefs r=mwu,nical (d315f572a) - Bug 1152361 - Ensure outbufAcquireFenceFd is initialized during boot animation. r=mwu (c17f9bc1a) - Bug 1152135 - Split EGLSurface buffer swap and HWC buffer swap r=mwu,nical,jgilbert (2ec0aaccc) - Bug 1148149 - Support Android Presentation API. r=snorp, r=jgilbert (60ae01557) - Bug 1150518 - Remove glClear() on blit composition r=Sushil (24b242a14) - Bug 1152370 part 3 - Use DisplaySurface r=mwu (c531c0b44) - Bug 1157661 - Fix a null-check in CompositorOGL::DrawQuad. r=nical (c00d429d3) - Bug 1113425 part 1 - Fix some bad CSS comment syntax in animation tests; r=mattwoodrow (7abbbb3de) - Bug 1113425 part 2 - Apply async properties when querying the animated transform; r=mattwoodrow (52e778eeb) - Bug 1113425 part 4 - Enable test_deferred_start.html on all platforms; r=mattwoodrow (3884a02a3) - Bug 1113425 part 3 - Make test_deferred_start.html wait an extra frame; r=mattwoodrow (0971c8836) - Bug 1148949 - Apply async properties when querying the animated transform for cross-process compositor parents too; r=mattwoodrow (8bdeafc25) - Bug 1157066. When reading back the OMTA transfrom of a layer don't include transforms from async panning or zooming. r=kats,birtles (43c1bab02) - Bug 1129133 - Clean up GeckoTouchDispatcher so that it's a real singleton. r=kats,mwu (ac97ee5f4) - Bug 1140578 - Remove some redundant code and an unused return value. r=mchang (9d02a9794) - Bug 1140578 - Simplify some code. r=mchang (5a2f95805) - Bug 1140578 - Add a explicit flag to track if we have pending touch moves to process. r=mchang (3255a2ac8) - Bug 1140578 - Prevent resampling moves across non-move touch events. r=mchang (5a2622f6c) - Bug 1146987 - Deal with cases where we get a batch of interleaved move and non-move events on the libui thread before anything is processed, with resampling disabled. r=mchang (462ce355c) - Bug 1149412 - Remove bad assertion. r=mchang (d9d2db4ba) - Bug 1137151: Marked destructor of |GeckoTouchDispatcher| as protected, r=mwu (21fae6af2) - Bug 1138502. Reset vsync unobserve count if a force composite occurs. r=mstange (9682c9e62) - Bug 1148583 - Dispatch touch events before composites. r=kats (cfabb0eef) - Bug 1128690 - Ensure Talos Performance Tests still work with silk enabled. r=mstange (089e87b89) - Bug 1138181 - Be more aggressive in updating plugin geometry in the compositor, avoids filtering out important offset updates that don't involve remote layer tree updates. r=roc (e341636de) - comment coming from Bug 1143249 (2f6c7bdc8) - Bug 1154614 - Don't try to pick up the same non-reentrant lock twice. r=dvander a=RyanVM (c69cba3d9) - Bug 1156981 - Split CompositorParent's scheduling of composition to CompositorScheduler r=mchang (bf87b2ba3) - Bug 1139541 - Make HWC skip opacity=0 layers. r=sotaro (cd6d5114c) - Bug 1149646 - Delete non-uniform vsync interval warning. r=kats (5bc0cd3fa) - Bug 1155498 - Part 3 - Use new FenceHandle to handle the fence in Compositor. r=sotaro (f5c685606) - Bug 1155498 - Part 4 - Use new FenceHandle to handle the fence in TextureClient. r=sotaro (0390d19fd) - Bug 1155498 - Part 5 - Use new FenceHandle to handle Decoder fence. r=sotaro (a99b62351) - Bug 1164513 - Add nullptr check r=milan (41053d048) - Bug 1155495 - Part 1: Remove TextureHostOGL and integrate the platform specific API into TextureHost. r=nical, r=sotaro (9c909e5e2) - Bug 1155495 - Part 2: Remove unnecessary class inheritance and casting. r=nical, r=sotaro (4ce5869ff) - Bug 1133007 - Send the content of a texture only if its was altered since previous transmission. r=kamidphish, r=boris (f78a07160) - Bug 1156456 patch 1 - Reftests comparing a 3-D transformed cube generated by main-thread paths and off-main-thread animations paths. r=birtles (f0f5309d9) - Bug 1156456 patch 2 - Transform the z component just like the x and y. r=birtles (cc36b5b91) - Bug 1156456 patch 3 - Send transform origin and perspective origin to layer in device pixels rather than CSS pixels. r=birtles (94ea8a04a) - Bug 1156456 followup - Also annotate as fuzzy on Mulet, on a CLOSED TREE. (712c97eff) - Bug 1156456 followup - Add a simple reftest for off-main-thread animation of opacity. (eac0fe0e4) - Bug 1157455 patch 1 - Add tests for OMTA transforms in degrees in addition to those in radians. r=birtles (83fb5b7af) - Bug 1157455 patch 2 - Send angles (in CSS transform functions) to the compositor thread with their units rather than sending all such angles in radians. r=birtles (a8b47f5b0) - Bug 1157455 patch 3 - When interpolating angles, preserve units when possible in order to avoid floating point error. r=birtles (ace148e00) - Bug 1157455 followup - fix test_transitions_per_property.html to expect different angle interpolation results, on a CLOSED TREE. (270ef56eb) - Bug 1022080 - Don't force intermediate surfaces when dumping textures, unless explicitly specified. r=nical (0a010b6c8) - Bug 1022080 - Make non-HTML dumping of textures work better. r=nical (304939544)
973 lines
27 KiB
C++
973 lines
27 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 "mozilla/layers/TextureClient.h"
|
|
#include <stdint.h> // for uint8_t, uint32_t, etc
|
|
#include "Layers.h" // for Layer, etc
|
|
#include "gfx2DGlue.h"
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
|
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
|
#include "mozilla/layers/YCbCrImageDataSerializer.h"
|
|
#include "nsDebug.h" // for NS_ASSERTION, NS_WARNING, etc
|
|
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
|
|
#include "ImageContainer.h" // for PlanarYCbCrData, etc
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "mozilla/gfx/Logging.h" // for gfxDebug
|
|
#include "mozilla/layers/TextureClientOGL.h"
|
|
#include "mozilla/layers/PTextureChild.h"
|
|
#include "SharedSurface.h"
|
|
#include "GLContext.h"
|
|
#include "mozilla/gfx/DataSurfaceHelpers.h" // for CreateDataSourceSurfaceByCloning
|
|
#include "nsPrintfCString.h" // for nsPrintfCString
|
|
#include "LayersLogging.h" // for AppendToString
|
|
#include "gfxUtils.h" // for gfxUtils::GetAsLZ4Base64Str
|
|
|
|
#ifdef XP_WIN
|
|
#include "mozilla/layers/TextureD3D9.h"
|
|
#include "mozilla/layers/TextureD3D11.h"
|
|
#include "mozilla/layers/TextureDIB.h"
|
|
#include "gfxWindowsPlatform.h"
|
|
#include "gfx2DGlue.h"
|
|
#endif
|
|
#ifdef MOZ_X11
|
|
#include "mozilla/layers/TextureClientX11.h"
|
|
#ifdef GL_PROVIDER_GLX
|
|
#include "GLXLibrary.h"
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
#include <cutils/properties.h>
|
|
#include "mozilla/layers/GrallocTextureClient.h"
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
# include "gfxReusableImageSurfaceWrapper.h"
|
|
#else
|
|
# include "gfxReusableSharedImageSurfaceWrapper.h"
|
|
# include "gfxSharedImageSurface.h"
|
|
#endif
|
|
|
|
#if 0
|
|
#define RECYCLE_LOG(...) printf_stderr(__VA_ARGS__)
|
|
#else
|
|
#define RECYCLE_LOG(...) do { } while (0)
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
namespace layers {
|
|
|
|
using namespace mozilla::ipc;
|
|
using namespace mozilla::gl;
|
|
using namespace mozilla::gfx;
|
|
|
|
struct ReleaseKeepAlive : public nsRunnable
|
|
{
|
|
NS_IMETHOD Run()
|
|
{
|
|
mKeep = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
UniquePtr<KeepAlive> mKeep;
|
|
};
|
|
|
|
/**
|
|
* TextureChild is the content-side incarnation of the PTexture IPDL actor.
|
|
*
|
|
* TextureChild is used to synchronize a texture client and its corresponding
|
|
* TextureHost if needed (a TextureClient that is not shared with the compositor
|
|
* does not have a TextureChild)
|
|
*
|
|
* During the deallocation phase, a TextureChild may hold its recently destroyed
|
|
* TextureClient's data until the compositor side confirmed that it is safe to
|
|
* deallocte or recycle the it.
|
|
*/
|
|
class TextureChild final : public PTextureChild
|
|
{
|
|
~TextureChild()
|
|
{
|
|
if (mKeep && mMainThreadOnly && !NS_IsMainThread()) {
|
|
nsRefPtr<ReleaseKeepAlive> release = new ReleaseKeepAlive();
|
|
release->mKeep = Move(mKeep);
|
|
NS_DispatchToMainThread(release);
|
|
}
|
|
}
|
|
public:
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureChild)
|
|
|
|
TextureChild()
|
|
: mForwarder(nullptr)
|
|
, mTextureClient(nullptr)
|
|
, mMainThreadOnly(false)
|
|
, mIPCOpen(false)
|
|
{
|
|
}
|
|
|
|
bool Recv__delete__() override;
|
|
|
|
bool RecvCompositorRecycle() override
|
|
{
|
|
RECYCLE_LOG("Receive recycle %p (%p)\n", mTextureClient, mWaitForRecycle.get());
|
|
mWaitForRecycle = nullptr;
|
|
return true;
|
|
}
|
|
|
|
void WaitForCompositorRecycle()
|
|
{
|
|
mWaitForRecycle = mTextureClient;
|
|
RECYCLE_LOG("Wait for recycle %p\n", mWaitForRecycle.get());
|
|
SendClientRecycle();
|
|
}
|
|
|
|
CompositableForwarder* GetForwarder() { return mForwarder; }
|
|
|
|
ISurfaceAllocator* GetAllocator() { return mForwarder; }
|
|
|
|
void ActorDestroy(ActorDestroyReason why) override;
|
|
|
|
bool IPCOpen() const { return mIPCOpen; }
|
|
|
|
private:
|
|
|
|
// AddIPDLReference and ReleaseIPDLReference are only to be called by CreateIPDLActor
|
|
// and DestroyIPDLActor, respectively. We intentionally make them private to prevent misuse.
|
|
// The purpose of these methods is to be aware of when the IPC system around this
|
|
// actor goes down: mIPCOpen is then set to false.
|
|
void AddIPDLReference() {
|
|
MOZ_ASSERT(mIPCOpen == false);
|
|
mIPCOpen = true;
|
|
AddRef();
|
|
}
|
|
void ReleaseIPDLReference() {
|
|
MOZ_ASSERT(mIPCOpen == true);
|
|
mIPCOpen = false;
|
|
Release();
|
|
}
|
|
|
|
RefPtr<CompositableForwarder> mForwarder;
|
|
RefPtr<TextureClient> mWaitForRecycle;
|
|
TextureClient* mTextureClient;
|
|
UniquePtr<KeepAlive> mKeep;
|
|
bool mMainThreadOnly;
|
|
bool mIPCOpen;
|
|
|
|
friend class TextureClient;
|
|
};
|
|
|
|
bool
|
|
TextureChild::Recv__delete__()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void
|
|
TextureChild::ActorDestroy(ActorDestroyReason why)
|
|
{
|
|
if (mTextureClient) {
|
|
mTextureClient->mActor = nullptr;
|
|
}
|
|
mWaitForRecycle = nullptr;
|
|
mKeep = nullptr;
|
|
}
|
|
|
|
// static
|
|
PTextureChild*
|
|
TextureClient::CreateIPDLActor()
|
|
{
|
|
TextureChild* c = new TextureChild();
|
|
c->AddIPDLReference();
|
|
return c;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
TextureClient::DestroyIPDLActor(PTextureChild* actor)
|
|
{
|
|
static_cast<TextureChild*>(actor)->ReleaseIPDLReference();
|
|
return true;
|
|
}
|
|
|
|
// static
|
|
TextureClient*
|
|
TextureClient::AsTextureClient(PTextureChild* actor)
|
|
{
|
|
return actor ? static_cast<TextureChild*>(actor)->mTextureClient : nullptr;
|
|
}
|
|
|
|
void
|
|
TextureClient::AddFlags(TextureFlags aFlags)
|
|
{
|
|
MOZ_ASSERT(!IsSharedWithCompositor() ||
|
|
((GetFlags() & TextureFlags::RECYCLE) && !IsAddedToCompositableClient()));
|
|
mFlags |= aFlags;
|
|
if (mValid && mActor && mActor->IPCOpen()) {
|
|
mActor->SendRecycleTexture(mFlags);
|
|
}
|
|
}
|
|
|
|
void
|
|
TextureClient::RemoveFlags(TextureFlags aFlags)
|
|
{
|
|
MOZ_ASSERT(!IsSharedWithCompositor() ||
|
|
((GetFlags() & TextureFlags::RECYCLE) && !IsAddedToCompositableClient()));
|
|
mFlags &= ~aFlags;
|
|
if (mValid && mActor && mActor->IPCOpen()) {
|
|
mActor->SendRecycleTexture(mFlags);
|
|
}
|
|
}
|
|
|
|
void
|
|
TextureClient::RecycleTexture(TextureFlags aFlags)
|
|
{
|
|
MOZ_ASSERT(GetFlags() & TextureFlags::RECYCLE);
|
|
MOZ_ASSERT(!HasRecycleCallback());
|
|
|
|
mAddedToCompositableClient = false;
|
|
if (mFlags != aFlags) {
|
|
mFlags = aFlags;
|
|
if (mValid && mActor && mActor->IPCOpen()) {
|
|
mActor->SendRecycleTexture(mFlags);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
TextureClient::WaitForCompositorRecycle()
|
|
{
|
|
mActor->WaitForCompositorRecycle();
|
|
}
|
|
|
|
void
|
|
TextureClient::SetAddedToCompositableClient()
|
|
{
|
|
if (!mAddedToCompositableClient) {
|
|
mAddedToCompositableClient = true;
|
|
}
|
|
}
|
|
|
|
bool
|
|
TextureClient::InitIPDLActor(CompositableForwarder* aForwarder)
|
|
{
|
|
MOZ_ASSERT(aForwarder && aForwarder->GetMessageLoop() == mAllocator->GetMessageLoop());
|
|
if (mActor && mActor->GetForwarder() == aForwarder) {
|
|
return true;
|
|
}
|
|
MOZ_ASSERT(!mActor, "Cannot use a texture on several IPC channels.");
|
|
|
|
SurfaceDescriptor desc;
|
|
if (!ToSurfaceDescriptor(desc)) {
|
|
return false;
|
|
}
|
|
|
|
mActor = static_cast<TextureChild*>(aForwarder->CreateTexture(desc, GetFlags()));
|
|
MOZ_ASSERT(mActor);
|
|
mActor->mForwarder = aForwarder;
|
|
mActor->mTextureClient = this;
|
|
mShared = true;
|
|
return mActor->IPCOpen();
|
|
}
|
|
|
|
PTextureChild*
|
|
TextureClient::GetIPDLActor()
|
|
{
|
|
return mActor;
|
|
}
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
static bool
|
|
DisableGralloc(SurfaceFormat aFormat, const gfx::IntSize& aSizeHint)
|
|
{
|
|
if (gfxPrefs::DisableGralloc()) {
|
|
return true;
|
|
}
|
|
if (aFormat == gfx::SurfaceFormat::A8) {
|
|
return true;
|
|
}
|
|
|
|
#if ANDROID_VERSION <= 15
|
|
// Adreno 200 has a problem of drawing gralloc buffer width less than 64 and
|
|
// drawing gralloc buffer with a height 9px-16px.
|
|
// See Bug 983971.
|
|
if (aSizeHint.width < 64 || aSizeHint.height < 32) {
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
static
|
|
already_AddRefed<BufferTextureClient>
|
|
CreateBufferTextureClient(ISurfaceAllocator* aAllocator,
|
|
SurfaceFormat aFormat,
|
|
TextureFlags aTextureFlags,
|
|
gfx::BackendType aMoz2DBackend)
|
|
{
|
|
if (aAllocator->IsSameProcess()) {
|
|
RefPtr<BufferTextureClient> result = new MemoryTextureClient(aAllocator, aFormat,
|
|
aMoz2DBackend,
|
|
aTextureFlags);
|
|
return result.forget();
|
|
}
|
|
RefPtr<BufferTextureClient> result = new ShmemTextureClient(aAllocator, aFormat,
|
|
aMoz2DBackend,
|
|
aTextureFlags);
|
|
return result.forget();
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<TextureClient>
|
|
TextureClient::CreateForDrawing(ISurfaceAllocator* aAllocator,
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::IntSize aSize,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aTextureFlags,
|
|
TextureAllocationFlags aAllocFlags)
|
|
{
|
|
if (aMoz2DBackend == gfx::BackendType::NONE) {
|
|
aMoz2DBackend = gfxPlatform::GetPlatform()->GetContentBackend();
|
|
}
|
|
|
|
if (!gfx::Factory::AllowedSurfaceSize(aSize)) {
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<TextureClient> texture;
|
|
|
|
#if defined(MOZ_WIDGET_GONK) || defined(XP_WIN)
|
|
int32_t maxTextureSize = aAllocator->GetMaxTextureSize();
|
|
#endif
|
|
|
|
#ifdef XP_WIN
|
|
LayersBackend parentBackend = aAllocator->GetCompositorBackendType();
|
|
if (parentBackend == LayersBackend::LAYERS_D3D11 &&
|
|
(aMoz2DBackend == gfx::BackendType::DIRECT2D ||
|
|
aMoz2DBackend == gfx::BackendType::DIRECT2D1_1) &&
|
|
gfxWindowsPlatform::GetPlatform()->GetD2DDevice() &&
|
|
aSize.width <= maxTextureSize &&
|
|
aSize.height <= maxTextureSize) {
|
|
texture = new TextureClientD3D11(aAllocator, aFormat, aTextureFlags);
|
|
}
|
|
if (parentBackend == LayersBackend::LAYERS_D3D9 &&
|
|
aMoz2DBackend == gfx::BackendType::CAIRO &&
|
|
aAllocator->IsSameProcess() &&
|
|
aSize.width <= maxTextureSize &&
|
|
aSize.height <= maxTextureSize) {
|
|
if (gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
|
|
texture = new CairoTextureClientD3D9(aAllocator, aFormat, aTextureFlags);
|
|
}
|
|
}
|
|
|
|
if (!texture && aFormat == SurfaceFormat::B8G8R8X8 &&
|
|
aAllocator->IsSameProcess() &&
|
|
aMoz2DBackend == gfx::BackendType::CAIRO) {
|
|
if (aAllocator->IsSameProcess()) {
|
|
texture = new TextureClientMemoryDIB(aAllocator, aFormat, aTextureFlags);
|
|
} else {
|
|
texture = new TextureClientShmemDIB(aAllocator, aFormat, aTextureFlags);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#ifdef MOZ_X11
|
|
LayersBackend parentBackend = aAllocator->GetCompositorBackendType();
|
|
gfxSurfaceType type =
|
|
gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType();
|
|
|
|
if (parentBackend == LayersBackend::LAYERS_BASIC &&
|
|
aMoz2DBackend == gfx::BackendType::CAIRO &&
|
|
type == gfxSurfaceType::Xlib)
|
|
{
|
|
texture = new TextureClientX11(aAllocator, aFormat, aTextureFlags);
|
|
}
|
|
#ifdef GL_PROVIDER_GLX
|
|
if (parentBackend == LayersBackend::LAYERS_OPENGL &&
|
|
type == gfxSurfaceType::Xlib &&
|
|
aFormat != SurfaceFormat::A8 &&
|
|
gl::sGLXLibrary.UseTextureFromPixmap())
|
|
{
|
|
texture = new TextureClientX11(aAllocator, aFormat, aTextureFlags);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
if (!DisableGralloc(aFormat, aSize)) {
|
|
// Don't allow Gralloc texture clients to exceed the maximum texture size.
|
|
// BufferTextureClients have code to handle tiling the surface client-side.
|
|
if (aSize.width <= maxTextureSize && aSize.height <= maxTextureSize) {
|
|
texture = new GrallocTextureClientOGL(aAllocator, aFormat, aMoz2DBackend,
|
|
aTextureFlags);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
MOZ_ASSERT(!texture || texture->CanExposeDrawTarget(), "texture cannot expose a DrawTarget?");
|
|
|
|
if (texture && texture->AllocateForSurface(aSize, aAllocFlags)) {
|
|
return texture.forget();
|
|
}
|
|
|
|
if (aAllocFlags & ALLOC_DISALLOW_BUFFERTEXTURECLIENT) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (texture) {
|
|
NS_WARNING("Failed to allocate a TextureClient, falling back to BufferTextureClient.");
|
|
}
|
|
|
|
// Can't do any better than a buffer texture client.
|
|
texture = CreateBufferTextureClient(aAllocator, aFormat, aTextureFlags, aMoz2DBackend);
|
|
|
|
if (!texture->AllocateForSurface(aSize, aAllocFlags)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return texture.forget();
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<BufferTextureClient>
|
|
TextureClient::CreateForRawBufferAccess(ISurfaceAllocator* aAllocator,
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::IntSize aSize,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aTextureFlags,
|
|
TextureAllocationFlags aAllocFlags)
|
|
{
|
|
if (!gfx::Factory::AllowedSurfaceSize(aSize)) {
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<BufferTextureClient> texture =
|
|
CreateBufferTextureClient(aAllocator, aFormat,
|
|
aTextureFlags, aMoz2DBackend);
|
|
if (texture) {
|
|
if (!texture->AllocateForSurface(aSize, aAllocFlags)) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
return texture.forget();
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<BufferTextureClient>
|
|
TextureClient::CreateForYCbCr(ISurfaceAllocator* aAllocator,
|
|
gfx::IntSize aYSize,
|
|
gfx::IntSize aCbCrSize,
|
|
StereoMode aStereoMode,
|
|
TextureFlags aTextureFlags)
|
|
{
|
|
if (!gfx::Factory::AllowedSurfaceSize(aYSize)) {
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<BufferTextureClient> texture;
|
|
if (aAllocator->IsSameProcess()) {
|
|
texture = new MemoryTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
gfx::BackendType::NONE,
|
|
aTextureFlags);
|
|
} else {
|
|
texture = new ShmemTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
gfx::BackendType::NONE,
|
|
aTextureFlags);
|
|
}
|
|
|
|
if (!texture->AllocateForYCbCr(aYSize, aCbCrSize, aStereoMode)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return texture.forget();
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<BufferTextureClient>
|
|
TextureClient::CreateWithBufferSize(ISurfaceAllocator* aAllocator,
|
|
gfx::SurfaceFormat aFormat,
|
|
size_t aSize,
|
|
TextureFlags aTextureFlags)
|
|
{
|
|
RefPtr<BufferTextureClient> texture;
|
|
if (aAllocator->IsSameProcess()) {
|
|
texture = new MemoryTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
gfx::BackendType::NONE,
|
|
aTextureFlags);
|
|
} else {
|
|
texture = new ShmemTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
gfx::BackendType::NONE,
|
|
aTextureFlags);
|
|
}
|
|
|
|
if (!texture->Allocate(aSize)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return texture.forget();
|
|
}
|
|
|
|
TextureClient::TextureClient(ISurfaceAllocator* aAllocator, TextureFlags aFlags)
|
|
: mAllocator(aAllocator)
|
|
, mFlags(aFlags)
|
|
, mShared(false)
|
|
, mValid(true)
|
|
, mAddedToCompositableClient(false)
|
|
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
|
|
, mPoolTracker(nullptr)
|
|
#endif
|
|
{}
|
|
|
|
TextureClient::~TextureClient()
|
|
{
|
|
// All the destruction code that may lead to virtual method calls must
|
|
// be in Finalize() which is called just before the destructor.
|
|
}
|
|
|
|
void
|
|
TextureClient::KeepUntilFullDeallocation(UniquePtr<KeepAlive> aKeep, bool aMainThreadOnly)
|
|
{
|
|
MOZ_ASSERT(mActor);
|
|
MOZ_ASSERT(!mActor->mKeep);
|
|
mActor->mKeep = Move(aKeep);
|
|
mActor->mMainThreadOnly = aMainThreadOnly;
|
|
}
|
|
|
|
void TextureClient::ForceRemove(bool sync)
|
|
{
|
|
if (mValid && mActor) {
|
|
if (sync || GetFlags() & TextureFlags::DEALLOCATE_CLIENT) {
|
|
MOZ_PERFORMANCE_WARNING("gfx", "TextureClient/Host pair requires synchronous deallocation");
|
|
if (mActor->IPCOpen()) {
|
|
mActor->SendClearTextureHostSync();
|
|
mActor->SendRemoveTexture();
|
|
}
|
|
} else {
|
|
if (mActor->IPCOpen()) {
|
|
mActor->SendRemoveTexture();
|
|
}
|
|
}
|
|
}
|
|
MarkInvalid();
|
|
}
|
|
|
|
bool TextureClient::CopyToTextureClient(TextureClient* aTarget,
|
|
const gfx::IntRect* aRect,
|
|
const gfx::IntPoint* aPoint)
|
|
{
|
|
MOZ_ASSERT(IsLocked());
|
|
MOZ_ASSERT(aTarget->IsLocked());
|
|
|
|
if (!aTarget->CanExposeDrawTarget() || !CanExposeDrawTarget()) {
|
|
return false;
|
|
}
|
|
|
|
RefPtr<DrawTarget> destinationTarget = aTarget->BorrowDrawTarget();
|
|
if (!destinationTarget) {
|
|
gfxWarning() << "TextureClient::CopyToTextureClient (dest) failed in BorrowDrawTarget";
|
|
return false;
|
|
}
|
|
|
|
RefPtr<DrawTarget> sourceTarget = BorrowDrawTarget();
|
|
if (!sourceTarget) {
|
|
gfxWarning() << "TextureClient::CopyToTextureClient (src) failed in BorrowDrawTarget";
|
|
return false;
|
|
}
|
|
|
|
RefPtr<gfx::SourceSurface> source = sourceTarget->Snapshot();
|
|
destinationTarget->CopySurface(source,
|
|
aRect ? *aRect : gfx::IntRect(gfx::IntPoint(0, 0), GetSize()),
|
|
aPoint ? *aPoint : gfx::IntPoint(0, 0));
|
|
return true;
|
|
}
|
|
|
|
void
|
|
TextureClient::Finalize()
|
|
{
|
|
MOZ_ASSERT(!IsLocked());
|
|
// Always make a temporary strong reference to the actor before we use it,
|
|
// in case TextureChild::ActorDestroy might null mActor concurrently.
|
|
RefPtr<TextureChild> actor = mActor;
|
|
|
|
if (actor) {
|
|
// The actor has a raw pointer to us, actor->mTextureClient.
|
|
// Null it before RemoveTexture calls to avoid invalid actor->mTextureClient
|
|
// when calling TextureChild::ActorDestroy()
|
|
actor->mTextureClient = nullptr;
|
|
// this will call ForceRemove in the right thread, using a sync proxy if needed
|
|
if (actor->GetForwarder()) {
|
|
actor->GetForwarder()->RemoveTexture(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool
|
|
TextureClient::ShouldDeallocateInDestructor() const
|
|
{
|
|
if (!IsAllocated()) {
|
|
return false;
|
|
}
|
|
|
|
// If we're meant to be deallocated by the host,
|
|
// but we haven't been shared yet or
|
|
// TextureFlags::DEALLOCATE_CLIENT is set, then we should
|
|
// deallocate on the client instead.
|
|
return !IsSharedWithCompositor() || (GetFlags() & TextureFlags::DEALLOCATE_CLIENT);
|
|
}
|
|
|
|
void
|
|
TextureClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
|
{
|
|
aStream << aPrefix;
|
|
aStream << nsPrintfCString("TextureClient (0x%p)", this).get();
|
|
AppendToString(aStream, GetSize(), " [size=", "]");
|
|
AppendToString(aStream, GetFormat(), " [format=", "]");
|
|
AppendToString(aStream, mFlags, " [flags=", "]");
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
if (gfxPrefs::LayersDumpTexture() || profiler_feature_active("layersdump")) {
|
|
nsAutoCString pfx(aPrefix);
|
|
pfx += " ";
|
|
|
|
aStream << "\n" << pfx.get() << "Surface: ";
|
|
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
|
|
if (dSurf) {
|
|
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
bool
|
|
ShmemTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor)
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
if (!IsAllocated() || GetFormat() == gfx::SurfaceFormat::UNKNOWN) {
|
|
return false;
|
|
}
|
|
|
|
aDescriptor = SurfaceDescriptorShmem(mShmem, GetFormat());
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ShmemTextureClient::Allocate(uint32_t aSize)
|
|
{
|
|
MOZ_ASSERT(mValid);
|
|
if (aSize > 0) {
|
|
SharedMemory::SharedMemoryType memType = OptimalShmemType();
|
|
mAllocated = GetAllocator()->AllocUnsafeShmem(aSize, memType, &mShmem);
|
|
}
|
|
return mAllocated;
|
|
}
|
|
|
|
uint8_t*
|
|
ShmemTextureClient::GetBuffer() const
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
if (mAllocated) {
|
|
return mShmem.get<uint8_t>();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
size_t
|
|
ShmemTextureClient::GetBufferSize() const
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
return mShmem.Size<uint8_t>();
|
|
}
|
|
|
|
ShmemTextureClient::ShmemTextureClient(ISurfaceAllocator* aAllocator,
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aFlags)
|
|
: BufferTextureClient(aAllocator, aFormat, aMoz2DBackend, aFlags)
|
|
, mAllocated(false)
|
|
{
|
|
MOZ_COUNT_CTOR(ShmemTextureClient);
|
|
}
|
|
|
|
ShmemTextureClient::~ShmemTextureClient()
|
|
{
|
|
MOZ_COUNT_DTOR(ShmemTextureClient);
|
|
if (ShouldDeallocateInDestructor()) {
|
|
// if the buffer has never been shared we must deallocate it or ir would
|
|
// leak.
|
|
GetAllocator()->DeallocShmem(mShmem);
|
|
}
|
|
}
|
|
|
|
bool
|
|
MemoryTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor)
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
if (!IsAllocated() || GetFormat() == gfx::SurfaceFormat::UNKNOWN) {
|
|
return false;
|
|
}
|
|
aDescriptor = SurfaceDescriptorMemory(reinterpret_cast<uintptr_t>(mBuffer),
|
|
GetFormat());
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
MemoryTextureClient::Allocate(uint32_t aSize)
|
|
{
|
|
MOZ_ASSERT(!mBuffer);
|
|
mBuffer = new (fallible) uint8_t[aSize];
|
|
if (!mBuffer) {
|
|
NS_WARNING("Failed to allocate buffer");
|
|
return false;
|
|
}
|
|
GfxMemoryImageReporter::DidAlloc(mBuffer);
|
|
mBufSize = aSize;
|
|
return true;
|
|
}
|
|
|
|
MemoryTextureClient::MemoryTextureClient(ISurfaceAllocator* aAllocator,
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aFlags)
|
|
: BufferTextureClient(aAllocator, aFormat, aMoz2DBackend, aFlags)
|
|
, mBuffer(nullptr)
|
|
, mBufSize(0)
|
|
{
|
|
MOZ_COUNT_CTOR(MemoryTextureClient);
|
|
}
|
|
|
|
MemoryTextureClient::~MemoryTextureClient()
|
|
{
|
|
MOZ_COUNT_DTOR(MemoryTextureClient);
|
|
if (mBuffer && ShouldDeallocateInDestructor()) {
|
|
// if the buffer has never been shared we must deallocate it or it would
|
|
// leak.
|
|
GfxMemoryImageReporter::WillFree(mBuffer);
|
|
delete [] mBuffer;
|
|
}
|
|
}
|
|
|
|
BufferTextureClient::BufferTextureClient(ISurfaceAllocator* aAllocator,
|
|
gfx::SurfaceFormat aFormat,
|
|
gfx::BackendType aMoz2DBackend,
|
|
TextureFlags aFlags)
|
|
: TextureClient(aAllocator, aFlags)
|
|
, mFormat(aFormat)
|
|
, mBackend(aMoz2DBackend)
|
|
, mOpenMode(OpenMode::OPEN_NONE)
|
|
, mLocked(false)
|
|
{}
|
|
|
|
BufferTextureClient::~BufferTextureClient()
|
|
{}
|
|
|
|
already_AddRefed<TextureClient>
|
|
BufferTextureClient::CreateSimilar(TextureFlags aFlags,
|
|
TextureAllocationFlags aAllocFlags) const
|
|
{
|
|
// This may return null
|
|
RefPtr<BufferTextureClient> newBufferTex = TextureClient::CreateForRawBufferAccess(
|
|
mAllocator, mFormat, mSize, mBackend, mFlags | aFlags, aAllocFlags
|
|
);
|
|
|
|
return newBufferTex.forget();
|
|
}
|
|
|
|
bool
|
|
BufferTextureClient::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
MOZ_ASSERT(mFormat != gfx::SurfaceFormat::YUV, "This textureClient cannot use YCbCr data");
|
|
MOZ_ASSERT(aSize.width > 0 && aSize.height > 0);
|
|
|
|
if (aSize.width <= 0 || aSize.height <= 0) {
|
|
gfxDebug() << "Asking for buffer of invalid size " << aSize.width << "x" << aSize.height;
|
|
return false;
|
|
}
|
|
|
|
uint32_t bufSize = ImageDataSerializer::ComputeMinBufferSize(aSize, mFormat);
|
|
if (!bufSize || !Allocate(bufSize)) {
|
|
return false;
|
|
}
|
|
|
|
if (aFlags & ALLOC_CLEAR_BUFFER) {
|
|
memset(GetBuffer(), 0, bufSize);
|
|
}
|
|
if (aFlags & ALLOC_CLEAR_BUFFER_WHITE) {
|
|
memset(GetBuffer(), 0xFF, bufSize);
|
|
}
|
|
|
|
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
|
serializer.InitializeBufferInfo(aSize, mFormat);
|
|
mSize = aSize;
|
|
return true;
|
|
}
|
|
|
|
gfx::DrawTarget*
|
|
BufferTextureClient::BorrowDrawTarget()
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
MOZ_ASSERT(mLocked, "BorrowDrawTarget should be called on locked textures only");
|
|
if (!mLocked) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (mDrawTarget) {
|
|
mDrawTarget->SetTransform(Matrix());
|
|
return mDrawTarget;
|
|
}
|
|
|
|
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
|
if (!serializer.IsValid()) {
|
|
return nullptr;
|
|
}
|
|
|
|
mDrawTarget = serializer.GetAsDrawTarget(mBackend);
|
|
if (mDrawTarget) {
|
|
return mDrawTarget;
|
|
}
|
|
|
|
mDrawTarget = serializer.GetAsDrawTarget(BackendType::CAIRO);
|
|
|
|
return mDrawTarget;
|
|
}
|
|
|
|
bool
|
|
BufferTextureClient::Lock(OpenMode aMode)
|
|
{
|
|
MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!");
|
|
mOpenMode = aMode;
|
|
mLocked = IsValid() && IsAllocated();;
|
|
return mLocked;
|
|
}
|
|
|
|
void
|
|
BufferTextureClient::Unlock()
|
|
{
|
|
MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!");
|
|
mLocked = false;
|
|
if (!mDrawTarget) {
|
|
return;
|
|
}
|
|
|
|
// see the comment on TextureClient::BorrowDrawTarget.
|
|
// This DrawTarget is internal to the TextureClient and is only exposed to the
|
|
// outside world between Lock() and Unlock(). This assertion checks that no outside
|
|
// reference remains by the time Unlock() is called.
|
|
MOZ_ASSERT(mDrawTarget->refCount() == 1);
|
|
|
|
if (mReadbackSink) {
|
|
RefPtr<SourceSurface> snapshot = mDrawTarget->Snapshot();
|
|
RefPtr<DataSourceSurface> dataSurf = snapshot->GetDataSurface();
|
|
mReadbackSink->ProcessReadback(dataSurf);
|
|
}
|
|
|
|
mDrawTarget->Flush();
|
|
}
|
|
|
|
bool
|
|
BufferTextureClient::UpdateYCbCr(const PlanarYCbCrData& aData)
|
|
{
|
|
MOZ_ASSERT(mLocked);
|
|
MOZ_ASSERT(mFormat == gfx::SurfaceFormat::YUV, "This textureClient can only use YCbCr data");
|
|
MOZ_ASSERT(!IsImmutable());
|
|
MOZ_ASSERT(IsValid());
|
|
MOZ_ASSERT(aData.mCbSkip == aData.mCrSkip);
|
|
|
|
YCbCrImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
|
MOZ_ASSERT(serializer.IsValid());
|
|
if (!serializer.CopyData(aData.mYChannel, aData.mCbChannel, aData.mCrChannel,
|
|
aData.mYSize, aData.mYStride,
|
|
aData.mCbCrSize, aData.mCbCrStride,
|
|
aData.mYSkip, aData.mCbSkip)) {
|
|
NS_WARNING("Failed to copy image data!");
|
|
return false;
|
|
}
|
|
|
|
if (TextureRequiresLocking(mFlags)) {
|
|
// We don't have support for proper locking yet, so we'll
|
|
// have to be immutable instead.
|
|
MarkImmutable();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
BufferTextureClient::AllocateForYCbCr(gfx::IntSize aYSize,
|
|
gfx::IntSize aCbCrSize,
|
|
StereoMode aStereoMode)
|
|
{
|
|
MOZ_ASSERT(IsValid());
|
|
|
|
size_t bufSize = YCbCrImageDataSerializer::ComputeMinBufferSize(aYSize,
|
|
aCbCrSize);
|
|
if (!bufSize || !Allocate(bufSize)) {
|
|
return false;
|
|
}
|
|
YCbCrImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
|
serializer.InitializeBufferInfo(aYSize,
|
|
aCbCrSize,
|
|
aStereoMode);
|
|
mSize = aYSize;
|
|
return true;
|
|
}
|
|
|
|
uint8_t*
|
|
BufferTextureClient::GetLockedData() const
|
|
{
|
|
MOZ_ASSERT(IsLocked());
|
|
|
|
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
|
MOZ_ASSERT(serializer.IsValid());
|
|
|
|
return serializer.GetData();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// SharedSurfaceTextureClient
|
|
|
|
SharedSurfaceTextureClient::SharedSurfaceTextureClient(ISurfaceAllocator* aAllocator,
|
|
TextureFlags aFlags,
|
|
gl::SharedSurface* surf)
|
|
: TextureClient(aAllocator, aFlags)
|
|
, mIsLocked(false)
|
|
, mSurf(surf)
|
|
, mGL(mSurf->mGL)
|
|
{
|
|
AddFlags(TextureFlags::DEALLOCATE_CLIENT);
|
|
}
|
|
|
|
SharedSurfaceTextureClient::~SharedSurfaceTextureClient()
|
|
{
|
|
// the data is owned externally.
|
|
}
|
|
|
|
bool
|
|
SharedSurfaceTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
|
|
{
|
|
aOutDescriptor = SharedSurfaceDescriptor((uintptr_t)mSurf);
|
|
return true;
|
|
}
|
|
|
|
already_AddRefed<SyncObject>
|
|
SyncObject::CreateSyncObject(SyncHandle aHandle)
|
|
{
|
|
if (!aHandle) {
|
|
return nullptr;
|
|
}
|
|
|
|
#ifdef XP_WIN
|
|
return MakeAndAddRef<SyncObjectD3D11>(aHandle);
|
|
#else
|
|
MOZ_ASSERT_UNREACHABLE();
|
|
return nullptr;
|
|
#endif
|
|
}
|
|
|
|
} // namespace layers
|
|
} // namespace mozilla
|