Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | #ifndef MOZILLA_GFX_CONTENTCLIENT_H |
michael@0 | 7 | #define MOZILLA_GFX_CONTENTCLIENT_H |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> // for uint32_t |
michael@0 | 10 | #include "RotatedBuffer.h" // for RotatedContentBuffer, etc |
michael@0 | 11 | #include "gfxTypes.h" |
michael@0 | 12 | #include "gfxPlatform.h" // for gfxPlatform |
michael@0 | 13 | #include "mozilla/Assertions.h" // for MOZ_CRASH |
michael@0 | 14 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 15 | #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef |
michael@0 | 16 | #include "mozilla/gfx/Point.h" // for IntSize |
michael@0 | 17 | #include "mozilla/layers/CompositableClient.h" // for CompositableClient |
michael@0 | 18 | #include "mozilla/layers/CompositableForwarder.h" |
michael@0 | 19 | #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc |
michael@0 | 20 | #include "mozilla/layers/ISurfaceAllocator.h" |
michael@0 | 21 | #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor |
michael@0 | 22 | #include "mozilla/layers/TextureClient.h" // for TextureClient |
michael@0 | 23 | #include "mozilla/mozalloc.h" // for operator delete |
michael@0 | 24 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 25 | #include "nsPoint.h" // for nsIntPoint |
michael@0 | 26 | #include "nsRect.h" // for nsIntRect |
michael@0 | 27 | #include "nsRegion.h" // for nsIntRegion |
michael@0 | 28 | #include "nsTArray.h" // for nsTArray |
michael@0 | 29 | |
michael@0 | 30 | class gfxContext; |
michael@0 | 31 | |
michael@0 | 32 | namespace mozilla { |
michael@0 | 33 | namespace gfx { |
michael@0 | 34 | class DrawTarget; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | namespace layers { |
michael@0 | 38 | |
michael@0 | 39 | class BasicLayerManager; |
michael@0 | 40 | class ThebesLayer; |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * A compositable client for Thebes layers. These are different to Image/Canvas |
michael@0 | 44 | * clients due to sending a valid region across IPC and because we do a lot more |
michael@0 | 45 | * optimisation work, encapsualted in RotatedContentBuffers. |
michael@0 | 46 | * |
michael@0 | 47 | * We use content clients for OMTC and non-OMTC, basic rendering so that |
michael@0 | 48 | * BasicThebesLayer has only one interface to deal with. We support single and |
michael@0 | 49 | * double buffered flavours. For tiled layers, we do not use a ContentClient |
michael@0 | 50 | * although we do have a ContentHost, and we do use texture clients and texture |
michael@0 | 51 | * hosts. |
michael@0 | 52 | * |
michael@0 | 53 | * The interface presented by ContentClient is used by the BasicThebesLayer |
michael@0 | 54 | * methods - PaintThebes, which is the same for MT and OMTC, and PaintBuffer |
michael@0 | 55 | * which is different (the OMTC one does a little more). The 'buffer' in the |
michael@0 | 56 | * names of a lot of these method is actually the TextureClient. But, 'buffer' |
michael@0 | 57 | * for the RotatedContentBuffer (as in SetBuffer) means a gfxSurface. See the |
michael@0 | 58 | * comments for SetBuffer and SetBufferProvider in RotatedContentBuffer. To keep |
michael@0 | 59 | * these mapped buffers alive, we store a pointer in mOldTextures if the |
michael@0 | 60 | * RotatedContentBuffer's surface is not the one from our texture client, once we |
michael@0 | 61 | * are done painting we unmap the surface/texture client and don't need to keep |
michael@0 | 62 | * it alive anymore, so we clear mOldTextures. |
michael@0 | 63 | * |
michael@0 | 64 | * The sequence for painting is: call BeginPaint on the content client; |
michael@0 | 65 | * call BeginPaintBuffer on the content client. That will initialise the buffer |
michael@0 | 66 | * for painting, by calling RotatedContentBuffer::BeginPaint (usually) which |
michael@0 | 67 | * will call back to ContentClient::FinalizeFrame to finalize update of the |
michael@0 | 68 | * buffers before drawing (i.e., it finalizes the previous frame). Then call |
michael@0 | 69 | * BorrowDrawTargetForPainting to get a DrawTarget to paint into. Then paint. |
michael@0 | 70 | * Then return that DrawTarget using ReturnDrawTarget. |
michael@0 | 71 | * Call EndPaint on the content client; |
michael@0 | 72 | * |
michael@0 | 73 | * SwapBuffers is called in response to the transaction reply from the compositor. |
michael@0 | 74 | */ |
michael@0 | 75 | class ContentClient : public CompositableClient |
michael@0 | 76 | { |
michael@0 | 77 | public: |
michael@0 | 78 | /** |
michael@0 | 79 | * Creates, configures, and returns a new content client. If necessary, a |
michael@0 | 80 | * message will be sent to the compositor to create a corresponding content |
michael@0 | 81 | * host. |
michael@0 | 82 | */ |
michael@0 | 83 | static TemporaryRef<ContentClient> CreateContentClient(CompositableForwarder* aFwd); |
michael@0 | 84 | |
michael@0 | 85 | ContentClient(CompositableForwarder* aForwarder) |
michael@0 | 86 | : CompositableClient(aForwarder) |
michael@0 | 87 | {} |
michael@0 | 88 | virtual ~ContentClient() |
michael@0 | 89 | {} |
michael@0 | 90 | |
michael@0 | 91 | |
michael@0 | 92 | virtual void Clear() = 0; |
michael@0 | 93 | virtual RotatedContentBuffer::PaintState BeginPaintBuffer(ThebesLayer* aLayer, |
michael@0 | 94 | uint32_t aFlags) = 0; |
michael@0 | 95 | virtual gfx::DrawTarget* BorrowDrawTargetForPainting(const RotatedContentBuffer::PaintState& aPaintState, |
michael@0 | 96 | RotatedContentBuffer::DrawIterator* aIter = nullptr) = 0; |
michael@0 | 97 | virtual void ReturnDrawTargetToBuffer(gfx::DrawTarget*& aReturned) = 0; |
michael@0 | 98 | |
michael@0 | 99 | // Called as part of the layers transation reply. Conveys data about our |
michael@0 | 100 | // buffer(s) from the compositor. If appropriate we should swap references |
michael@0 | 101 | // to our buffers. |
michael@0 | 102 | virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) {} |
michael@0 | 103 | |
michael@0 | 104 | // call before and after painting into this content client |
michael@0 | 105 | virtual void BeginPaint() {} |
michael@0 | 106 | virtual void EndPaint(); |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * A ContentClient for use with OMTC. |
michael@0 | 111 | */ |
michael@0 | 112 | class ContentClientRemote : public ContentClient |
michael@0 | 113 | { |
michael@0 | 114 | public: |
michael@0 | 115 | ContentClientRemote(CompositableForwarder* aForwarder) |
michael@0 | 116 | : ContentClient(aForwarder) |
michael@0 | 117 | {} |
michael@0 | 118 | |
michael@0 | 119 | virtual void Updated(const nsIntRegion& aRegionToDraw, |
michael@0 | 120 | const nsIntRegion& aVisibleRegion, |
michael@0 | 121 | bool aDidSelfCopy) = 0; |
michael@0 | 122 | }; |
michael@0 | 123 | |
michael@0 | 124 | // thin wrapper around RotatedContentBuffer, for on-mtc |
michael@0 | 125 | class ContentClientBasic : public ContentClient |
michael@0 | 126 | , protected RotatedContentBuffer |
michael@0 | 127 | { |
michael@0 | 128 | public: |
michael@0 | 129 | ContentClientBasic(); |
michael@0 | 130 | |
michael@0 | 131 | typedef RotatedContentBuffer::PaintState PaintState; |
michael@0 | 132 | typedef RotatedContentBuffer::ContentType ContentType; |
michael@0 | 133 | |
michael@0 | 134 | virtual void Clear() { RotatedContentBuffer::Clear(); } |
michael@0 | 135 | virtual PaintState BeginPaintBuffer(ThebesLayer* aLayer, |
michael@0 | 136 | uint32_t aFlags) MOZ_OVERRIDE |
michael@0 | 137 | { |
michael@0 | 138 | return RotatedContentBuffer::BeginPaint(aLayer, aFlags); |
michael@0 | 139 | } |
michael@0 | 140 | virtual gfx::DrawTarget* BorrowDrawTargetForPainting(const PaintState& aPaintState, |
michael@0 | 141 | RotatedContentBuffer::DrawIterator* aIter = nullptr) MOZ_OVERRIDE |
michael@0 | 142 | { |
michael@0 | 143 | return RotatedContentBuffer::BorrowDrawTargetForPainting(aPaintState, aIter); |
michael@0 | 144 | } |
michael@0 | 145 | virtual void ReturnDrawTargetToBuffer(gfx::DrawTarget*& aReturned) MOZ_OVERRIDE |
michael@0 | 146 | { |
michael@0 | 147 | BorrowDrawTarget::ReturnDrawTarget(aReturned); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | void DrawTo(ThebesLayer* aLayer, |
michael@0 | 151 | gfx::DrawTarget* aTarget, |
michael@0 | 152 | float aOpacity, |
michael@0 | 153 | gfx::CompositionOp aOp, |
michael@0 | 154 | gfx::SourceSurface* aMask, |
michael@0 | 155 | const gfx::Matrix* aMaskTransform) |
michael@0 | 156 | { |
michael@0 | 157 | RotatedContentBuffer::DrawTo(aLayer, aTarget, aOpacity, aOp, |
michael@0 | 158 | aMask, aMaskTransform); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | virtual void CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, |
michael@0 | 162 | RefPtr<gfx::DrawTarget>* aBlackDT, RefPtr<gfx::DrawTarget>* aWhiteDT) MOZ_OVERRIDE; |
michael@0 | 163 | |
michael@0 | 164 | virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE |
michael@0 | 165 | { |
michael@0 | 166 | MOZ_CRASH("Should not be called on non-remote ContentClient"); |
michael@0 | 167 | } |
michael@0 | 168 | }; |
michael@0 | 169 | |
michael@0 | 170 | /** |
michael@0 | 171 | * A ContentClientRemote backed by a RotatedContentBuffer. |
michael@0 | 172 | * |
michael@0 | 173 | * When using a ContentClientRemote, SurfaceDescriptors are created on |
michael@0 | 174 | * the rendering side and destroyed on the compositing side. They are only |
michael@0 | 175 | * passed from one side to the other when the TextureClient/Hosts are created. |
michael@0 | 176 | * *Ownership* of the SurfaceDescriptor moves from the rendering side to the |
michael@0 | 177 | * compositing side with the create message (send from CreateBuffer) which |
michael@0 | 178 | * tells the compositor that TextureClients have been created and that the |
michael@0 | 179 | * compositor should assign the corresponding TextureHosts to our corresponding |
michael@0 | 180 | * ContentHost. |
michael@0 | 181 | * |
michael@0 | 182 | * If the size or type of our buffer(s) change(s), then we simply destroy and |
michael@0 | 183 | * create them. |
michael@0 | 184 | */ |
michael@0 | 185 | // Version using new texture clients |
michael@0 | 186 | class ContentClientRemoteBuffer : public ContentClientRemote |
michael@0 | 187 | , protected RotatedContentBuffer |
michael@0 | 188 | { |
michael@0 | 189 | using RotatedContentBuffer::BufferRect; |
michael@0 | 190 | using RotatedContentBuffer::BufferRotation; |
michael@0 | 191 | public: |
michael@0 | 192 | ContentClientRemoteBuffer(CompositableForwarder* aForwarder) |
michael@0 | 193 | : ContentClientRemote(aForwarder) |
michael@0 | 194 | , RotatedContentBuffer(ContainsVisibleBounds) |
michael@0 | 195 | , mIsNewBuffer(false) |
michael@0 | 196 | , mFrontAndBackBufferDiffer(false) |
michael@0 | 197 | , mSurfaceFormat(gfx::SurfaceFormat::B8G8R8A8) |
michael@0 | 198 | {} |
michael@0 | 199 | |
michael@0 | 200 | typedef RotatedContentBuffer::PaintState PaintState; |
michael@0 | 201 | typedef RotatedContentBuffer::ContentType ContentType; |
michael@0 | 202 | |
michael@0 | 203 | virtual void Clear() |
michael@0 | 204 | { |
michael@0 | 205 | RotatedContentBuffer::Clear(); |
michael@0 | 206 | mTextureClient = nullptr; |
michael@0 | 207 | mTextureClientOnWhite = nullptr; |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | virtual PaintState BeginPaintBuffer(ThebesLayer* aLayer, |
michael@0 | 211 | uint32_t aFlags) MOZ_OVERRIDE |
michael@0 | 212 | { |
michael@0 | 213 | return RotatedContentBuffer::BeginPaint(aLayer, aFlags); |
michael@0 | 214 | } |
michael@0 | 215 | virtual gfx::DrawTarget* BorrowDrawTargetForPainting(const PaintState& aPaintState, |
michael@0 | 216 | RotatedContentBuffer::DrawIterator* aIter = nullptr) MOZ_OVERRIDE |
michael@0 | 217 | { |
michael@0 | 218 | return RotatedContentBuffer::BorrowDrawTargetForPainting(aPaintState, aIter); |
michael@0 | 219 | } |
michael@0 | 220 | virtual void ReturnDrawTargetToBuffer(gfx::DrawTarget*& aReturned) MOZ_OVERRIDE |
michael@0 | 221 | { |
michael@0 | 222 | BorrowDrawTarget::ReturnDrawTarget(aReturned); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * Begin/End Paint map a gfxASurface from the texture client |
michael@0 | 227 | * into the buffer of RotatedBuffer. The surface is only |
michael@0 | 228 | * valid when the texture client is locked, so is mapped out |
michael@0 | 229 | * of RotatedContentBuffer when we are done painting. |
michael@0 | 230 | * None of the underlying buffer attributes (rect, rotation) |
michael@0 | 231 | * are affected by mapping/unmapping. |
michael@0 | 232 | */ |
michael@0 | 233 | virtual void BeginPaint() MOZ_OVERRIDE; |
michael@0 | 234 | virtual void EndPaint() MOZ_OVERRIDE; |
michael@0 | 235 | |
michael@0 | 236 | virtual void Updated(const nsIntRegion& aRegionToDraw, |
michael@0 | 237 | const nsIntRegion& aVisibleRegion, |
michael@0 | 238 | bool aDidSelfCopy); |
michael@0 | 239 | |
michael@0 | 240 | virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) MOZ_OVERRIDE; |
michael@0 | 241 | |
michael@0 | 242 | // Expose these protected methods from the superclass. |
michael@0 | 243 | virtual const nsIntRect& BufferRect() const |
michael@0 | 244 | { |
michael@0 | 245 | return RotatedContentBuffer::BufferRect(); |
michael@0 | 246 | } |
michael@0 | 247 | virtual const nsIntPoint& BufferRotation() const |
michael@0 | 248 | { |
michael@0 | 249 | return RotatedContentBuffer::BufferRotation(); |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | virtual void CreateBuffer(ContentType aType, const nsIntRect& aRect, uint32_t aFlags, |
michael@0 | 253 | RefPtr<gfx::DrawTarget>* aBlackDT, RefPtr<gfx::DrawTarget>* aWhiteDT) MOZ_OVERRIDE; |
michael@0 | 254 | |
michael@0 | 255 | virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE |
michael@0 | 256 | { |
michael@0 | 257 | return mTextureInfo; |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | protected: |
michael@0 | 261 | void DestroyBuffers(); |
michael@0 | 262 | |
michael@0 | 263 | virtual nsIntRegion GetUpdatedRegion(const nsIntRegion& aRegionToDraw, |
michael@0 | 264 | const nsIntRegion& aVisibleRegion, |
michael@0 | 265 | bool aDidSelfCopy); |
michael@0 | 266 | |
michael@0 | 267 | void BuildTextureClients(gfx::SurfaceFormat aFormat, |
michael@0 | 268 | const nsIntRect& aRect, |
michael@0 | 269 | uint32_t aFlags); |
michael@0 | 270 | |
michael@0 | 271 | // Create the front buffer for the ContentClient/Host pair if necessary |
michael@0 | 272 | // and notify the compositor that we have created the buffer(s). |
michael@0 | 273 | virtual void CreateFrontBuffer(const nsIntRect& aBufferRect) = 0; |
michael@0 | 274 | virtual void DestroyFrontBuffer() {} |
michael@0 | 275 | |
michael@0 | 276 | bool CreateAndAllocateTextureClient(RefPtr<TextureClient>& aClient, |
michael@0 | 277 | TextureFlags aFlags = 0); |
michael@0 | 278 | |
michael@0 | 279 | virtual void AbortTextureClientCreation() |
michael@0 | 280 | { |
michael@0 | 281 | mTextureClient = nullptr; |
michael@0 | 282 | mTextureClientOnWhite = nullptr; |
michael@0 | 283 | mIsNewBuffer = false; |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | RefPtr<TextureClient> mTextureClient; |
michael@0 | 287 | RefPtr<TextureClient> mTextureClientOnWhite; |
michael@0 | 288 | // keep a record of texture clients we have created and need to keep around |
michael@0 | 289 | // (for RotatedBuffer to access), then unlock and remove them when we are done |
michael@0 | 290 | // painting. |
michael@0 | 291 | nsTArray<RefPtr<TextureClient> > mOldTextures; |
michael@0 | 292 | |
michael@0 | 293 | TextureInfo mTextureInfo; |
michael@0 | 294 | bool mIsNewBuffer; |
michael@0 | 295 | bool mFrontAndBackBufferDiffer; |
michael@0 | 296 | gfx::IntSize mSize; |
michael@0 | 297 | gfx::SurfaceFormat mSurfaceFormat; |
michael@0 | 298 | }; |
michael@0 | 299 | |
michael@0 | 300 | /** |
michael@0 | 301 | * A double buffered ContentClient. mTextureClient is the back buffer, which |
michael@0 | 302 | * we draw into. mFrontClient is the front buffer which we may read from, but |
michael@0 | 303 | * not write to, when the compositor does not have the 'soft' lock. We can write |
michael@0 | 304 | * into mTextureClient at any time. |
michael@0 | 305 | * |
michael@0 | 306 | * The ContentHost keeps a reference to both corresponding texture hosts, in |
michael@0 | 307 | * response to our UpdateTextureRegion message, the compositor swaps its |
michael@0 | 308 | * references. In response to the compositor's reply we swap our references |
michael@0 | 309 | * (in SwapBuffers). |
michael@0 | 310 | */ |
michael@0 | 311 | class ContentClientDoubleBuffered : public ContentClientRemoteBuffer |
michael@0 | 312 | { |
michael@0 | 313 | public: |
michael@0 | 314 | ContentClientDoubleBuffered(CompositableForwarder* aFwd) |
michael@0 | 315 | : ContentClientRemoteBuffer(aFwd) |
michael@0 | 316 | { |
michael@0 | 317 | mTextureInfo.mCompositableType = COMPOSITABLE_CONTENT_DOUBLE; |
michael@0 | 318 | } |
michael@0 | 319 | virtual ~ContentClientDoubleBuffered() {} |
michael@0 | 320 | |
michael@0 | 321 | virtual void Clear() MOZ_OVERRIDE |
michael@0 | 322 | { |
michael@0 | 323 | ContentClientRemoteBuffer::Clear(); |
michael@0 | 324 | mFrontClient = nullptr; |
michael@0 | 325 | mFrontClientOnWhite = nullptr; |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) MOZ_OVERRIDE; |
michael@0 | 329 | |
michael@0 | 330 | virtual void BeginPaint() MOZ_OVERRIDE; |
michael@0 | 331 | |
michael@0 | 332 | virtual void FinalizeFrame(const nsIntRegion& aRegionToDraw) MOZ_OVERRIDE; |
michael@0 | 333 | |
michael@0 | 334 | protected: |
michael@0 | 335 | virtual void CreateFrontBuffer(const nsIntRect& aBufferRect) MOZ_OVERRIDE; |
michael@0 | 336 | virtual void DestroyFrontBuffer() MOZ_OVERRIDE; |
michael@0 | 337 | |
michael@0 | 338 | private: |
michael@0 | 339 | void UpdateDestinationFrom(const RotatedBuffer& aSource, |
michael@0 | 340 | const nsIntRegion& aUpdateRegion); |
michael@0 | 341 | |
michael@0 | 342 | virtual void AbortTextureClientCreation() MOZ_OVERRIDE |
michael@0 | 343 | { |
michael@0 | 344 | mTextureClient = nullptr; |
michael@0 | 345 | mTextureClientOnWhite = nullptr; |
michael@0 | 346 | mFrontClient = nullptr; |
michael@0 | 347 | mFrontClientOnWhite = nullptr; |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | RefPtr<TextureClient> mFrontClient; |
michael@0 | 351 | RefPtr<TextureClient> mFrontClientOnWhite; |
michael@0 | 352 | nsIntRegion mFrontUpdatedRegion; |
michael@0 | 353 | nsIntRect mFrontBufferRect; |
michael@0 | 354 | nsIntPoint mFrontBufferRotation; |
michael@0 | 355 | }; |
michael@0 | 356 | |
michael@0 | 357 | /** |
michael@0 | 358 | * A single buffered ContentClient. We have a single TextureClient/Host |
michael@0 | 359 | * which we update and then send a message to the compositor that we are |
michael@0 | 360 | * done updating. It is not safe for the compositor to use the corresponding |
michael@0 | 361 | * TextureHost's memory directly, it must upload it to video memory of some |
michael@0 | 362 | * kind. We are free to modify the TextureClient once we receive reply from |
michael@0 | 363 | * the compositor. |
michael@0 | 364 | */ |
michael@0 | 365 | class ContentClientSingleBuffered : public ContentClientRemoteBuffer |
michael@0 | 366 | { |
michael@0 | 367 | public: |
michael@0 | 368 | ContentClientSingleBuffered(CompositableForwarder* aFwd) |
michael@0 | 369 | : ContentClientRemoteBuffer(aFwd) |
michael@0 | 370 | { |
michael@0 | 371 | mTextureInfo.mCompositableType = COMPOSITABLE_CONTENT_SINGLE; |
michael@0 | 372 | } |
michael@0 | 373 | virtual ~ContentClientSingleBuffered() {} |
michael@0 | 374 | |
michael@0 | 375 | virtual void FinalizeFrame(const nsIntRegion& aRegionToDraw) MOZ_OVERRIDE; |
michael@0 | 376 | |
michael@0 | 377 | protected: |
michael@0 | 378 | virtual void CreateFrontBuffer(const nsIntRect& aBufferRect) MOZ_OVERRIDE {} |
michael@0 | 379 | }; |
michael@0 | 380 | |
michael@0 | 381 | /** |
michael@0 | 382 | * A single buffered ContentClient that creates temporary buffers which are |
michael@0 | 383 | * used to update the host-side texture. The ownership of the buffers is |
michael@0 | 384 | * passed to the host side during the transaction, and we need to create |
michael@0 | 385 | * new ones each frame. |
michael@0 | 386 | */ |
michael@0 | 387 | class ContentClientIncremental : public ContentClientRemote |
michael@0 | 388 | , public BorrowDrawTarget |
michael@0 | 389 | { |
michael@0 | 390 | public: |
michael@0 | 391 | ContentClientIncremental(CompositableForwarder* aFwd) |
michael@0 | 392 | : ContentClientRemote(aFwd) |
michael@0 | 393 | , mContentType(gfxContentType::COLOR_ALPHA) |
michael@0 | 394 | , mHasBuffer(false) |
michael@0 | 395 | , mHasBufferOnWhite(false) |
michael@0 | 396 | { |
michael@0 | 397 | mTextureInfo.mCompositableType = BUFFER_CONTENT_INC; |
michael@0 | 398 | } |
michael@0 | 399 | |
michael@0 | 400 | typedef RotatedContentBuffer::PaintState PaintState; |
michael@0 | 401 | typedef RotatedContentBuffer::ContentType ContentType; |
michael@0 | 402 | |
michael@0 | 403 | virtual TextureInfo GetTextureInfo() const |
michael@0 | 404 | { |
michael@0 | 405 | return mTextureInfo; |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | virtual void Clear() |
michael@0 | 409 | { |
michael@0 | 410 | mBufferRect.SetEmpty(); |
michael@0 | 411 | mHasBuffer = false; |
michael@0 | 412 | mHasBufferOnWhite = false; |
michael@0 | 413 | } |
michael@0 | 414 | |
michael@0 | 415 | virtual PaintState BeginPaintBuffer(ThebesLayer* aLayer, |
michael@0 | 416 | uint32_t aFlags) MOZ_OVERRIDE; |
michael@0 | 417 | virtual gfx::DrawTarget* BorrowDrawTargetForPainting(const PaintState& aPaintState, |
michael@0 | 418 | RotatedContentBuffer::DrawIterator* aIter = nullptr) MOZ_OVERRIDE; |
michael@0 | 419 | virtual void ReturnDrawTargetToBuffer(gfx::DrawTarget*& aReturned) MOZ_OVERRIDE |
michael@0 | 420 | { |
michael@0 | 421 | BorrowDrawTarget::ReturnDrawTarget(aReturned); |
michael@0 | 422 | } |
michael@0 | 423 | |
michael@0 | 424 | virtual void Updated(const nsIntRegion& aRegionToDraw, |
michael@0 | 425 | const nsIntRegion& aVisibleRegion, |
michael@0 | 426 | bool aDidSelfCopy); |
michael@0 | 427 | |
michael@0 | 428 | virtual void EndPaint() |
michael@0 | 429 | { |
michael@0 | 430 | if (IsSurfaceDescriptorValid(mUpdateDescriptor)) { |
michael@0 | 431 | mForwarder->DestroySharedSurface(&mUpdateDescriptor); |
michael@0 | 432 | } |
michael@0 | 433 | if (IsSurfaceDescriptorValid(mUpdateDescriptorOnWhite)) { |
michael@0 | 434 | mForwarder->DestroySharedSurface(&mUpdateDescriptorOnWhite); |
michael@0 | 435 | } |
michael@0 | 436 | ContentClientRemote::EndPaint(); |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | private: |
michael@0 | 440 | |
michael@0 | 441 | enum BufferType{ |
michael@0 | 442 | BUFFER_BLACK, |
michael@0 | 443 | BUFFER_WHITE |
michael@0 | 444 | }; |
michael@0 | 445 | |
michael@0 | 446 | void NotifyBufferCreated(ContentType aType, uint32_t aFlags) |
michael@0 | 447 | { |
michael@0 | 448 | mTextureInfo.mTextureFlags = aFlags & ~TEXTURE_DEALLOCATE_CLIENT; |
michael@0 | 449 | mContentType = aType; |
michael@0 | 450 | |
michael@0 | 451 | mForwarder->CreatedIncrementalBuffer(this, |
michael@0 | 452 | mTextureInfo, |
michael@0 | 453 | mBufferRect); |
michael@0 | 454 | |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | TemporaryRef<gfx::DrawTarget> GetUpdateSurface(BufferType aType, |
michael@0 | 458 | const nsIntRegion& aUpdateRegion); |
michael@0 | 459 | |
michael@0 | 460 | TextureInfo mTextureInfo; |
michael@0 | 461 | nsIntRect mBufferRect; |
michael@0 | 462 | nsIntPoint mBufferRotation; |
michael@0 | 463 | |
michael@0 | 464 | SurfaceDescriptor mUpdateDescriptor; |
michael@0 | 465 | SurfaceDescriptor mUpdateDescriptorOnWhite; |
michael@0 | 466 | |
michael@0 | 467 | ContentType mContentType; |
michael@0 | 468 | |
michael@0 | 469 | bool mHasBuffer; |
michael@0 | 470 | bool mHasBufferOnWhite; |
michael@0 | 471 | }; |
michael@0 | 472 | |
michael@0 | 473 | } |
michael@0 | 474 | } |
michael@0 | 475 | |
michael@0 | 476 | #endif |