1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/client/SimpleTiledContentClient.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,189 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef MOZILLA_GFX_SIMPLETILEDCONTENTCLIENT_H 1.10 +#define MOZILLA_GFX_SIMPLETILEDCONTENTCLIENT_H 1.11 + 1.12 +// We include this header here so that we don't need to 1.13 +// duplicate BasicTiledLayerPaintData 1.14 +#include "TiledContentClient.h" 1.15 + 1.16 +#include "SharedBuffer.h" 1.17 + 1.18 +namespace mozilla { 1.19 +namespace layers { 1.20 + 1.21 +class ClientTiledThebesLayer; 1.22 + 1.23 +class SimpleTiledLayerTile; 1.24 +class SimpleTiledLayerBuffer; 1.25 +class SimpleClientTiledThebesLayer; 1.26 +class SimpleTiledLayerBuffer; 1.27 + 1.28 +#define GFX_SIMP_TILEDLAYER_DEBUG_OVERLAY 1.29 + 1.30 +struct SimpleTiledLayerTile 1.31 +{ 1.32 + RefPtr<TextureClient> mTileBuffer; 1.33 + RefPtr<ClientLayerManager> mManager; 1.34 + nsRefPtr<SharedBuffer> mCachedBuffer; 1.35 + TimeStamp mLastUpdate; 1.36 + 1.37 + SimpleTiledLayerTile() { } 1.38 + 1.39 + SimpleTiledLayerTile(ClientLayerManager *aManager, TextureClient *aBuffer) 1.40 + : mTileBuffer(aBuffer) 1.41 + , mManager(aManager) 1.42 + { } 1.43 + 1.44 + bool operator== (const SimpleTiledLayerTile& o) const 1.45 + { 1.46 + return mTileBuffer == o.mTileBuffer; 1.47 + } 1.48 + 1.49 + bool operator!= (const SimpleTiledLayerTile& o) const 1.50 + { 1.51 + return mTileBuffer != o.mTileBuffer; 1.52 + } 1.53 + 1.54 + void SetLayerManager(ClientLayerManager *aManager) 1.55 + { 1.56 + mManager = aManager; 1.57 + } 1.58 + 1.59 + bool IsPlaceholderTile() 1.60 + { 1.61 + return mTileBuffer == nullptr; 1.62 + } 1.63 + 1.64 + TileDescriptor GetTileDescriptor() 1.65 + { 1.66 + if (mTileBuffer) 1.67 + return TexturedTileDescriptor(nullptr, mTileBuffer->GetIPDLActor(), 0); 1.68 + 1.69 + NS_NOTREACHED("Unhandled SimpleTiledLayerTile type"); 1.70 + return PlaceholderTileDescriptor(); 1.71 + } 1.72 + 1.73 + void Release() 1.74 + { 1.75 + mTileBuffer = nullptr; 1.76 + mCachedBuffer = nullptr; 1.77 + } 1.78 +}; 1.79 + 1.80 +class SimpleTiledLayerBuffer 1.81 + : public TiledLayerBuffer<SimpleTiledLayerBuffer, SimpleTiledLayerTile> 1.82 +{ 1.83 + friend class TiledLayerBuffer<SimpleTiledLayerBuffer, SimpleTiledLayerTile>; 1.84 + 1.85 +public: 1.86 + SimpleTiledLayerBuffer(SimpleClientTiledThebesLayer* aThebesLayer, 1.87 + CompositableClient* aCompositableClient, 1.88 + ClientLayerManager* aManager) 1.89 + : mThebesLayer(aThebesLayer) 1.90 + , mCompositableClient(aCompositableClient) 1.91 + , mManager(aManager) 1.92 + , mLastPaintOpaque(false) 1.93 + {} 1.94 + 1.95 + SimpleTiledLayerBuffer() 1.96 + : mLastPaintOpaque(false) 1.97 + {} 1.98 + 1.99 + void PaintThebes(const nsIntRegion& aNewValidRegion, 1.100 + const nsIntRegion& aPaintRegion, 1.101 + LayerManager::DrawThebesLayerCallback aCallback, 1.102 + void* aCallbackData); 1.103 + 1.104 + SurfaceDescriptorTiles GetSurfaceDescriptorTiles(); 1.105 + 1.106 + void Release() { 1.107 + for (size_t i = 0; i < mRetainedTiles.Length(); i++) { 1.108 + mRetainedTiles[i].Release(); 1.109 + } 1.110 + } 1.111 + 1.112 + const CSSToParentLayerScale& GetFrameResolution() const { return mFrameResolution; } 1.113 + void SetFrameResolution(const CSSToParentLayerScale& aResolution) { mFrameResolution = aResolution; } 1.114 + 1.115 + bool HasFormatChanged() const; 1.116 +private: 1.117 + SimpleClientTiledThebesLayer* mThebesLayer; 1.118 + CompositableClient* mCompositableClient; 1.119 + ClientLayerManager* mManager; 1.120 + LayerManager::DrawThebesLayerCallback mCallback; 1.121 + void* mCallbackData; 1.122 + CSSToParentLayerScale mFrameResolution; 1.123 + bool mLastPaintOpaque; 1.124 + 1.125 + gfxContentType GetContentType() const; 1.126 + 1.127 + SimpleTiledLayerTile ValidateTile(SimpleTiledLayerTile aTile, 1.128 + const nsIntPoint& aTileOrigin, 1.129 + const nsIntRegion& aDirtyRect); 1.130 + 1.131 + SimpleTiledLayerTile GetPlaceholderTile() const { return SimpleTiledLayerTile(); } 1.132 + 1.133 + void ReleaseTile(SimpleTiledLayerTile aTile) { aTile.Release(); } 1.134 + 1.135 + void SwapTiles(SimpleTiledLayerTile& aTileA, SimpleTiledLayerTile& aTileB) { std::swap(aTileA, aTileB); } 1.136 +}; 1.137 + 1.138 +class SimpleTiledContentClient : public CompositableClient 1.139 +{ 1.140 + friend class SimpleClientTiledThebesLayer; 1.141 + 1.142 +public: 1.143 + SimpleTiledContentClient(SimpleClientTiledThebesLayer* aThebesLayer, 1.144 + ClientLayerManager* aManager); 1.145 + 1.146 + ~SimpleTiledContentClient(); 1.147 + 1.148 + virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE 1.149 + { 1.150 + return TextureInfo(BUFFER_SIMPLE_TILED); 1.151 + } 1.152 + 1.153 + void UseTiledLayerBuffer(); 1.154 + 1.155 +private: 1.156 + SimpleTiledLayerBuffer mTiledBuffer; 1.157 +}; 1.158 + 1.159 +class SimpleClientTiledThebesLayer : public ThebesLayer, 1.160 + public ClientLayer 1.161 +{ 1.162 + typedef ThebesLayer Base; 1.163 + 1.164 +public: 1.165 + SimpleClientTiledThebesLayer(ClientLayerManager* const aManager); 1.166 + ~SimpleClientTiledThebesLayer(); 1.167 + 1.168 + // Thebes Layer 1.169 + virtual Layer* AsLayer() { return this; } 1.170 + virtual void InvalidateRegion(const nsIntRegion& aRegion) { 1.171 + mInvalidRegion.Or(mInvalidRegion, aRegion); 1.172 + mValidRegion.Sub(mValidRegion, aRegion); 1.173 + } 1.174 + 1.175 + // Shadow methods 1.176 + virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs); 1.177 + virtual ShadowableLayer* AsShadowableLayer() { return this; } 1.178 + 1.179 + virtual void Disconnect() { ClientLayer::Disconnect(); } 1.180 + 1.181 + virtual void RenderLayer(); 1.182 + 1.183 +protected: 1.184 + ClientLayerManager* ClientManager() { return static_cast<ClientLayerManager*>(mManager); } 1.185 + 1.186 + RefPtr<SimpleTiledContentClient> mContentClient; 1.187 +}; 1.188 + 1.189 +} // mozilla 1.190 +} // layers 1.191 + 1.192 +#endif