1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef MOZILLA_GFX_SINGLETILEDCONTENTCLIENT_H
8 #define MOZILLA_GFX_SINGLETILEDCONTENTCLIENT_H
9 
10 #include "TiledContentClient.h"
11 
12 namespace mozilla {
13 namespace layers {
14 
15 class ClientTiledPaintedLayer;
16 class ClientLayerManager;
17 
18 /**
19  * Provide an instance of TiledLayerBuffer backed by drawable TextureClients.
20  * This buffer provides an implementation of ValidateTile using a
21  * thebes callback and can support painting using a single paint buffer.
22  * Whether a single paint buffer is used is controlled by
23  * gfxPrefs::PerTileDrawing().
24  */
25 class ClientSingleTiledLayerBuffer : public ClientTiledLayerBuffer,
26                                      public TextureClientAllocator {
~ClientSingleTiledLayerBuffer()27   virtual ~ClientSingleTiledLayerBuffer() {}
28 
29  public:
30   ClientSingleTiledLayerBuffer(ClientTiledPaintedLayer& aPaintedLayer,
31                                CompositableClient& aCompositableClient,
32                                ClientLayerManager* aManager);
33 
34   // TextureClientAllocator
35   already_AddRefed<TextureClient> GetTextureClient() override;
ReturnTextureClientDeferred(TextureClient * aClient)36   void ReturnTextureClientDeferred(TextureClient* aClient) override {}
ReportClientLost()37   void ReportClientLost() override {}
38 
39   // ClientTiledLayerBuffer
40   void PaintThebes(const nsIntRegion& aNewValidRegion,
41                    const nsIntRegion& aPaintRegion,
42                    const nsIntRegion& aDirtyRegion,
43                    LayerManager::DrawPaintedLayerCallback aCallback,
44                    void* aCallbackData,
45                    TilePaintFlags aFlags = TilePaintFlags::None) override;
46 
SupportsProgressiveUpdate()47   bool SupportsProgressiveUpdate() override { return false; }
ProgressiveUpdate(const nsIntRegion & aValidRegion,const nsIntRegion & aInvalidRegion,const nsIntRegion & aOldValidRegion,nsIntRegion & aOutDrawnRegion,BasicTiledLayerPaintData * aPaintData,LayerManager::DrawPaintedLayerCallback aCallback,void * aCallbackData)48   bool ProgressiveUpdate(const nsIntRegion& aValidRegion,
49                          const nsIntRegion& aInvalidRegion,
50                          const nsIntRegion& aOldValidRegion,
51                          nsIntRegion& aOutDrawnRegion,
52                          BasicTiledLayerPaintData* aPaintData,
53                          LayerManager::DrawPaintedLayerCallback aCallback,
54                          void* aCallbackData) override {
55     MOZ_ASSERT(false, "ProgressiveUpdate not supported!");
56     return false;
57   }
58 
ResetPaintedAndValidState()59   void ResetPaintedAndValidState() override {
60     mPaintedRegion.SetEmpty();
61     mValidRegion.SetEmpty();
62     mTile.DiscardBuffers();
63   }
64 
GetValidRegion()65   const nsIntRegion& GetValidRegion() override { return mValidRegion; }
66 
IsLowPrecision()67   bool IsLowPrecision() const override { return false; }
68 
69   void ReleaseTiles();
70 
71   void DiscardBuffers();
72 
73   SurfaceDescriptorTiles GetSurfaceDescriptorTiles();
74 
ClearPaintedRegion()75   void ClearPaintedRegion() { mPaintedRegion.SetEmpty(); }
76 
77  private:
78   TileClient mTile;
79 
80   RefPtr<ClientLayerManager> mManager;
81 
82   nsIntRegion mPaintedRegion;
83   nsIntRegion mValidRegion;
84   bool mWasLastPaintProgressive;
85 
86   /**
87    * While we're adding tiles, this is used to keep track of the position of
88    * the top-left of the top-left-most tile.  When we come to wrap the tiles in
89    * TiledDrawTarget we subtract the value of this member from each tile's
90    * offset so that all the tiles have a positive offset, then add a
91    * translation to the TiledDrawTarget to compensate.  This is important so
92    * that the mRect of the TiledDrawTarget is always at a positive x/y
93    * position, otherwise its GetSize() methods will be broken.
94    */
95   gfx::IntPoint mTilingOrigin;
96   gfx::IntSize mSize;
97   gfxImageFormat mFormat;
98 };
99 
100 class SingleTiledContentClient : public TiledContentClient {
101  public:
102   SingleTiledContentClient(ClientTiledPaintedLayer& aPaintedLayer,
103                            ClientLayerManager* aManager);
104 
105  protected:
~SingleTiledContentClient()106   ~SingleTiledContentClient() {
107     MOZ_COUNT_DTOR(SingleTiledContentClient);
108 
109     mTiledBuffer->ReleaseTiles();
110   }
111 
112  public:
113   static bool ClientSupportsLayerSize(const gfx::IntSize& aSize,
114                                       ClientLayerManager* aManager);
115 
116   virtual void ClearCachedResources() override;
117 
118   virtual void UpdatedBuffer(TiledBufferType aType) override;
119 
GetTiledBuffer()120   virtual ClientTiledLayerBuffer* GetTiledBuffer() override {
121     return mTiledBuffer;
122   }
GetLowPrecisionTiledBuffer()123   virtual ClientTiledLayerBuffer* GetLowPrecisionTiledBuffer() override {
124     return nullptr;
125   }
126 
127  private:
128   RefPtr<ClientSingleTiledLayerBuffer> mTiledBuffer;
129 };
130 
131 }  // namespace layers
132 }  // namespace mozilla
133 
134 #endif
135