gfx/layers/Compositor.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/Compositor.h"
michael@0 7 #include "base/message_loop.h" // for MessageLoop
michael@0 8 #include "mozilla/layers/CompositorParent.h" // for CompositorParent
michael@0 9 #include "mozilla/layers/Effects.h" // for Effect, EffectChain, etc
michael@0 10 #include "mozilla/mozalloc.h" // for operator delete, etc
michael@0 11 #include "gfx2DGlue.h"
michael@0 12
michael@0 13 namespace mozilla {
michael@0 14 namespace gfx {
michael@0 15 class Matrix4x4;
michael@0 16 }
michael@0 17
michael@0 18 namespace layers {
michael@0 19
michael@0 20 /* static */ LayersBackend Compositor::sBackend = LayersBackend::LAYERS_NONE;
michael@0 21 /* static */ LayersBackend
michael@0 22 Compositor::GetBackend()
michael@0 23 {
michael@0 24 AssertOnCompositorThread();
michael@0 25 return sBackend;
michael@0 26 }
michael@0 27
michael@0 28 /* static */ void
michael@0 29 Compositor::SetBackend(LayersBackend backend)
michael@0 30 {
michael@0 31 if (sBackend != LayersBackend::LAYERS_NONE && sBackend != backend) {
michael@0 32 // Assert this once we figure out bug 972891.
michael@0 33 //MOZ_CRASH("Trying to use more than one OMTC compositor.");
michael@0 34
michael@0 35 #ifdef XP_MACOSX
michael@0 36 printf("ERROR: Changing compositor from %u to %u.\n",
michael@0 37 unsigned(sBackend), unsigned(backend));
michael@0 38 #endif
michael@0 39 }
michael@0 40 sBackend = backend;
michael@0 41 }
michael@0 42
michael@0 43 /* static */ void
michael@0 44 Compositor::AssertOnCompositorThread()
michael@0 45 {
michael@0 46 MOZ_ASSERT(CompositorParent::CompositorLoop() ==
michael@0 47 MessageLoop::current(),
michael@0 48 "Can only call this from the compositor thread!");
michael@0 49 }
michael@0 50
michael@0 51 bool
michael@0 52 Compositor::ShouldDrawDiagnostics(DiagnosticFlags aFlags)
michael@0 53 {
michael@0 54 if ((aFlags & DIAGNOSTIC_TILE) && !(mDiagnosticTypes & DIAGNOSTIC_TILE_BORDERS)) {
michael@0 55 return false;
michael@0 56 }
michael@0 57 if ((aFlags & DIAGNOSTIC_BIGIMAGE) &&
michael@0 58 !(mDiagnosticTypes & DIAGNOSTIC_BIGIMAGE_BORDERS)) {
michael@0 59 return false;
michael@0 60 }
michael@0 61 if (!mDiagnosticTypes) {
michael@0 62 return false;
michael@0 63 }
michael@0 64 return true;
michael@0 65 }
michael@0 66
michael@0 67 void
michael@0 68 Compositor::DrawDiagnostics(DiagnosticFlags aFlags,
michael@0 69 const nsIntRegion& aVisibleRegion,
michael@0 70 const gfx::Rect& aClipRect,
michael@0 71 const gfx::Matrix4x4& aTransform,
michael@0 72 uint32_t aFlashCounter)
michael@0 73 {
michael@0 74 if (!ShouldDrawDiagnostics(aFlags)) {
michael@0 75 return;
michael@0 76 }
michael@0 77
michael@0 78 if (aVisibleRegion.GetNumRects() > 1) {
michael@0 79 nsIntRegionRectIterator screenIter(aVisibleRegion);
michael@0 80
michael@0 81 while (const nsIntRect* rect = screenIter.Next())
michael@0 82 {
michael@0 83 DrawDiagnostics(aFlags | DIAGNOSTIC_REGION_RECT,
michael@0 84 ToRect(*rect), aClipRect, aTransform, aFlashCounter);
michael@0 85 }
michael@0 86 }
michael@0 87
michael@0 88 DrawDiagnostics(aFlags, ToRect(aVisibleRegion.GetBounds()),
michael@0 89 aClipRect, aTransform, aFlashCounter);
michael@0 90 }
michael@0 91
michael@0 92 void
michael@0 93 Compositor::DrawDiagnostics(DiagnosticFlags aFlags,
michael@0 94 const gfx::Rect& aVisibleRect,
michael@0 95 const gfx::Rect& aClipRect,
michael@0 96 const gfx::Matrix4x4& aTransform,
michael@0 97 uint32_t aFlashCounter)
michael@0 98 {
michael@0 99 if (!ShouldDrawDiagnostics(aFlags)) {
michael@0 100 return;
michael@0 101 }
michael@0 102
michael@0 103 DrawDiagnosticsInternal(aFlags, aVisibleRect, aClipRect, aTransform,
michael@0 104 aFlashCounter);
michael@0 105 }
michael@0 106
michael@0 107 gfx::Rect
michael@0 108 Compositor::ClipRectInLayersCoordinates(gfx::Rect aClip) const {
michael@0 109 gfx::Rect result;
michael@0 110 aClip = aClip + GetCurrentRenderTarget()->GetOrigin();
michael@0 111 gfx::IntSize destSize = GetWidgetSize();
michael@0 112
michael@0 113 switch (mScreenRotation) {
michael@0 114 case ROTATION_0:
michael@0 115 result = aClip;
michael@0 116 break;
michael@0 117 case ROTATION_90:
michael@0 118 result = gfx::Rect(aClip.y,
michael@0 119 destSize.width - aClip.x - aClip.width,
michael@0 120 aClip.height, aClip.width);
michael@0 121 break;
michael@0 122 case ROTATION_270:
michael@0 123 result = gfx::Rect(destSize.height - aClip.y - aClip.height,
michael@0 124 aClip.x,
michael@0 125 aClip.height, aClip.width);
michael@0 126 break;
michael@0 127 case ROTATION_180:
michael@0 128 result = gfx::Rect(destSize.width - aClip.x - aClip.width,
michael@0 129 destSize.height - aClip.y - aClip.height,
michael@0 130 aClip.width, aClip.height);
michael@0 131 break;
michael@0 132 // ScreenRotation has a sentinel value, need to catch it in the switch
michael@0 133 // statement otherwise the build fails (-WError)
michael@0 134 default: {}
michael@0 135 }
michael@0 136 return result;
michael@0 137 }
michael@0 138
michael@0 139 void
michael@0 140 Compositor::DrawDiagnosticsInternal(DiagnosticFlags aFlags,
michael@0 141 const gfx::Rect& aVisibleRect,
michael@0 142 const gfx::Rect& aClipRect,
michael@0 143 const gfx::Matrix4x4& aTransform,
michael@0 144 uint32_t aFlashCounter)
michael@0 145 {
michael@0 146 #ifdef MOZ_B2G
michael@0 147 int lWidth = 4;
michael@0 148 #elif defined(ANDROID)
michael@0 149 int lWidth = 10;
michael@0 150 #else
michael@0 151 int lWidth = 2;
michael@0 152 #endif
michael@0 153 float opacity = 0.7f;
michael@0 154
michael@0 155 gfx::Color color;
michael@0 156 if (aFlags & DIAGNOSTIC_CONTENT) {
michael@0 157 color = gfx::Color(0.0f, 1.0f, 0.0f, 1.0f); // green
michael@0 158 if (aFlags & DIAGNOSTIC_COMPONENT_ALPHA) {
michael@0 159 color = gfx::Color(0.0f, 1.0f, 1.0f, 1.0f); // greenish blue
michael@0 160 }
michael@0 161 } else if (aFlags & DIAGNOSTIC_IMAGE) {
michael@0 162 color = gfx::Color(1.0f, 0.0f, 0.0f, 1.0f); // red
michael@0 163 } else if (aFlags & DIAGNOSTIC_COLOR) {
michael@0 164 color = gfx::Color(0.0f, 0.0f, 1.0f, 1.0f); // blue
michael@0 165 } else if (aFlags & DIAGNOSTIC_CONTAINER) {
michael@0 166 color = gfx::Color(0.8f, 0.0f, 0.8f, 1.0f); // purple
michael@0 167 }
michael@0 168
michael@0 169 // make tile borders a bit more transparent to keep layer borders readable.
michael@0 170 if (aFlags & DIAGNOSTIC_TILE ||
michael@0 171 aFlags & DIAGNOSTIC_BIGIMAGE ||
michael@0 172 aFlags & DIAGNOSTIC_REGION_RECT) {
michael@0 173 lWidth = 1;
michael@0 174 opacity = 0.5f;
michael@0 175 color.r *= 0.7f;
michael@0 176 color.g *= 0.7f;
michael@0 177 color.b *= 0.7f;
michael@0 178 }
michael@0 179
michael@0 180 if (mDiagnosticTypes & DIAGNOSTIC_FLASH_BORDERS) {
michael@0 181 float flash = (float)aFlashCounter / (float)DIAGNOSTIC_FLASH_COUNTER_MAX;
michael@0 182 color.r *= flash;
michael@0 183 color.g *= flash;
michael@0 184 color.b *= flash;
michael@0 185 }
michael@0 186
michael@0 187 EffectChain effects;
michael@0 188
michael@0 189 effects.mPrimaryEffect = new EffectSolidColor(color);
michael@0 190 // left
michael@0 191 this->DrawQuad(gfx::Rect(aVisibleRect.x, aVisibleRect.y,
michael@0 192 lWidth, aVisibleRect.height),
michael@0 193 aClipRect, effects, opacity,
michael@0 194 aTransform);
michael@0 195 // top
michael@0 196 this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y,
michael@0 197 aVisibleRect.width - 2 * lWidth, lWidth),
michael@0 198 aClipRect, effects, opacity,
michael@0 199 aTransform);
michael@0 200 // right
michael@0 201 this->DrawQuad(gfx::Rect(aVisibleRect.x + aVisibleRect.width - lWidth, aVisibleRect.y,
michael@0 202 lWidth, aVisibleRect.height),
michael@0 203 aClipRect, effects, opacity,
michael@0 204 aTransform);
michael@0 205 // bottom
michael@0 206 this->DrawQuad(gfx::Rect(aVisibleRect.x + lWidth, aVisibleRect.y + aVisibleRect.height-lWidth,
michael@0 207 aVisibleRect.width - 2 * lWidth, lWidth),
michael@0 208 aClipRect, effects, opacity,
michael@0 209 aTransform);
michael@0 210 }
michael@0 211
michael@0 212 } // namespace
michael@0 213 } // namespace

mercurial