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 GFX_CLIENTPAINTEDLAYER_H
8 #define GFX_CLIENTPAINTEDLAYER_H
9 
10 #include "ClientLayerManager.h"                // for ClientLayerManager, etc
11 #include "Layers.h"                            // for PaintedLayer, etc
12 #include "RotatedBuffer.h"                     // for RotatedBuffer, etc
13 #include "mozilla/Attributes.h"                // for override
14 #include "mozilla/RefPtr.h"                    // for RefPtr
15 #include "mozilla/layers/ContentClient.h"      // for ContentClient
16 #include "mozilla/mozalloc.h"                  // for operator delete
17 #include "nsDebug.h"                           // for NS_ASSERTION
18 #include "nsISupportsImpl.h"                   // for MOZ_COUNT_CTOR, etc
19 #include "nsRegion.h"                          // for nsIntRegion
20 #include "mozilla/layers/PLayerTransaction.h"  // for PaintedLayerAttributes
21 
22 namespace mozilla {
23 namespace gfx {
24 class DrawEventRecorderMemory;
25 class DrawTargetCapture;
26 };  // namespace gfx
27 
28 namespace layers {
29 class CompositableClient;
30 class ShadowableLayer;
31 class SpecificLayerAttributes;
32 
33 class ClientPaintedLayer : public PaintedLayer, public ClientLayer {
34  public:
35   typedef ContentClient::PaintState PaintState;
36   typedef ContentClient::ContentType ContentType;
37 
38   explicit ClientPaintedLayer(
39       ClientLayerManager* aLayerManager,
40       LayerManager::PaintedLayerCreationHint aCreationHint = LayerManager::NONE)
PaintedLayer(aLayerManager,static_cast<ClientLayer * > (this),aCreationHint)41       : PaintedLayer(aLayerManager, static_cast<ClientLayer*>(this),
42                      aCreationHint),
43         mContentClient(nullptr) {
44     MOZ_COUNT_CTOR(ClientPaintedLayer);
45   }
46 
47  protected:
~ClientPaintedLayer()48   virtual ~ClientPaintedLayer() {
49     if (mContentClient) {
50       mContentClient->OnDetach();
51       mContentClient = nullptr;
52     }
53     MOZ_COUNT_DTOR(ClientPaintedLayer);
54   }
55 
56  public:
SetVisibleRegion(const LayerIntRegion & aRegion)57   void SetVisibleRegion(const LayerIntRegion& aRegion) override {
58     NS_ASSERTION(ClientManager()->InConstruction(),
59                  "Can only set properties in construction phase");
60     PaintedLayer::SetVisibleRegion(aRegion);
61   }
InvalidateRegion(const nsIntRegion & aRegion)62   void InvalidateRegion(const nsIntRegion& aRegion) override {
63     NS_ASSERTION(ClientManager()->InConstruction(),
64                  "Can only set properties in construction phase");
65     mInvalidRegion.Add(aRegion);
66     UpdateValidRegionAfterInvalidRegionChanged();
67   }
68 
RenderLayer()69   void RenderLayer() override { RenderLayerWithReadback(nullptr); }
70 
71   void RenderLayerWithReadback(ReadbackProcessor* aReadback) override;
72 
ClearCachedResources()73   void ClearCachedResources() override {
74     if (mContentClient) {
75       mContentClient->Clear();
76     }
77     ClearValidRegion();
78     DestroyBackBuffer();
79   }
80 
HandleMemoryPressure()81   void HandleMemoryPressure() override {
82     if (mContentClient) {
83       mContentClient->HandleMemoryPressure();
84     }
85   }
86 
FillSpecificAttributes(SpecificLayerAttributes & aAttrs)87   void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) override {
88     aAttrs = PaintedLayerAttributes(GetValidRegion());
89   }
90 
ClientManager()91   ClientLayerManager* ClientManager() {
92     return static_cast<ClientLayerManager*>(mManager);
93   }
94 
AsLayer()95   Layer* AsLayer() override { return this; }
AsShadowableLayer()96   ShadowableLayer* AsShadowableLayer() override { return this; }
97 
GetCompositableClient()98   CompositableClient* GetCompositableClient() override {
99     return mContentClient;
100   }
101 
Disconnect()102   void Disconnect() override { mContentClient = nullptr; }
103 
104  protected:
105   void RecordThebes();
106   bool HasMaskLayers();
107   bool EnsureContentClient();
108   uint32_t GetPaintFlags(ReadbackProcessor* aReadback);
109   void UpdateContentClient(PaintState& aState);
110   bool UpdatePaintRegion(PaintState& aState);
111   void FinishPaintState(PaintState& aState);
112 
113   void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
114 
DestroyBackBuffer()115   void DestroyBackBuffer() { mContentClient = nullptr; }
116 
117   RefPtr<ContentClient> mContentClient;
118 };
119 
120 }  // namespace layers
121 }  // namespace mozilla
122 
123 #endif
124