Files
palemoon27/gfx/layers/client/ClientCanvasLayer.cpp
T
roytam1 3b276a5398 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1077651 Measure frame uniformity by synthesizing native events. r=kats,mrbkap (95a796145)
- Bug 1154231 - Part 2. Reclaim cached resources when memory-pressure occurs. r=mattwoodrow (cff6ac1f9)
- fix build (15112d396)
- Bug 1155649 - XFlush at the end of frames when OMTC is enabled on Linux. r=jrmuizel (8bc22dd42)
- Bug 1158120 - Edit include and comments that contained gfxIntSize and nsIntSize. r=nical (fc25c0c96)
- Bug 1167235 - Part 1: Add code exposing a PersistentBufferProvider. r=nical (8340f8ede)
- Bug 1134251 - Disable broken B2G Desktop tests on Mulet. r=jmaher, r=jgilbert (db4d4253c)
- Bug 1134271 - Skip conformance/canvas/buffer-offscreen-test.html on Android; r=jgilbert (2fe8d8623)
- Bug 1124996 - Remove expected fail on OSX 10.10. r=jgilbert (388438a7e)
- Bug 1145492 - Update FramebufferTexture2D to allow binding mipmaps. r=jgilbert (5e4c6bf95)
- Bug 1158089 - Remove LAYERS_D3D10 enum value since it's unused. r=Bas (720d3b3b4)
- Bug 1156058 - Null pointer check. r=jgilbert (f9b9c6ca6)
- Bug 1131463 - Report AtomicRefCounterWithFinalize doing the wrong thing with AddRef and Release in release build as well. r=sotaro (7c009766e)
- Bug 1142071 - Re-add WaitForBufferOwnership() r=jgilbert (0753bcd25)
- partial revert of patch not found... (4ed1e76f1)
- Bug 1143979 - Use RAII local instead of useless temporary. - r=kamidphish (d8a50143f)
- Bug 1017865 - Refactor attach/detach for FB attachments. - r=kamidphish (9c7e41065)
- Bug 1144906 - Add accel E10S backend for WebGL compositing. - r=jrmuizel,mattwoodrow,nical,sotaro (559ab767f)
- Bug 1167235 - Part 2: Add support for the basic buffer provider to CanvasLayer. r=nical (4ac399c16)
- Bug 1155252 - Add a pref to control the maximum canvas 2d size and set it to 0x7ff. r=jrmuizel (7ae6cde3f)
- Bug 1167235 - Part 3: Switch CanvasRenderingContext2D to use the new BufferProvider API. r=nical (f678c14ab)
- Bug 1192159: Do not forget about the transform when not using an active target. r=jrmuizel (a4bd28a75)
- Bug 1167235 - Part 4: Remove DrawTarget as a possible means of initializing Canvas layers. r=nical (dbd153cfb)
- Bug 1167235 - Part 5: Make CanvasLayerComposite ImageHost type agnostic. r=nical (df15bd85d)
- Bug 1167235 - Part 6: Fix up HasInternalBuffer return value on TextureHostDirectUpload. r=nical (437cd1680)
- Bug 1091851 - Fix a race condition in Sqlite.jsm shutdown. r=mak (8b6ac8848)
2020-12-09 23:03:57 +08:00

