gfx/layers/client/ClientCanvasLayer.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "ClientCanvasLayer.h"
michael@0 7 #include "GLContext.h" // for GLContext
michael@0 8 #include "GLScreenBuffer.h" // for GLScreenBuffer
michael@0 9 #include "GeckoProfiler.h" // for PROFILER_LABEL
michael@0 10 #include "SharedSurfaceEGL.h" // for SurfaceFactory_EGLImage
michael@0 11 #include "SharedSurfaceGL.h" // for SurfaceFactory_GLTexture, etc
michael@0 12 #include "SurfaceStream.h" // for SurfaceStream, etc
michael@0 13 #include "SurfaceTypes.h" // for SurfaceStreamType
michael@0 14 #include "ClientLayerManager.h" // for ClientLayerManager, etc
michael@0 15 #include "mozilla/gfx/Point.h" // for IntSize
michael@0 16 #include "mozilla/layers/CompositorTypes.h"
michael@0 17 #include "mozilla/layers/LayersTypes.h"
michael@0 18 #include "nsCOMPtr.h" // for already_AddRefed
michael@0 19 #include "nsISupportsImpl.h" // for Layer::AddRef, etc
michael@0 20 #include "nsRect.h" // for nsIntRect
michael@0 21 #include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
michael@0 22 #ifdef MOZ_WIDGET_GONK
michael@0 23 #include "SharedSurfaceGralloc.h"
michael@0 24 #endif
michael@0 25 #ifdef XP_MACOSX
michael@0 26 #include "SharedSurfaceIO.h"
michael@0 27 #endif
michael@0 28 #include "gfxPrefs.h" // for WebGLForceLayersReadback
michael@0 29
michael@0 30 using namespace mozilla::gfx;
michael@0 31 using namespace mozilla::gl;
michael@0 32
michael@0 33 namespace mozilla {
michael@0 34 namespace layers {
michael@0 35
michael@0 36 ClientCanvasLayer::~ClientCanvasLayer()
michael@0 37 {
michael@0 38 MOZ_COUNT_DTOR(ClientCanvasLayer);
michael@0 39 if (mCanvasClient) {
michael@0 40 mCanvasClient->OnDetach();
michael@0 41 mCanvasClient = nullptr;
michael@0 42 }
michael@0 43 if (mTextureSurface) {
michael@0 44 delete mTextureSurface;
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 void
michael@0 49 ClientCanvasLayer::Initialize(const Data& aData)
michael@0 50 {
michael@0 51 CopyableCanvasLayer::Initialize(aData);
michael@0 52
michael@0 53 mCanvasClient = nullptr;
michael@0 54
michael@0 55 if (mGLContext) {
michael@0 56 GLScreenBuffer* screen = mGLContext->Screen();
michael@0 57
michael@0 58 SurfaceCaps caps = screen->Caps();
michael@0 59 if (mStream) {
michael@0 60 // The screen caps are irrelevant if we're using a separate stream
michael@0 61 caps = GetContentFlags() & CONTENT_OPAQUE ? SurfaceCaps::ForRGB() : SurfaceCaps::ForRGBA();
michael@0 62 }
michael@0 63
michael@0 64 SurfaceStreamType streamType =
michael@0 65 SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread,
michael@0 66 screen->PreserveBuffer());
michael@0 67 SurfaceFactory_GL* factory = nullptr;
michael@0 68 if (!gfxPrefs::WebGLForceLayersReadback()) {
michael@0 69 if (ClientManager()->AsShadowForwarder()->GetCompositorBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) {
michael@0 70 if (mGLContext->GetContextType() == GLContextType::EGL) {
michael@0 71 bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
michael@0 72
michael@0 73 if (!isCrossProcess) {
michael@0 74 // [Basic/OGL Layers, OMTC] WebGL layer init.
michael@0 75 factory = SurfaceFactory_EGLImage::Create(mGLContext, caps);
michael@0 76 } else {
michael@0 77 // [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing)
michael@0 78 #ifdef MOZ_WIDGET_GONK
michael@0 79 factory = new SurfaceFactory_Gralloc(mGLContext, caps, ClientManager()->AsShadowForwarder());
michael@0 80 #else
michael@0 81 // we could do readback here maybe
michael@0 82 NS_NOTREACHED("isCrossProcess but not on native B2G!");
michael@0 83 #endif
michael@0 84 }
michael@0 85 } else {
michael@0 86 // [Basic Layers, OMTC] WebGL layer init.
michael@0 87 // Well, this *should* work...
michael@0 88 #ifdef XP_MACOSX
michael@0 89 factory = new SurfaceFactory_IOSurface(mGLContext, caps);
michael@0 90 #else
michael@0 91 factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps);
michael@0 92 #endif
michael@0 93 }
michael@0 94 }
michael@0 95 }
michael@0 96
michael@0 97 if (mStream) {
michael@0 98 // We're using a stream other than the one in the default screen
michael@0 99 mFactory = factory;
michael@0 100 if (!mFactory) {
michael@0 101 // Absolutely must have a factory here, so create a basic one
michael@0 102 mFactory = new SurfaceFactory_Basic(mGLContext, caps);
michael@0 103 }
michael@0 104
michael@0 105 gfx::IntSize size = gfx::IntSize(aData.mSize.width, aData.mSize.height);
michael@0 106 mTextureSurface = SharedSurface_GLTexture::Create(mGLContext, mGLContext,
michael@0 107 mGLContext->GetGLFormats(),
michael@0 108 size, caps.alpha, aData.mTexID);
michael@0 109 SharedSurface* producer = mStream->SwapProducer(mFactory, size);
michael@0 110 if (!producer) {
michael@0 111 // Fallback to basic factory
michael@0 112 delete mFactory;
michael@0 113 mFactory = new SurfaceFactory_Basic(mGLContext, caps);
michael@0 114 producer = mStream->SwapProducer(mFactory, size);
michael@0 115 MOZ_ASSERT(producer, "Failed to create initial canvas surface with basic factory");
michael@0 116 }
michael@0 117 } else if (factory) {
michael@0 118 screen->Morph(factory, streamType);
michael@0 119 }
michael@0 120 }
michael@0 121 }
michael@0 122
michael@0 123 void
michael@0 124 ClientCanvasLayer::RenderLayer()
michael@0 125 {
michael@0 126 PROFILER_LABEL("ClientCanvasLayer", "Paint");
michael@0 127 if (!IsDirty()) {
michael@0 128 return;
michael@0 129 }
michael@0 130
michael@0 131 if (GetMaskLayer()) {
michael@0 132 ToClientLayer(GetMaskLayer())->RenderLayer();
michael@0 133 }
michael@0 134
michael@0 135 if (!mCanvasClient) {
michael@0 136 TextureFlags flags = TEXTURE_IMMEDIATE_UPLOAD;
michael@0 137 if (mNeedsYFlip) {
michael@0 138 flags |= TEXTURE_NEEDS_Y_FLIP;
michael@0 139 }
michael@0 140
michael@0 141 if (!mGLContext) {
michael@0 142 // We don't support locking for buffer surfaces currently
michael@0 143 flags |= TEXTURE_IMMEDIATE_UPLOAD;
michael@0 144 } else {
michael@0 145 // GLContext's SurfaceStream handles ownership itself,
michael@0 146 // and doesn't require layers to do any deallocation.
michael@0 147 flags |= TEXTURE_DEALLOCATE_CLIENT;
michael@0 148 }
michael@0 149 mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(),
michael@0 150 ClientManager()->AsShadowForwarder(), flags);
michael@0 151 if (!mCanvasClient) {
michael@0 152 return;
michael@0 153 }
michael@0 154 if (HasShadow()) {
michael@0 155 mCanvasClient->Connect();
michael@0 156 ClientManager()->AsShadowForwarder()->Attach(mCanvasClient, this);
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 FirePreTransactionCallback();
michael@0 161 mCanvasClient->Update(gfx::IntSize(mBounds.width, mBounds.height), this);
michael@0 162
michael@0 163 FireDidTransactionCallback();
michael@0 164
michael@0 165 ClientManager()->Hold(this);
michael@0 166 mCanvasClient->Updated();
michael@0 167 mCanvasClient->OnTransaction();
michael@0 168 }
michael@0 169
michael@0 170 already_AddRefed<CanvasLayer>
michael@0 171 ClientLayerManager::CreateCanvasLayer()
michael@0 172 {
michael@0 173 NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
michael@0 174 nsRefPtr<ClientCanvasLayer> layer =
michael@0 175 new ClientCanvasLayer(this);
michael@0 176 CREATE_SHADOW(Canvas);
michael@0 177 return layer.forget();
michael@0 178 }
michael@0 179
michael@0 180 }
michael@0 181 }

mercurial