gfx/layers/client/CanvasClient.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 20; 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 "mozilla/layers/CanvasClient.h"
michael@0 7 #include "ClientCanvasLayer.h" // for ClientCanvasLayer
michael@0 8 #include "GLContext.h" // for GLContext
michael@0 9 #include "GLScreenBuffer.h" // for GLScreenBuffer
michael@0 10 #include "SurfaceStream.h" // for SurfaceStream
michael@0 11 #include "SurfaceTypes.h" // for SurfaceStreamHandle
michael@0 12 #include "gfx2DGlue.h" // for ImageFormatToSurfaceFormat
michael@0 13 #include "gfxPlatform.h" // for gfxPlatform
michael@0 14 #include "mozilla/gfx/BaseSize.h" // for BaseSize
michael@0 15 #include "mozilla/layers/CompositableForwarder.h"
michael@0 16 #include "mozilla/layers/GrallocTextureClient.h"
michael@0 17 #include "mozilla/layers/LayersTypes.h"
michael@0 18 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc
michael@0 19 #include "mozilla/layers/TextureClientOGL.h"
michael@0 20 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 21 #include "nsDebug.h" // for printf_stderr, NS_ASSERTION
michael@0 22 #include "nsXULAppAPI.h" // for XRE_GetProcessType, etc
michael@0 23 #ifdef MOZ_WIDGET_GONK
michael@0 24 #include "SharedSurfaceGralloc.h"
michael@0 25 #endif
michael@0 26
michael@0 27 using namespace mozilla::gfx;
michael@0 28 using namespace mozilla::gl;
michael@0 29
michael@0 30 namespace mozilla {
michael@0 31 namespace layers {
michael@0 32
michael@0 33 /* static */ TemporaryRef<CanvasClient>
michael@0 34 CanvasClient::CreateCanvasClient(CanvasClientType aType,
michael@0 35 CompositableForwarder* aForwarder,
michael@0 36 TextureFlags aFlags)
michael@0 37 {
michael@0 38 #ifndef MOZ_WIDGET_GONK
michael@0 39 if (XRE_GetProcessType() != GeckoProcessType_Default) {
michael@0 40 NS_WARNING("Most platforms still need an optimized way to share GL cross process.");
michael@0 41 return new CanvasClient2D(aForwarder, aFlags);
michael@0 42 }
michael@0 43 #endif
michael@0 44 if (aType == CanvasClientGLContext &&
michael@0 45 aForwarder->GetCompositorBackendType() == LayersBackend::LAYERS_OPENGL) {
michael@0 46 aFlags |= TEXTURE_DEALLOCATE_CLIENT;
michael@0 47 return new CanvasClientSurfaceStream(aForwarder, aFlags);
michael@0 48 }
michael@0 49 return new CanvasClient2D(aForwarder, aFlags);
michael@0 50 }
michael@0 51
michael@0 52 void
michael@0 53 CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
michael@0 54 {
michael@0 55 if (mBuffer &&
michael@0 56 (mBuffer->IsImmutable() || mBuffer->GetSize() != aSize)) {
michael@0 57 GetForwarder()->RemoveTextureFromCompositable(this, mBuffer);
michael@0 58 mBuffer = nullptr;
michael@0 59 }
michael@0 60
michael@0 61 bool bufferCreated = false;
michael@0 62 if (!mBuffer) {
michael@0 63 bool isOpaque = (aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE);
michael@0 64 gfxContentType contentType = isOpaque
michael@0 65 ? gfxContentType::COLOR
michael@0 66 : gfxContentType::COLOR_ALPHA;
michael@0 67 gfxImageFormat format
michael@0 68 = gfxPlatform::GetPlatform()->OptimalFormatForContent(contentType);
michael@0 69 uint32_t flags = TEXTURE_FLAGS_DEFAULT;
michael@0 70 if (mTextureFlags & TEXTURE_NEEDS_Y_FLIP) {
michael@0 71 flags |= TEXTURE_NEEDS_Y_FLIP;
michael@0 72 }
michael@0 73 mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format),
michael@0 74 flags,
michael@0 75 gfxPlatform::GetPlatform()->GetPreferredCanvasBackend());
michael@0 76 MOZ_ASSERT(mBuffer->CanExposeDrawTarget());
michael@0 77 mBuffer->AllocateForSurface(aSize);
michael@0 78
michael@0 79 bufferCreated = true;
michael@0 80 }
michael@0 81
michael@0 82 if (!mBuffer->Lock(OPEN_WRITE_ONLY)) {
michael@0 83 mBuffer = nullptr;
michael@0 84 return;
michael@0 85 }
michael@0 86
michael@0 87 bool updated = false;
michael@0 88 {
michael@0 89 // Restrict drawTarget to a scope so that terminates before Unlock.
michael@0 90 RefPtr<DrawTarget> target =
michael@0 91 mBuffer->GetAsDrawTarget();
michael@0 92 if (target) {
michael@0 93 aLayer->UpdateTarget(target);
michael@0 94 updated = true;
michael@0 95 }
michael@0 96 }
michael@0 97 mBuffer->Unlock();
michael@0 98
michael@0 99 if (bufferCreated && !AddTextureClient(mBuffer)) {
michael@0 100 mBuffer = nullptr;
michael@0 101 return;
michael@0 102 }
michael@0 103
michael@0 104 if (updated) {
michael@0 105 GetForwarder()->UpdatedTexture(this, mBuffer, nullptr);
michael@0 106 GetForwarder()->UseTexture(this, mBuffer);
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 CanvasClientSurfaceStream::CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder,
michael@0 111 TextureFlags aFlags)
michael@0 112 : CanvasClient(aLayerForwarder, aFlags)
michael@0 113 {
michael@0 114 }
michael@0 115
michael@0 116 void
michael@0 117 CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
michael@0 118 {
michael@0 119 aLayer->mGLContext->MakeCurrent();
michael@0 120 GLScreenBuffer* screen = aLayer->mGLContext->Screen();
michael@0 121 SurfaceStream* stream = nullptr;
michael@0 122
michael@0 123 if (aLayer->mStream) {
michael@0 124 stream = aLayer->mStream;
michael@0 125
michael@0 126 // Copy our current surface to the current producer surface in our stream, then
michael@0 127 // call SwapProducer to make a new buffer ready.
michael@0 128 stream->CopySurfaceToProducer(aLayer->mTextureSurface, aLayer->mFactory);
michael@0 129 stream->SwapProducer(aLayer->mFactory, gfx::IntSize(aSize.width, aSize.height));
michael@0 130 } else {
michael@0 131 stream = screen->Stream();
michael@0 132 }
michael@0 133
michael@0 134 bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default);
michael@0 135 bool bufferCreated = false;
michael@0 136 if (isCrossProcess) {
michael@0 137 #ifdef MOZ_WIDGET_GONK
michael@0 138 SharedSurface* surf = stream->SwapConsumer();
michael@0 139 if (!surf) {
michael@0 140 printf_stderr("surf is null post-SwapConsumer!\n");
michael@0 141 return;
michael@0 142 }
michael@0 143
michael@0 144 if (surf->Type() != SharedSurfaceType::Gralloc) {
michael@0 145 printf_stderr("Unexpected non-Gralloc SharedSurface in IPC path!");
michael@0 146 MOZ_ASSERT(false);
michael@0 147 return;
michael@0 148 }
michael@0 149
michael@0 150 SharedSurface_Gralloc* grallocSurf = SharedSurface_Gralloc::Cast(surf);
michael@0 151
michael@0 152 RefPtr<GrallocTextureClientOGL> grallocTextureClient =
michael@0 153 static_cast<GrallocTextureClientOGL*>(grallocSurf->GetTextureClient());
michael@0 154
michael@0 155 // If IPDLActor is null means this TextureClient didn't AddTextureClient yet
michael@0 156 if (!grallocTextureClient->GetIPDLActor()) {
michael@0 157 grallocTextureClient->SetTextureFlags(mTextureInfo.mTextureFlags);
michael@0 158 AddTextureClient(grallocTextureClient);
michael@0 159 }
michael@0 160
michael@0 161 if (grallocTextureClient->GetIPDLActor()) {
michael@0 162 GetForwarder()->UseTexture(this, grallocTextureClient);
michael@0 163 }
michael@0 164 #else
michael@0 165 printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!");
michael@0 166 MOZ_ASSERT(false);
michael@0 167 #endif
michael@0 168 } else {
michael@0 169 if (!mBuffer) {
michael@0 170 StreamTextureClientOGL* textureClient =
michael@0 171 new StreamTextureClientOGL(mTextureInfo.mTextureFlags);
michael@0 172 textureClient->InitWith(stream);
michael@0 173 mBuffer = textureClient;
michael@0 174 bufferCreated = true;
michael@0 175 }
michael@0 176
michael@0 177 if (bufferCreated && !AddTextureClient(mBuffer)) {
michael@0 178 mBuffer = nullptr;
michael@0 179 }
michael@0 180
michael@0 181 if (mBuffer) {
michael@0 182 GetForwarder()->UseTexture(this, mBuffer);
michael@0 183 }
michael@0 184 }
michael@0 185
michael@0 186 aLayer->Painted();
michael@0 187 }
michael@0 188
michael@0 189 }
michael@0 190 }

mercurial