Wed, 31 Dec 2014 06:09:35 +0100
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: 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/ContentClient.h" |
michael@0 | 7 | #include "BasicLayers.h" // for BasicLayerManager |
michael@0 | 8 | #include "gfxColor.h" // for gfxRGBA |
michael@0 | 9 | #include "gfxContext.h" // for gfxContext, etc |
michael@0 | 10 | #include "gfxPlatform.h" // for gfxPlatform |
michael@0 | 11 | #include "gfxPrefs.h" // for gfxPrefs |
michael@0 | 12 | #include "gfxPoint.h" // for gfxIntSize, gfxPoint |
michael@0 | 13 | #include "gfxTeeSurface.h" // for gfxTeeSurface |
michael@0 | 14 | #include "gfxUtils.h" // for gfxUtils |
michael@0 | 15 | #include "ipc/ShadowLayers.h" // for ShadowLayerForwarder |
michael@0 | 16 | #include "mozilla/ArrayUtils.h" // for ArrayLength |
michael@0 | 17 | #include "mozilla/gfx/2D.h" // for DrawTarget, Factory |
michael@0 | 18 | #include "mozilla/gfx/BasePoint.h" // for BasePoint |
michael@0 | 19 | #include "mozilla/gfx/BaseSize.h" // for BaseSize |
michael@0 | 20 | #include "mozilla/gfx/Rect.h" // for Rect |
michael@0 | 21 | #include "mozilla/gfx/Types.h" |
michael@0 | 22 | #include "mozilla/layers/LayerManagerComposite.h" |
michael@0 | 23 | #include "mozilla/layers/LayersMessages.h" // for ThebesBufferData |
michael@0 | 24 | #include "mozilla/layers/LayersTypes.h" |
michael@0 | 25 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 26 | #include "nsDebug.h" // for NS_ASSERTION, NS_WARNING, etc |
michael@0 | 27 | #include "nsISupportsImpl.h" // for gfxContext::Release, etc |
michael@0 | 28 | #include "nsIWidget.h" // for nsIWidget |
michael@0 | 29 | #include "prenv.h" // for PR_GetEnv |
michael@0 | 30 | #ifdef XP_WIN |
michael@0 | 31 | #include "gfxWindowsPlatform.h" |
michael@0 | 32 | #endif |
michael@0 | 33 | #include "gfx2DGlue.h" |
michael@0 | 34 | |
michael@0 | 35 | namespace mozilla { |
michael@0 | 36 | |
michael@0 | 37 | using namespace gfx; |
michael@0 | 38 | |
michael@0 | 39 | namespace layers { |
michael@0 | 40 | |
michael@0 | 41 | static TextureFlags TextureFlagsForRotatedContentBufferFlags(uint32_t aBufferFlags) |
michael@0 | 42 | { |
michael@0 | 43 | TextureFlags result = 0; |
michael@0 | 44 | |
michael@0 | 45 | if (aBufferFlags & RotatedContentBuffer::BUFFER_COMPONENT_ALPHA) { |
michael@0 | 46 | result |= TEXTURE_COMPONENT_ALPHA; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | if (aBufferFlags & RotatedContentBuffer::ALLOW_REPEAT) { |
michael@0 | 50 | result |= TEXTURE_ALLOW_REPEAT; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | return result; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | /* static */ TemporaryRef<ContentClient> |
michael@0 | 58 | ContentClient::CreateContentClient(CompositableForwarder* aForwarder) |
michael@0 | 59 | { |
michael@0 | 60 | LayersBackend backend = aForwarder->GetCompositorBackendType(); |
michael@0 | 61 | if (backend != LayersBackend::LAYERS_OPENGL && |
michael@0 | 62 | backend != LayersBackend::LAYERS_D3D9 && |
michael@0 | 63 | backend != LayersBackend::LAYERS_D3D11 && |
michael@0 | 64 | backend != LayersBackend::LAYERS_BASIC) { |
michael@0 | 65 | return nullptr; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | bool useDoubleBuffering = false; |
michael@0 | 69 | |
michael@0 | 70 | #ifdef XP_WIN |
michael@0 | 71 | if (backend == LayersBackend::LAYERS_D3D11) { |
michael@0 | 72 | useDoubleBuffering = !!gfxWindowsPlatform::GetPlatform()->GetD2DDevice(); |
michael@0 | 73 | } else |
michael@0 | 74 | #endif |
michael@0 | 75 | { |
michael@0 | 76 | useDoubleBuffering = (LayerManagerComposite::SupportsDirectTexturing() && |
michael@0 | 77 | backend != LayersBackend::LAYERS_D3D9) || |
michael@0 | 78 | backend == LayersBackend::LAYERS_BASIC; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | if (useDoubleBuffering || PR_GetEnv("MOZ_FORCE_DOUBLE_BUFFERING")) { |
michael@0 | 82 | return new ContentClientDoubleBuffered(aForwarder); |
michael@0 | 83 | } |
michael@0 | 84 | #ifdef XP_MACOSX |
michael@0 | 85 | if (backend == LayersBackend::LAYERS_OPENGL) { |
michael@0 | 86 | return new ContentClientIncremental(aForwarder); |
michael@0 | 87 | } |
michael@0 | 88 | #endif |
michael@0 | 89 | return new ContentClientSingleBuffered(aForwarder); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | void |
michael@0 | 93 | ContentClient::EndPaint() |
michael@0 | 94 | { |
michael@0 | 95 | // It is very important that this is called after any overridden EndPaint behaviour, |
michael@0 | 96 | // because destroying textures is a three stage process: |
michael@0 | 97 | // 1. We are done with the buffer and move it to ContentClient::mOldTextures, |
michael@0 | 98 | // that happens in DestroyBuffers which is may be called indirectly from |
michael@0 | 99 | // PaintThebes. |
michael@0 | 100 | // 2. The content client calls RemoveTextureClient on the texture clients in |
michael@0 | 101 | // mOldTextures and forgets them. They then become invalid. The compositable |
michael@0 | 102 | // client keeps a record of IDs. This happens in EndPaint. |
michael@0 | 103 | // 3. An IPC message is sent to destroy the corresponding texture host. That |
michael@0 | 104 | // happens from OnTransaction. |
michael@0 | 105 | // It is important that these steps happen in order. |
michael@0 | 106 | OnTransaction(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | // We pass a null pointer for the ContentClient Forwarder argument, which means |
michael@0 | 110 | // this client will not have a ContentHost on the other side. |
michael@0 | 111 | ContentClientBasic::ContentClientBasic() |
michael@0 | 112 | : ContentClient(nullptr) |
michael@0 | 113 | , RotatedContentBuffer(ContainsVisibleBounds) |
michael@0 | 114 | {} |
michael@0 | 115 | |
michael@0 | 116 | void |
michael@0 | 117 | ContentClientBasic::CreateBuffer(ContentType aType, |
michael@0 | 118 | const nsIntRect& aRect, |
michael@0 | 119 | uint32_t aFlags, |
michael@0 | 120 | RefPtr<gfx::DrawTarget>* aBlackDT, |
michael@0 | 121 | RefPtr<gfx::DrawTarget>* aWhiteDT) |
michael@0 | 122 | { |
michael@0 | 123 | MOZ_ASSERT(!(aFlags & BUFFER_COMPONENT_ALPHA)); |
michael@0 | 124 | gfxImageFormat format = |
michael@0 | 125 | gfxPlatform::GetPlatform()->OptimalFormatForContent(aType); |
michael@0 | 126 | |
michael@0 | 127 | *aBlackDT = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( |
michael@0 | 128 | IntSize(aRect.width, aRect.height), |
michael@0 | 129 | ImageFormatToSurfaceFormat(format)); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | void |
michael@0 | 133 | ContentClientRemoteBuffer::DestroyBuffers() |
michael@0 | 134 | { |
michael@0 | 135 | if (!mTextureClient) { |
michael@0 | 136 | return; |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | mOldTextures.AppendElement(mTextureClient); |
michael@0 | 140 | mTextureClient = nullptr; |
michael@0 | 141 | if (mTextureClientOnWhite) { |
michael@0 | 142 | mOldTextures.AppendElement(mTextureClientOnWhite); |
michael@0 | 143 | mTextureClientOnWhite = nullptr; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | DestroyFrontBuffer(); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | void |
michael@0 | 150 | ContentClientRemoteBuffer::BeginPaint() |
michael@0 | 151 | { |
michael@0 | 152 | // XXX: So we might not have a TextureClient yet.. because it will |
michael@0 | 153 | // only be created by CreateBuffer.. which will deliver a locked surface!. |
michael@0 | 154 | if (mTextureClient) { |
michael@0 | 155 | SetBufferProvider(mTextureClient); |
michael@0 | 156 | } |
michael@0 | 157 | if (mTextureClientOnWhite) { |
michael@0 | 158 | SetBufferProviderOnWhite(mTextureClientOnWhite); |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | void |
michael@0 | 163 | ContentClientRemoteBuffer::EndPaint() |
michael@0 | 164 | { |
michael@0 | 165 | // XXX: We might still not have a texture client if PaintThebes |
michael@0 | 166 | // decided we didn't need one yet because the region to draw was empty. |
michael@0 | 167 | SetBufferProvider(nullptr); |
michael@0 | 168 | SetBufferProviderOnWhite(nullptr); |
michael@0 | 169 | for (unsigned i = 0; i< mOldTextures.Length(); ++i) { |
michael@0 | 170 | if (mOldTextures[i]->IsLocked()) { |
michael@0 | 171 | mOldTextures[i]->Unlock(); |
michael@0 | 172 | } |
michael@0 | 173 | } |
michael@0 | 174 | mOldTextures.Clear(); |
michael@0 | 175 | |
michael@0 | 176 | if (mTextureClient && mTextureClient->IsLocked()) { |
michael@0 | 177 | mTextureClient->Unlock(); |
michael@0 | 178 | } |
michael@0 | 179 | if (mTextureClientOnWhite && mTextureClientOnWhite->IsLocked()) { |
michael@0 | 180 | mTextureClientOnWhite->Unlock(); |
michael@0 | 181 | } |
michael@0 | 182 | ContentClientRemote::EndPaint(); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | bool |
michael@0 | 186 | ContentClientRemoteBuffer::CreateAndAllocateTextureClient(RefPtr<TextureClient>& aClient, |
michael@0 | 187 | TextureFlags aFlags) |
michael@0 | 188 | { |
michael@0 | 189 | // gfx::BackendType::NONE means fallback to the content backend |
michael@0 | 190 | aClient = CreateTextureClientForDrawing(mSurfaceFormat, |
michael@0 | 191 | mTextureInfo.mTextureFlags | aFlags, |
michael@0 | 192 | gfx::BackendType::NONE, |
michael@0 | 193 | mSize); |
michael@0 | 194 | if (!aClient) { |
michael@0 | 195 | return false; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | if (!aClient->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) { |
michael@0 | 199 | aClient = CreateTextureClientForDrawing(mSurfaceFormat, |
michael@0 | 200 | mTextureInfo.mTextureFlags | TEXTURE_ALLOC_FALLBACK | aFlags, |
michael@0 | 201 | gfx::BackendType::NONE, |
michael@0 | 202 | mSize); |
michael@0 | 203 | if (!aClient) { |
michael@0 | 204 | return false; |
michael@0 | 205 | } |
michael@0 | 206 | if (!aClient->AllocateForSurface(mSize, ALLOC_CLEAR_BUFFER)) { |
michael@0 | 207 | NS_WARNING("Could not allocate texture client"); |
michael@0 | 208 | aClient = nullptr; |
michael@0 | 209 | return false; |
michael@0 | 210 | } |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | NS_WARN_IF_FALSE(aClient->IsValid(), "Created an invalid texture client"); |
michael@0 | 214 | return true; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | void |
michael@0 | 218 | ContentClientRemoteBuffer::BuildTextureClients(SurfaceFormat aFormat, |
michael@0 | 219 | const nsIntRect& aRect, |
michael@0 | 220 | uint32_t aFlags) |
michael@0 | 221 | { |
michael@0 | 222 | // If we hit this assertion, then it might be due to an empty transaction |
michael@0 | 223 | // followed by a real transaction. Our buffers should be created (but not |
michael@0 | 224 | // painted in the empty transaction) and then painted (but not created) in the |
michael@0 | 225 | // real transaction. That is kind of fragile, and this assert will catch |
michael@0 | 226 | // circumstances where we screw that up, e.g., by unnecessarily recreating our |
michael@0 | 227 | // buffers. |
michael@0 | 228 | NS_ABORT_IF_FALSE(!mIsNewBuffer, |
michael@0 | 229 | "Bad! Did we create a buffer twice without painting?"); |
michael@0 | 230 | |
michael@0 | 231 | mIsNewBuffer = true; |
michael@0 | 232 | |
michael@0 | 233 | DestroyBuffers(); |
michael@0 | 234 | |
michael@0 | 235 | mSurfaceFormat = aFormat; |
michael@0 | 236 | mSize = gfx::IntSize(aRect.width, aRect.height); |
michael@0 | 237 | mTextureInfo.mTextureFlags = TextureFlagsForRotatedContentBufferFlags(aFlags); |
michael@0 | 238 | |
michael@0 | 239 | if (!CreateAndAllocateTextureClient(mTextureClient, TEXTURE_ON_BLACK) || |
michael@0 | 240 | !AddTextureClient(mTextureClient)) { |
michael@0 | 241 | AbortTextureClientCreation(); |
michael@0 | 242 | return; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | if (aFlags & BUFFER_COMPONENT_ALPHA) { |
michael@0 | 246 | if (!CreateAndAllocateTextureClient(mTextureClientOnWhite, TEXTURE_ON_WHITE) || |
michael@0 | 247 | !AddTextureClient(mTextureClientOnWhite)) { |
michael@0 | 248 | AbortTextureClientCreation(); |
michael@0 | 249 | return; |
michael@0 | 250 | } |
michael@0 | 251 | mTextureInfo.mTextureFlags |= TEXTURE_COMPONENT_ALPHA; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | CreateFrontBuffer(aRect); |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | void |
michael@0 | 258 | ContentClientRemoteBuffer::CreateBuffer(ContentType aType, |
michael@0 | 259 | const nsIntRect& aRect, |
michael@0 | 260 | uint32_t aFlags, |
michael@0 | 261 | RefPtr<gfx::DrawTarget>* aBlackDT, |
michael@0 | 262 | RefPtr<gfx::DrawTarget>* aWhiteDT) |
michael@0 | 263 | { |
michael@0 | 264 | BuildTextureClients(gfxPlatform::GetPlatform()->Optimal2DFormatForContent(aType), aRect, aFlags); |
michael@0 | 265 | if (!mTextureClient) { |
michael@0 | 266 | return; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | // We just created the textures and we are about to get their draw targets |
michael@0 | 270 | // so we have to lock them here. |
michael@0 | 271 | DebugOnly<bool> locked = mTextureClient->Lock(OPEN_READ_WRITE); |
michael@0 | 272 | MOZ_ASSERT(locked, "Could not lock the TextureClient"); |
michael@0 | 273 | |
michael@0 | 274 | *aBlackDT = mTextureClient->GetAsDrawTarget(); |
michael@0 | 275 | if (aFlags & BUFFER_COMPONENT_ALPHA) { |
michael@0 | 276 | locked = mTextureClientOnWhite->Lock(OPEN_READ_WRITE); |
michael@0 | 277 | MOZ_ASSERT(locked, "Could not lock the second TextureClient for component alpha"); |
michael@0 | 278 | |
michael@0 | 279 | *aWhiteDT = mTextureClientOnWhite->GetAsDrawTarget(); |
michael@0 | 280 | } |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | nsIntRegion |
michael@0 | 284 | ContentClientRemoteBuffer::GetUpdatedRegion(const nsIntRegion& aRegionToDraw, |
michael@0 | 285 | const nsIntRegion& aVisibleRegion, |
michael@0 | 286 | bool aDidSelfCopy) |
michael@0 | 287 | { |
michael@0 | 288 | nsIntRegion updatedRegion; |
michael@0 | 289 | if (mIsNewBuffer || aDidSelfCopy) { |
michael@0 | 290 | // A buffer reallocation clears both buffers. The front buffer has all the |
michael@0 | 291 | // content by now, but the back buffer is still clear. Here, in effect, we |
michael@0 | 292 | // are saying to copy all of the pixels of the front buffer to the back. |
michael@0 | 293 | // Also when we self-copied in the buffer, the buffer space |
michael@0 | 294 | // changes and some changed buffer content isn't reflected in the |
michael@0 | 295 | // draw or invalidate region (on purpose!). When this happens, we |
michael@0 | 296 | // need to read back the entire buffer too. |
michael@0 | 297 | updatedRegion = aVisibleRegion; |
michael@0 | 298 | mIsNewBuffer = false; |
michael@0 | 299 | } else { |
michael@0 | 300 | updatedRegion = aRegionToDraw; |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | NS_ASSERTION(BufferRect().Contains(aRegionToDraw.GetBounds()), |
michael@0 | 304 | "Update outside of buffer rect!"); |
michael@0 | 305 | NS_ABORT_IF_FALSE(mTextureClient, "should have a back buffer by now"); |
michael@0 | 306 | |
michael@0 | 307 | return updatedRegion; |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | void |
michael@0 | 311 | ContentClientRemoteBuffer::Updated(const nsIntRegion& aRegionToDraw, |
michael@0 | 312 | const nsIntRegion& aVisibleRegion, |
michael@0 | 313 | bool aDidSelfCopy) |
michael@0 | 314 | { |
michael@0 | 315 | nsIntRegion updatedRegion = GetUpdatedRegion(aRegionToDraw, |
michael@0 | 316 | aVisibleRegion, |
michael@0 | 317 | aDidSelfCopy); |
michael@0 | 318 | |
michael@0 | 319 | MOZ_ASSERT(mTextureClient); |
michael@0 | 320 | if (mTextureClientOnWhite) { |
michael@0 | 321 | mForwarder->UseComponentAlphaTextures(this, mTextureClient, |
michael@0 | 322 | mTextureClientOnWhite); |
michael@0 | 323 | } else { |
michael@0 | 324 | mForwarder->UseTexture(this, mTextureClient); |
michael@0 | 325 | } |
michael@0 | 326 | mForwarder->UpdateTextureRegion(this, |
michael@0 | 327 | ThebesBufferData(BufferRect(), |
michael@0 | 328 | BufferRotation()), |
michael@0 | 329 | updatedRegion); |
michael@0 | 330 | } |
michael@0 | 331 | |
michael@0 | 332 | void |
michael@0 | 333 | ContentClientRemoteBuffer::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) |
michael@0 | 334 | { |
michael@0 | 335 | MOZ_ASSERT(mTextureClient); |
michael@0 | 336 | mFrontAndBackBufferDiffer = true; |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | void |
michael@0 | 340 | ContentClientDoubleBuffered::CreateFrontBuffer(const nsIntRect& aBufferRect) |
michael@0 | 341 | { |
michael@0 | 342 | if (!CreateAndAllocateTextureClient(mFrontClient, TEXTURE_ON_BLACK) || |
michael@0 | 343 | !AddTextureClient(mFrontClient)) { |
michael@0 | 344 | AbortTextureClientCreation(); |
michael@0 | 345 | return; |
michael@0 | 346 | } |
michael@0 | 347 | if (mTextureInfo.mTextureFlags & TEXTURE_COMPONENT_ALPHA) { |
michael@0 | 348 | if (!CreateAndAllocateTextureClient(mFrontClientOnWhite, TEXTURE_ON_WHITE) || |
michael@0 | 349 | !AddTextureClient(mFrontClientOnWhite)) { |
michael@0 | 350 | AbortTextureClientCreation(); |
michael@0 | 351 | return; |
michael@0 | 352 | } |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | mFrontBufferRect = aBufferRect; |
michael@0 | 356 | mFrontBufferRotation = nsIntPoint(); |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | void |
michael@0 | 360 | ContentClientDoubleBuffered::DestroyFrontBuffer() |
michael@0 | 361 | { |
michael@0 | 362 | MOZ_ASSERT(mFrontClient); |
michael@0 | 363 | |
michael@0 | 364 | mOldTextures.AppendElement(mFrontClient); |
michael@0 | 365 | mFrontClient = nullptr; |
michael@0 | 366 | if (mFrontClientOnWhite) { |
michael@0 | 367 | mOldTextures.AppendElement(mFrontClientOnWhite); |
michael@0 | 368 | mFrontClientOnWhite = nullptr; |
michael@0 | 369 | } |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | void |
michael@0 | 373 | ContentClientDoubleBuffered::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) |
michael@0 | 374 | { |
michael@0 | 375 | mFrontUpdatedRegion = aFrontUpdatedRegion; |
michael@0 | 376 | |
michael@0 | 377 | RefPtr<TextureClient> oldBack = mTextureClient; |
michael@0 | 378 | mTextureClient = mFrontClient; |
michael@0 | 379 | mFrontClient = oldBack; |
michael@0 | 380 | |
michael@0 | 381 | oldBack = mTextureClientOnWhite; |
michael@0 | 382 | mTextureClientOnWhite = mFrontClientOnWhite; |
michael@0 | 383 | mFrontClientOnWhite = oldBack; |
michael@0 | 384 | |
michael@0 | 385 | nsIntRect oldBufferRect = mBufferRect; |
michael@0 | 386 | mBufferRect = mFrontBufferRect; |
michael@0 | 387 | mFrontBufferRect = oldBufferRect; |
michael@0 | 388 | |
michael@0 | 389 | nsIntPoint oldBufferRotation = mBufferRotation; |
michael@0 | 390 | mBufferRotation = mFrontBufferRotation; |
michael@0 | 391 | mFrontBufferRotation = oldBufferRotation; |
michael@0 | 392 | |
michael@0 | 393 | MOZ_ASSERT(mFrontClient); |
michael@0 | 394 | |
michael@0 | 395 | ContentClientRemoteBuffer::SwapBuffers(aFrontUpdatedRegion); |
michael@0 | 396 | } |
michael@0 | 397 | |
michael@0 | 398 | void |
michael@0 | 399 | ContentClientDoubleBuffered::BeginPaint() |
michael@0 | 400 | { |
michael@0 | 401 | ContentClientRemoteBuffer::BeginPaint(); |
michael@0 | 402 | |
michael@0 | 403 | mIsNewBuffer = false; |
michael@0 | 404 | |
michael@0 | 405 | if (!mFrontAndBackBufferDiffer) { |
michael@0 | 406 | return; |
michael@0 | 407 | } |
michael@0 | 408 | |
michael@0 | 409 | if (mDidSelfCopy) { |
michael@0 | 410 | // We can't easily draw our front buffer into us, since we're going to be |
michael@0 | 411 | // copying stuff around anyway it's easiest if we just move our situation |
michael@0 | 412 | // to non-rotated while we're at it. If this situation occurs we'll have |
michael@0 | 413 | // hit a self-copy path in PaintThebes before as well anyway. |
michael@0 | 414 | mBufferRect.MoveTo(mFrontBufferRect.TopLeft()); |
michael@0 | 415 | mBufferRotation = nsIntPoint(); |
michael@0 | 416 | return; |
michael@0 | 417 | } |
michael@0 | 418 | mBufferRect = mFrontBufferRect; |
michael@0 | 419 | mBufferRotation = mFrontBufferRotation; |
michael@0 | 420 | } |
michael@0 | 421 | |
michael@0 | 422 | // Sync front/back buffers content |
michael@0 | 423 | // After executing, the new back buffer has the same (interesting) pixels as |
michael@0 | 424 | // the new front buffer, and mValidRegion et al. are correct wrt the new |
michael@0 | 425 | // back buffer (i.e. as they were for the old back buffer) |
michael@0 | 426 | void |
michael@0 | 427 | ContentClientDoubleBuffered::FinalizeFrame(const nsIntRegion& aRegionToDraw) |
michael@0 | 428 | { |
michael@0 | 429 | if (mTextureClient) { |
michael@0 | 430 | DebugOnly<bool> locked = mTextureClient->Lock(OPEN_READ_WRITE); |
michael@0 | 431 | MOZ_ASSERT(locked); |
michael@0 | 432 | } |
michael@0 | 433 | if (mTextureClientOnWhite) { |
michael@0 | 434 | DebugOnly<bool> locked = mTextureClientOnWhite->Lock(OPEN_READ_WRITE); |
michael@0 | 435 | MOZ_ASSERT(locked); |
michael@0 | 436 | } |
michael@0 | 437 | |
michael@0 | 438 | if (!mFrontAndBackBufferDiffer) { |
michael@0 | 439 | MOZ_ASSERT(!mDidSelfCopy, "If we have to copy the world, then our buffers are different, right?"); |
michael@0 | 440 | return; |
michael@0 | 441 | } |
michael@0 | 442 | MOZ_ASSERT(mFrontClient); |
michael@0 | 443 | |
michael@0 | 444 | MOZ_LAYERS_LOG(("BasicShadowableThebes(%p): reading back <x=%d,y=%d,w=%d,h=%d>", |
michael@0 | 445 | this, |
michael@0 | 446 | mFrontUpdatedRegion.GetBounds().x, |
michael@0 | 447 | mFrontUpdatedRegion.GetBounds().y, |
michael@0 | 448 | mFrontUpdatedRegion.GetBounds().width, |
michael@0 | 449 | mFrontUpdatedRegion.GetBounds().height)); |
michael@0 | 450 | |
michael@0 | 451 | mFrontAndBackBufferDiffer = false; |
michael@0 | 452 | |
michael@0 | 453 | nsIntRegion updateRegion = mFrontUpdatedRegion; |
michael@0 | 454 | if (mDidSelfCopy) { |
michael@0 | 455 | mDidSelfCopy = false; |
michael@0 | 456 | updateRegion = mBufferRect; |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | // No point in sync'ing what we are going to draw over anyway. And if there is |
michael@0 | 460 | // nothing to sync at all, there is nothing to do and we can go home early. |
michael@0 | 461 | updateRegion.Sub(updateRegion, aRegionToDraw); |
michael@0 | 462 | if (updateRegion.IsEmpty()) { |
michael@0 | 463 | return; |
michael@0 | 464 | } |
michael@0 | 465 | |
michael@0 | 466 | // We need to ensure that we lock these two buffers in the same |
michael@0 | 467 | // order as the compositor to prevent deadlocks. |
michael@0 | 468 | if (!mFrontClient->Lock(OPEN_READ_ONLY)) { |
michael@0 | 469 | return; |
michael@0 | 470 | } |
michael@0 | 471 | if (mFrontClientOnWhite && |
michael@0 | 472 | !mFrontClientOnWhite->Lock(OPEN_READ_ONLY)) { |
michael@0 | 473 | mFrontClient->Unlock(); |
michael@0 | 474 | return; |
michael@0 | 475 | } |
michael@0 | 476 | { |
michael@0 | 477 | // Restrict the DrawTargets and frontBuffer to a scope to make |
michael@0 | 478 | // sure there is no more external references to the DrawTargets |
michael@0 | 479 | // when we Unlock the TextureClients. |
michael@0 | 480 | RefPtr<DrawTarget> dt = mFrontClient->GetAsDrawTarget(); |
michael@0 | 481 | RefPtr<DrawTarget> dtOnWhite = mFrontClientOnWhite |
michael@0 | 482 | ? mFrontClientOnWhite->GetAsDrawTarget() |
michael@0 | 483 | : nullptr; |
michael@0 | 484 | RotatedBuffer frontBuffer(dt, |
michael@0 | 485 | dtOnWhite, |
michael@0 | 486 | mFrontBufferRect, |
michael@0 | 487 | mFrontBufferRotation); |
michael@0 | 488 | UpdateDestinationFrom(frontBuffer, updateRegion); |
michael@0 | 489 | } |
michael@0 | 490 | |
michael@0 | 491 | mFrontClient->Unlock(); |
michael@0 | 492 | if (mFrontClientOnWhite) { |
michael@0 | 493 | mFrontClientOnWhite->Unlock(); |
michael@0 | 494 | } |
michael@0 | 495 | } |
michael@0 | 496 | |
michael@0 | 497 | void |
michael@0 | 498 | ContentClientDoubleBuffered::UpdateDestinationFrom(const RotatedBuffer& aSource, |
michael@0 | 499 | const nsIntRegion& aUpdateRegion) |
michael@0 | 500 | { |
michael@0 | 501 | DrawIterator iter; |
michael@0 | 502 | while (DrawTarget* destDT = |
michael@0 | 503 | BorrowDrawTargetForQuadrantUpdate(aUpdateRegion.GetBounds(), BUFFER_BLACK, &iter)) { |
michael@0 | 504 | bool isClippingCheap = IsClippingCheap(destDT, iter.mDrawRegion); |
michael@0 | 505 | if (isClippingCheap) { |
michael@0 | 506 | gfxUtils::ClipToRegion(destDT, iter.mDrawRegion); |
michael@0 | 507 | } |
michael@0 | 508 | |
michael@0 | 509 | aSource.DrawBufferWithRotation(destDT, BUFFER_BLACK, 1.0, CompositionOp::OP_SOURCE); |
michael@0 | 510 | if (isClippingCheap) { |
michael@0 | 511 | destDT->PopClip(); |
michael@0 | 512 | } |
michael@0 | 513 | // Flush the destination before the sources become inaccessible (Unlock). |
michael@0 | 514 | destDT->Flush(); |
michael@0 | 515 | ReturnDrawTargetToBuffer(destDT); |
michael@0 | 516 | } |
michael@0 | 517 | |
michael@0 | 518 | if (aSource.HaveBufferOnWhite()) { |
michael@0 | 519 | MOZ_ASSERT(HaveBufferOnWhite()); |
michael@0 | 520 | DrawIterator whiteIter; |
michael@0 | 521 | while (DrawTarget* destDT = |
michael@0 | 522 | BorrowDrawTargetForQuadrantUpdate(aUpdateRegion.GetBounds(), BUFFER_WHITE, &whiteIter)) { |
michael@0 | 523 | bool isClippingCheap = IsClippingCheap(destDT, whiteIter.mDrawRegion); |
michael@0 | 524 | if (isClippingCheap) { |
michael@0 | 525 | gfxUtils::ClipToRegion(destDT, whiteIter.mDrawRegion); |
michael@0 | 526 | } |
michael@0 | 527 | |
michael@0 | 528 | aSource.DrawBufferWithRotation(destDT, BUFFER_WHITE, 1.0, CompositionOp::OP_SOURCE); |
michael@0 | 529 | if (isClippingCheap) { |
michael@0 | 530 | destDT->PopClip(); |
michael@0 | 531 | } |
michael@0 | 532 | // Flush the destination before the sources become inaccessible (Unlock). |
michael@0 | 533 | destDT->Flush(); |
michael@0 | 534 | ReturnDrawTargetToBuffer(destDT); |
michael@0 | 535 | } |
michael@0 | 536 | } |
michael@0 | 537 | } |
michael@0 | 538 | |
michael@0 | 539 | void |
michael@0 | 540 | ContentClientSingleBuffered::FinalizeFrame(const nsIntRegion& aRegionToDraw) |
michael@0 | 541 | { |
michael@0 | 542 | if (mTextureClient) { |
michael@0 | 543 | DebugOnly<bool> locked = mTextureClient->Lock(OPEN_READ_WRITE); |
michael@0 | 544 | MOZ_ASSERT(locked); |
michael@0 | 545 | } |
michael@0 | 546 | if (mTextureClientOnWhite) { |
michael@0 | 547 | DebugOnly<bool> locked = mTextureClientOnWhite->Lock(OPEN_READ_WRITE); |
michael@0 | 548 | MOZ_ASSERT(locked); |
michael@0 | 549 | } |
michael@0 | 550 | } |
michael@0 | 551 | |
michael@0 | 552 | static void |
michael@0 | 553 | WrapRotationAxis(int32_t* aRotationPoint, int32_t aSize) |
michael@0 | 554 | { |
michael@0 | 555 | if (*aRotationPoint < 0) { |
michael@0 | 556 | *aRotationPoint += aSize; |
michael@0 | 557 | } else if (*aRotationPoint >= aSize) { |
michael@0 | 558 | *aRotationPoint -= aSize; |
michael@0 | 559 | } |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | static void |
michael@0 | 563 | FillSurface(DrawTarget* aDT, const nsIntRegion& aRegion, |
michael@0 | 564 | const nsIntPoint& aOffset, const gfxRGBA& aColor) |
michael@0 | 565 | { |
michael@0 | 566 | nsIntRegionRectIterator iter(aRegion); |
michael@0 | 567 | const nsIntRect* r; |
michael@0 | 568 | while ((r = iter.Next()) != nullptr) { |
michael@0 | 569 | aDT->FillRect(Rect(r->x - aOffset.x, r->y - aOffset.y, |
michael@0 | 570 | r->width, r->height), |
michael@0 | 571 | ColorPattern(ToColor(aColor))); |
michael@0 | 572 | } |
michael@0 | 573 | } |
michael@0 | 574 | |
michael@0 | 575 | RotatedContentBuffer::PaintState |
michael@0 | 576 | ContentClientIncremental::BeginPaintBuffer(ThebesLayer* aLayer, |
michael@0 | 577 | uint32_t aFlags) |
michael@0 | 578 | { |
michael@0 | 579 | mTextureInfo.mDeprecatedTextureHostFlags = 0; |
michael@0 | 580 | PaintState result; |
michael@0 | 581 | // We need to disable rotation if we're going to be resampled when |
michael@0 | 582 | // drawing, because we might sample across the rotation boundary. |
michael@0 | 583 | bool canHaveRotation = !(aFlags & RotatedContentBuffer::PAINT_WILL_RESAMPLE); |
michael@0 | 584 | |
michael@0 | 585 | nsIntRegion validRegion = aLayer->GetValidRegion(); |
michael@0 | 586 | |
michael@0 | 587 | bool canUseOpaqueSurface = aLayer->CanUseOpaqueSurface(); |
michael@0 | 588 | ContentType contentType = |
michael@0 | 589 | canUseOpaqueSurface ? gfxContentType::COLOR : |
michael@0 | 590 | gfxContentType::COLOR_ALPHA; |
michael@0 | 591 | |
michael@0 | 592 | SurfaceMode mode; |
michael@0 | 593 | nsIntRegion neededRegion; |
michael@0 | 594 | bool canReuseBuffer; |
michael@0 | 595 | nsIntRect destBufferRect; |
michael@0 | 596 | |
michael@0 | 597 | while (true) { |
michael@0 | 598 | mode = aLayer->GetSurfaceMode(); |
michael@0 | 599 | neededRegion = aLayer->GetVisibleRegion(); |
michael@0 | 600 | // If we're going to resample, we need a buffer that's in clamp mode. |
michael@0 | 601 | canReuseBuffer = neededRegion.GetBounds().Size() <= mBufferRect.Size() && |
michael@0 | 602 | mHasBuffer && |
michael@0 | 603 | (!(aFlags & RotatedContentBuffer::PAINT_WILL_RESAMPLE) || |
michael@0 | 604 | !(mTextureInfo.mTextureFlags & TEXTURE_ALLOW_REPEAT)); |
michael@0 | 605 | |
michael@0 | 606 | if (canReuseBuffer) { |
michael@0 | 607 | if (mBufferRect.Contains(neededRegion.GetBounds())) { |
michael@0 | 608 | // We don't need to adjust mBufferRect. |
michael@0 | 609 | destBufferRect = mBufferRect; |
michael@0 | 610 | } else { |
michael@0 | 611 | // The buffer's big enough but doesn't contain everything that's |
michael@0 | 612 | // going to be visible. We'll move it. |
michael@0 | 613 | destBufferRect = nsIntRect(neededRegion.GetBounds().TopLeft(), mBufferRect.Size()); |
michael@0 | 614 | } |
michael@0 | 615 | } else { |
michael@0 | 616 | destBufferRect = neededRegion.GetBounds(); |
michael@0 | 617 | } |
michael@0 | 618 | |
michael@0 | 619 | if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { |
michael@0 | 620 | if (!gfxPrefs::ComponentAlphaEnabled() || |
michael@0 | 621 | !aLayer->GetParent() || |
michael@0 | 622 | !aLayer->GetParent()->SupportsComponentAlphaChildren()) { |
michael@0 | 623 | mode = SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA; |
michael@0 | 624 | } else { |
michael@0 | 625 | contentType = gfxContentType::COLOR; |
michael@0 | 626 | } |
michael@0 | 627 | } |
michael@0 | 628 | |
michael@0 | 629 | if ((aFlags & RotatedContentBuffer::PAINT_WILL_RESAMPLE) && |
michael@0 | 630 | (!neededRegion.GetBounds().IsEqualInterior(destBufferRect) || |
michael@0 | 631 | neededRegion.GetNumRects() > 1)) { |
michael@0 | 632 | // The area we add to neededRegion might not be painted opaquely |
michael@0 | 633 | if (mode == SurfaceMode::SURFACE_OPAQUE) { |
michael@0 | 634 | contentType = gfxContentType::COLOR_ALPHA; |
michael@0 | 635 | mode = SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA; |
michael@0 | 636 | } |
michael@0 | 637 | // For component alpha layers, we leave contentType as gfxContentType::COLOR. |
michael@0 | 638 | |
michael@0 | 639 | // We need to validate the entire buffer, to make sure that only valid |
michael@0 | 640 | // pixels are sampled |
michael@0 | 641 | neededRegion = destBufferRect; |
michael@0 | 642 | } |
michael@0 | 643 | |
michael@0 | 644 | if (mHasBuffer && |
michael@0 | 645 | (mContentType != contentType || |
michael@0 | 646 | (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) != mHasBufferOnWhite)) { |
michael@0 | 647 | // We're effectively clearing the valid region, so we need to draw |
michael@0 | 648 | // the entire needed region now. |
michael@0 | 649 | result.mRegionToInvalidate = aLayer->GetValidRegion(); |
michael@0 | 650 | validRegion.SetEmpty(); |
michael@0 | 651 | mHasBuffer = false; |
michael@0 | 652 | mHasBufferOnWhite = false; |
michael@0 | 653 | mBufferRect.SetRect(0, 0, 0, 0); |
michael@0 | 654 | mBufferRotation.MoveTo(0, 0); |
michael@0 | 655 | // Restart decision process with the cleared buffer. We can only go |
michael@0 | 656 | // around the loop one more iteration, since mTexImage is null now. |
michael@0 | 657 | continue; |
michael@0 | 658 | } |
michael@0 | 659 | |
michael@0 | 660 | break; |
michael@0 | 661 | } |
michael@0 | 662 | |
michael@0 | 663 | result.mRegionToDraw.Sub(neededRegion, validRegion); |
michael@0 | 664 | if (result.mRegionToDraw.IsEmpty()) |
michael@0 | 665 | return result; |
michael@0 | 666 | |
michael@0 | 667 | if (destBufferRect.width > mForwarder->GetMaxTextureSize() || |
michael@0 | 668 | destBufferRect.height > mForwarder->GetMaxTextureSize()) { |
michael@0 | 669 | return result; |
michael@0 | 670 | } |
michael@0 | 671 | |
michael@0 | 672 | // BlitTextureImage depends on the FBO texture target being |
michael@0 | 673 | // TEXTURE_2D. This isn't the case on some older X1600-era Radeons. |
michael@0 | 674 | if (!mForwarder->SupportsTextureBlitting() || |
michael@0 | 675 | !mForwarder->SupportsPartialUploads()) { |
michael@0 | 676 | result.mRegionToDraw = neededRegion; |
michael@0 | 677 | validRegion.SetEmpty(); |
michael@0 | 678 | mHasBuffer = false; |
michael@0 | 679 | mHasBufferOnWhite = false; |
michael@0 | 680 | mBufferRect.SetRect(0, 0, 0, 0); |
michael@0 | 681 | mBufferRotation.MoveTo(0, 0); |
michael@0 | 682 | canReuseBuffer = false; |
michael@0 | 683 | } |
michael@0 | 684 | |
michael@0 | 685 | nsIntRect drawBounds = result.mRegionToDraw.GetBounds(); |
michael@0 | 686 | bool createdBuffer = false; |
michael@0 | 687 | |
michael@0 | 688 | uint32_t bufferFlags = canHaveRotation ? TEXTURE_ALLOW_REPEAT : 0; |
michael@0 | 689 | if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { |
michael@0 | 690 | bufferFlags |= TEXTURE_COMPONENT_ALPHA; |
michael@0 | 691 | } |
michael@0 | 692 | if (canReuseBuffer) { |
michael@0 | 693 | nsIntRect keepArea; |
michael@0 | 694 | if (keepArea.IntersectRect(destBufferRect, mBufferRect)) { |
michael@0 | 695 | // Set mBufferRotation so that the pixels currently in mBuffer |
michael@0 | 696 | // will still be rendered in the right place when mBufferRect |
michael@0 | 697 | // changes to destBufferRect. |
michael@0 | 698 | nsIntPoint newRotation = mBufferRotation + |
michael@0 | 699 | (destBufferRect.TopLeft() - mBufferRect.TopLeft()); |
michael@0 | 700 | WrapRotationAxis(&newRotation.x, mBufferRect.width); |
michael@0 | 701 | WrapRotationAxis(&newRotation.y, mBufferRect.height); |
michael@0 | 702 | NS_ASSERTION(nsIntRect(nsIntPoint(0,0), mBufferRect.Size()).Contains(newRotation), |
michael@0 | 703 | "newRotation out of bounds"); |
michael@0 | 704 | int32_t xBoundary = destBufferRect.XMost() - newRotation.x; |
michael@0 | 705 | int32_t yBoundary = destBufferRect.YMost() - newRotation.y; |
michael@0 | 706 | if ((drawBounds.x < xBoundary && xBoundary < drawBounds.XMost()) || |
michael@0 | 707 | (drawBounds.y < yBoundary && yBoundary < drawBounds.YMost()) || |
michael@0 | 708 | (newRotation != nsIntPoint(0,0) && !canHaveRotation)) { |
michael@0 | 709 | // The stuff we need to redraw will wrap around an edge of the |
michael@0 | 710 | // buffer, so we will need to do a self-copy |
michael@0 | 711 | // If mBufferRotation == nsIntPoint(0,0) we could do a real |
michael@0 | 712 | // self-copy but we're not going to do that in GL yet. |
michael@0 | 713 | // We can't do a real self-copy because the buffer is rotated. |
michael@0 | 714 | // So allocate a new buffer for the destination. |
michael@0 | 715 | destBufferRect = neededRegion.GetBounds(); |
michael@0 | 716 | createdBuffer = true; |
michael@0 | 717 | } else { |
michael@0 | 718 | mBufferRect = destBufferRect; |
michael@0 | 719 | mBufferRotation = newRotation; |
michael@0 | 720 | } |
michael@0 | 721 | } else { |
michael@0 | 722 | // No pixels are going to be kept. The whole visible region |
michael@0 | 723 | // will be redrawn, so we don't need to copy anything, so we don't |
michael@0 | 724 | // set destBuffer. |
michael@0 | 725 | mBufferRect = destBufferRect; |
michael@0 | 726 | mBufferRotation = nsIntPoint(0,0); |
michael@0 | 727 | } |
michael@0 | 728 | } else { |
michael@0 | 729 | // The buffer's not big enough, so allocate a new one |
michael@0 | 730 | createdBuffer = true; |
michael@0 | 731 | } |
michael@0 | 732 | NS_ASSERTION(!(aFlags & RotatedContentBuffer::PAINT_WILL_RESAMPLE) || |
michael@0 | 733 | destBufferRect == neededRegion.GetBounds(), |
michael@0 | 734 | "If we're resampling, we need to validate the entire buffer"); |
michael@0 | 735 | |
michael@0 | 736 | if (!createdBuffer && !mHasBuffer) { |
michael@0 | 737 | return result; |
michael@0 | 738 | } |
michael@0 | 739 | |
michael@0 | 740 | if (createdBuffer) { |
michael@0 | 741 | if (mHasBuffer && |
michael@0 | 742 | (mode != SurfaceMode::SURFACE_COMPONENT_ALPHA || mHasBufferOnWhite)) { |
michael@0 | 743 | mTextureInfo.mDeprecatedTextureHostFlags = TEXTURE_HOST_COPY_PREVIOUS; |
michael@0 | 744 | } |
michael@0 | 745 | |
michael@0 | 746 | mHasBuffer = true; |
michael@0 | 747 | if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { |
michael@0 | 748 | mHasBufferOnWhite = true; |
michael@0 | 749 | } |
michael@0 | 750 | mBufferRect = destBufferRect; |
michael@0 | 751 | mBufferRotation = nsIntPoint(0,0); |
michael@0 | 752 | NotifyBufferCreated(contentType, bufferFlags); |
michael@0 | 753 | } |
michael@0 | 754 | |
michael@0 | 755 | NS_ASSERTION(canHaveRotation || mBufferRotation == nsIntPoint(0,0), |
michael@0 | 756 | "Rotation disabled, but we have nonzero rotation?"); |
michael@0 | 757 | |
michael@0 | 758 | nsIntRegion invalidate; |
michael@0 | 759 | invalidate.Sub(aLayer->GetValidRegion(), destBufferRect); |
michael@0 | 760 | result.mRegionToInvalidate.Or(result.mRegionToInvalidate, invalidate); |
michael@0 | 761 | |
michael@0 | 762 | // If we do partial updates, we have to clip drawing to the regionToDraw. |
michael@0 | 763 | // If we don't clip, background images will be fillrect'd to the region correctly, |
michael@0 | 764 | // while text or lines will paint outside of the regionToDraw. This becomes apparent |
michael@0 | 765 | // with concave regions. Right now the scrollbars invalidate a narrow strip of the bar |
michael@0 | 766 | // although they never cover it. This leads to two draw rects, the narow strip and the actually |
michael@0 | 767 | // newly exposed area. It would be wise to fix this glitch in any way to have simpler |
michael@0 | 768 | // clip and draw regions. |
michael@0 | 769 | result.mClip = DrawRegionClip::DRAW; |
michael@0 | 770 | result.mMode = mode; |
michael@0 | 771 | |
michael@0 | 772 | return result; |
michael@0 | 773 | } |
michael@0 | 774 | |
michael@0 | 775 | DrawTarget* |
michael@0 | 776 | ContentClientIncremental::BorrowDrawTargetForPainting(const PaintState& aPaintState, |
michael@0 | 777 | RotatedContentBuffer::DrawIterator* aIter) |
michael@0 | 778 | { |
michael@0 | 779 | if (aPaintState.mMode == SurfaceMode::SURFACE_NONE) { |
michael@0 | 780 | return nullptr; |
michael@0 | 781 | } |
michael@0 | 782 | |
michael@0 | 783 | if (aIter) { |
michael@0 | 784 | if (aIter->mCount++ > 0) { |
michael@0 | 785 | return nullptr; |
michael@0 | 786 | } |
michael@0 | 787 | aIter->mDrawRegion = aPaintState.mRegionToDraw; |
michael@0 | 788 | } |
michael@0 | 789 | |
michael@0 | 790 | DrawTarget* result = nullptr; |
michael@0 | 791 | |
michael@0 | 792 | nsIntRect drawBounds = aPaintState.mRegionToDraw.GetBounds(); |
michael@0 | 793 | MOZ_ASSERT(!mLoanedDrawTarget); |
michael@0 | 794 | |
michael@0 | 795 | // BeginUpdate is allowed to modify the given region, |
michael@0 | 796 | // if it wants more to be repainted than we request. |
michael@0 | 797 | if (aPaintState.mMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { |
michael@0 | 798 | nsIntRegion drawRegionCopy = aPaintState.mRegionToDraw; |
michael@0 | 799 | RefPtr<DrawTarget> onBlack = GetUpdateSurface(BUFFER_BLACK, drawRegionCopy); |
michael@0 | 800 | RefPtr<DrawTarget> onWhite = GetUpdateSurface(BUFFER_WHITE, aPaintState.mRegionToDraw); |
michael@0 | 801 | if (onBlack && onWhite) { |
michael@0 | 802 | NS_ASSERTION(aPaintState.mRegionToDraw == drawRegionCopy, |
michael@0 | 803 | "BeginUpdate should always modify the draw region in the same way!"); |
michael@0 | 804 | FillSurface(onBlack, aPaintState.mRegionToDraw, nsIntPoint(drawBounds.x, drawBounds.y), gfxRGBA(0.0, 0.0, 0.0, 1.0)); |
michael@0 | 805 | FillSurface(onWhite, aPaintState.mRegionToDraw, nsIntPoint(drawBounds.x, drawBounds.y), gfxRGBA(1.0, 1.0, 1.0, 1.0)); |
michael@0 | 806 | mLoanedDrawTarget = Factory::CreateDualDrawTarget(onBlack, onWhite); |
michael@0 | 807 | } else { |
michael@0 | 808 | mLoanedDrawTarget = nullptr; |
michael@0 | 809 | } |
michael@0 | 810 | } else { |
michael@0 | 811 | mLoanedDrawTarget = GetUpdateSurface(BUFFER_BLACK, aPaintState.mRegionToDraw); |
michael@0 | 812 | } |
michael@0 | 813 | if (!mLoanedDrawTarget) { |
michael@0 | 814 | NS_WARNING("unable to get context for update"); |
michael@0 | 815 | return nullptr; |
michael@0 | 816 | } |
michael@0 | 817 | |
michael@0 | 818 | result = mLoanedDrawTarget; |
michael@0 | 819 | mLoanedTransform = mLoanedDrawTarget->GetTransform(); |
michael@0 | 820 | mLoanedTransform.Translate(-drawBounds.x, -drawBounds.y); |
michael@0 | 821 | result->SetTransform(mLoanedTransform); |
michael@0 | 822 | mLoanedTransform.Translate(drawBounds.x, drawBounds.y); |
michael@0 | 823 | |
michael@0 | 824 | if (mContentType == gfxContentType::COLOR_ALPHA) { |
michael@0 | 825 | gfxUtils::ClipToRegion(result, aPaintState.mRegionToDraw); |
michael@0 | 826 | nsIntRect bounds = aPaintState.mRegionToDraw.GetBounds(); |
michael@0 | 827 | result->ClearRect(Rect(bounds.x, bounds.y, bounds.width, bounds.height)); |
michael@0 | 828 | } |
michael@0 | 829 | |
michael@0 | 830 | return result; |
michael@0 | 831 | } |
michael@0 | 832 | |
michael@0 | 833 | void |
michael@0 | 834 | ContentClientIncremental::Updated(const nsIntRegion& aRegionToDraw, |
michael@0 | 835 | const nsIntRegion& aVisibleRegion, |
michael@0 | 836 | bool aDidSelfCopy) |
michael@0 | 837 | { |
michael@0 | 838 | if (IsSurfaceDescriptorValid(mUpdateDescriptor)) { |
michael@0 | 839 | mForwarder->UpdateTextureIncremental(this, |
michael@0 | 840 | TextureFront, |
michael@0 | 841 | mUpdateDescriptor, |
michael@0 | 842 | aRegionToDraw, |
michael@0 | 843 | mBufferRect, |
michael@0 | 844 | mBufferRotation); |
michael@0 | 845 | mUpdateDescriptor = SurfaceDescriptor(); |
michael@0 | 846 | } |
michael@0 | 847 | if (IsSurfaceDescriptorValid(mUpdateDescriptorOnWhite)) { |
michael@0 | 848 | mForwarder->UpdateTextureIncremental(this, |
michael@0 | 849 | TextureOnWhiteFront, |
michael@0 | 850 | mUpdateDescriptorOnWhite, |
michael@0 | 851 | aRegionToDraw, |
michael@0 | 852 | mBufferRect, |
michael@0 | 853 | mBufferRotation); |
michael@0 | 854 | mUpdateDescriptorOnWhite = SurfaceDescriptor(); |
michael@0 | 855 | } |
michael@0 | 856 | |
michael@0 | 857 | } |
michael@0 | 858 | |
michael@0 | 859 | TemporaryRef<DrawTarget> |
michael@0 | 860 | ContentClientIncremental::GetUpdateSurface(BufferType aType, |
michael@0 | 861 | const nsIntRegion& aUpdateRegion) |
michael@0 | 862 | { |
michael@0 | 863 | nsIntRect rgnSize = aUpdateRegion.GetBounds(); |
michael@0 | 864 | if (!mBufferRect.Contains(rgnSize)) { |
michael@0 | 865 | NS_ERROR("update outside of image"); |
michael@0 | 866 | return nullptr; |
michael@0 | 867 | } |
michael@0 | 868 | SurfaceDescriptor desc; |
michael@0 | 869 | if (!mForwarder->AllocSurfaceDescriptor(rgnSize.Size().ToIntSize(), |
michael@0 | 870 | mContentType, |
michael@0 | 871 | &desc)) { |
michael@0 | 872 | NS_WARNING("creating SurfaceDescriptor failed!"); |
michael@0 | 873 | Clear(); |
michael@0 | 874 | return nullptr; |
michael@0 | 875 | } |
michael@0 | 876 | |
michael@0 | 877 | if (aType == BUFFER_BLACK) { |
michael@0 | 878 | MOZ_ASSERT(!IsSurfaceDescriptorValid(mUpdateDescriptor)); |
michael@0 | 879 | mUpdateDescriptor = desc; |
michael@0 | 880 | } else { |
michael@0 | 881 | MOZ_ASSERT(!IsSurfaceDescriptorValid(mUpdateDescriptorOnWhite)); |
michael@0 | 882 | MOZ_ASSERT(aType == BUFFER_WHITE); |
michael@0 | 883 | mUpdateDescriptorOnWhite = desc; |
michael@0 | 884 | } |
michael@0 | 885 | |
michael@0 | 886 | return GetDrawTargetForDescriptor(desc, gfx::BackendType::COREGRAPHICS); |
michael@0 | 887 | } |
michael@0 | 888 | |
michael@0 | 889 | } |
michael@0 | 890 | } |