203 lines
5.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; 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 "ClientCanvasLayer.h"
#include "GLContext.h" // for GLContext
#include "GLScreenBuffer.h" // for GLScreenBuffer
#include "GeckoProfiler.h" // for PROFILER_LABEL
#include "SharedSurfaceEGL.h" // for SurfaceFactory_EGLImage
#include "SharedSurfaceGL.h" // for SurfaceFactory_GLTexture, etc
#include "ClientLayerManager.h" // for ClientLayerManager, etc
#include "mozilla/gfx/Point.h" // for IntSize
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersTypes.h"
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsISupportsImpl.h" // for Layer::AddRef, etc
#include "nsRect.h" // for mozilla::gfx::IntRect
#include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
#include "gfxPrefs.h" // for WebGLForceLayersReadback
#ifdef XP_WIN
#include "SharedSurfaceANGLE.h" // for SurfaceFactory_ANGLEShareHandle
#include "gfxWindowsPlatform.h"
#endif
#ifdef MOZ_WIDGET_GONK
#include "SharedSurfaceGralloc.h"
#endif
#ifdef XP_MACOSX
#include "SharedSurfaceIO.h"
#endif
using namespace mozilla::gfx;
using namespace mozilla::gl;
namespace mozilla {
namespace layers {
ClientCanvasLayer::~ClientCanvasLayer()
{
MOZ_COUNT_DTOR(ClientCanvasLayer);
if (mCanvasClient) {
mCanvasClient->OnDetach();
mCanvasClient = nullptr;
}
}
void
ClientCanvasLayer::Initialize(const Data& aData)
{
CopyableCanvasLayer::Initialize(aData);
mCanvasClient = nullptr;
if (!mGLContext)
return;
GLScreenBuffer* screen = mGLContext->Screen();
SurfaceCaps caps;
if (mGLFrontbuffer) {
// The screen caps are irrelevant if we're using a separate frontbuffer.
caps = mGLFrontbuffer->mHasAlpha ? SurfaceCaps::ForRGBA()
: SurfaceCaps::ForRGB();
} else {
MOZ_ASSERT(screen);
caps = screen->mCaps;
}
MOZ_ASSERT(caps.alpha == aData.mHasAlpha);
auto forwarder = ClientManager()->AsShadowForwarder();
mFlags = TextureFlags::ORIGIN_BOTTOM_LEFT;
if (!aData.mIsGLAlphaPremult) {
mFlags |= TextureFlags::NON_PREMULTIPLIED;
}
UniquePtr<SurfaceFactory> factory;
if (!gfxPrefs::WebGLForceLayersReadback()) {
switch (forwarder->GetCompositorBackendType()) {
case mozilla::layers::LayersBackend::LAYERS_OPENGL: {
#if defined(XP_MACOSX)
factory = SurfaceFactory_IOSurface::Create(mGLContext, caps, forwarder, mFlags);
#elif defined(MOZ_WIDGET_GONK)
factory = MakeUnique<SurfaceFactory_Gralloc>(mGLContext, caps, forwarder, mFlags);
#else
if (mGLContext->GetContextType() == GLContextType::EGL) {
bool isCrossProcess = (XRE_GetProcessType() != GeckoProcessType_Default);
if (!isCrossProcess) {
factory = SurfaceFactory_EGLImage::Create(mGLContext, caps, forwarder,
mFlags);
}
}
#endif
break;
}
case mozilla::layers::LayersBackend::LAYERS_D3D11: {
#ifdef XP_WIN
if (mGLContext->IsANGLE() &&
DoesD3D11TextureSharingWork(gfxWindowsPlatform::GetPlatform()->GetD3D11Device()))
{
factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext, caps, forwarder,
mFlags);
}
#endif
break;
}
default:
break;
}
}
if (mGLFrontbuffer) {
// We're using a source other than the one in the default screen.
// (SkiaGL)
mFactory = Move(factory);
if (!mFactory) {
// Absolutely must have a factory here, so create a basic one
mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps, mFlags);
}
} else {
if (factory)
screen->Morph(Move(factory));
}
}
void
ClientCanvasLayer::RenderLayer()
{
PROFILER_LABEL("ClientCanvasLayer", "RenderLayer",
js::ProfileEntry::Category::GRAPHICS);
if (GetMaskLayer()) {
ToClientLayer(GetMaskLayer())->RenderLayer();
}
if (!IsDirty()) {
return;
}
Painted();
if (!mCanvasClient) {
TextureFlags flags = TextureFlags::IMMEDIATE_UPLOAD;
if (mOriginPos == gl::OriginPos::BottomLeft) {
flags |= TextureFlags::ORIGIN_BOTTOM_LEFT;
}
if (!mGLContext) {
// We don't support locking for buffer surfaces currently
flags |= TextureFlags::IMMEDIATE_UPLOAD;
}
if (!mIsAlphaPremultiplied) {
flags |= TextureFlags::NON_PREMULTIPLIED;
}
mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
ClientManager()->AsShadowForwarder(),
flags);
if (!mCanvasClient) {
return;
}
if (HasShadow()) {
mCanvasClient->Connect();
ClientManager()->AsShadowForwarder()->Attach(mCanvasClient, this);
}
}
FirePreTransactionCallback();
mCanvasClient->Update(gfx::IntSize(mBounds.width, mBounds.height), this);
FireDidTransactionCallback();
ClientManager()->Hold(this);
mCanvasClient->Updated();
mCanvasClient->OnTransaction();
}
CanvasClient::CanvasClientType
ClientCanvasLayer::GetCanvasClientType()
{
if (mGLContext) {
return CanvasClient::CanvasClientTypeShSurf;
}
return CanvasClient::CanvasClientSurface;
}
already_AddRefed<CanvasLayer>
ClientLayerManager::CreateCanvasLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
nsRefPtr<ClientCanvasLayer> layer =
new ClientCanvasLayer(this);
CREATE_SHADOW(Canvas);
return layer.forget();
}
} // namespace layers
} // namespace mozilla