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 * StaticPrefs::PerTileDrawing(). 24 */ 25 class ClientSingleTiledLayerBuffer : public ClientTiledLayerBuffer, 26 public TextureClientAllocator { 27 virtual ~ClientSingleTiledLayerBuffer() = default; 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 mValidRegion.SetEmpty(); 61 mTile.DiscardBuffers(); 62 } 63 GetValidRegion()64 const nsIntRegion& GetValidRegion() override { return mValidRegion; } 65 IsLowPrecision()66 bool IsLowPrecision() const override { return false; } 67 68 void ReleaseTiles(); 69 70 void DiscardBuffers(); 71 72 SurfaceDescriptorTiles GetSurfaceDescriptorTiles(); 73 74 private: 75 TileClient mTile; 76 77 RefPtr<ClientLayerManager> mManager; 78 79 nsIntRegion mValidRegion; 80 bool mWasLastPaintProgressive; 81 82 /** 83 * While we're adding tiles, this is used to keep track of the position of 84 * the top-left of the top-left-most tile. When we come to wrap the tiles in 85 * TiledDrawTarget we subtract the value of this member from each tile's 86 * offset so that all the tiles have a positive offset, then add a 87 * translation to the TiledDrawTarget to compensate. This is important so 88 * that the mRect of the TiledDrawTarget is always at a positive x/y 89 * position, otherwise its GetSize() methods will be broken. 90 */ 91 gfx::IntPoint mTilingOrigin; 92 gfx::IntSize mSize; 93 gfxImageFormat mFormat; 94 }; 95 96 class SingleTiledContentClient : public TiledContentClient { 97 public: 98 SingleTiledContentClient(ClientTiledPaintedLayer& aPaintedLayer, 99 ClientLayerManager* aManager); 100 101 protected: ~SingleTiledContentClient()102 ~SingleTiledContentClient() { 103 MOZ_COUNT_DTOR(SingleTiledContentClient); 104 105 mTiledBuffer->ReleaseTiles(); 106 } 107 108 public: 109 static bool ClientSupportsLayerSize(const gfx::IntSize& aSize, 110 ClientLayerManager* aManager); 111 112 void ClearCachedResources() override; 113 114 void UpdatedBuffer(TiledBufferType aType) override; 115 GetTiledBuffer()116 ClientTiledLayerBuffer* GetTiledBuffer() override { return mTiledBuffer; } GetLowPrecisionTiledBuffer()117 ClientTiledLayerBuffer* GetLowPrecisionTiledBuffer() override { 118 return nullptr; 119 } 120 121 private: 122 RefPtr<ClientSingleTiledLayerBuffer> mTiledBuffer; 123 }; 124 125 } // namespace layers 126 } // namespace mozilla 127 128 #endif 129