Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GFX_CLIENTPAINTEDLAYER_H
7 : #define GFX_CLIENTPAINTEDLAYER_H
8 :
9 : #include "ClientLayerManager.h" // for ClientLayerManager, etc
10 : #include "Layers.h" // for PaintedLayer, etc
11 : #include "RotatedBuffer.h" // for RotatedContentBuffer, etc
12 : #include "mozilla/Attributes.h" // for override
13 : #include "mozilla/RefPtr.h" // for RefPtr
14 : #include "mozilla/layers/ContentClient.h" // for ContentClient
15 : #include "mozilla/mozalloc.h" // for operator delete
16 : #include "nsDebug.h" // for NS_ASSERTION
17 : #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
18 : #include "nsRegion.h" // for nsIntRegion
19 : #include "mozilla/layers/PLayerTransaction.h" // for PaintedLayerAttributes
20 :
21 : namespace mozilla {
22 : namespace gfx {
23 : class DrawEventRecorderMemory;
24 : class DrawTargetCapture;
25 : };
26 :
27 : namespace layers {
28 : class CompositableClient;
29 : class ShadowableLayer;
30 : class SpecificLayerAttributes;
31 :
32 : class ClientPaintedLayer : public PaintedLayer,
33 : public ClientLayer {
34 : public:
35 : typedef RotatedContentBuffer::PaintState PaintState;
36 : typedef RotatedContentBuffer::ContentType ContentType;
37 :
38 22 : explicit ClientPaintedLayer(ClientLayerManager* aLayerManager,
39 22 : LayerManager::PaintedLayerCreationHint aCreationHint = LayerManager::NONE) :
40 : PaintedLayer(aLayerManager, static_cast<ClientLayer*>(this), aCreationHint),
41 22 : mContentClient(nullptr)
42 : {
43 22 : MOZ_COUNT_CTOR(ClientPaintedLayer);
44 22 : }
45 :
46 : protected:
47 38 : virtual ~ClientPaintedLayer()
48 38 : {
49 19 : if (mContentClient) {
50 19 : mContentClient->OnDetach();
51 19 : mContentClient = nullptr;
52 : }
53 19 : MOZ_COUNT_DTOR(ClientPaintedLayer);
54 57 : }
55 :
56 : public:
57 76 : virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
58 : {
59 76 : NS_ASSERTION(ClientManager()->InConstruction(),
60 : "Can only set properties in construction phase");
61 76 : PaintedLayer::SetVisibleRegion(aRegion);
62 76 : }
63 185 : virtual void InvalidateRegion(const nsIntRegion& aRegion) override
64 : {
65 185 : NS_ASSERTION(ClientManager()->InConstruction(),
66 : "Can only set properties in construction phase");
67 185 : mInvalidRegion.Add(aRegion);
68 185 : UpdateValidRegionAfterInvalidRegionChanged();
69 185 : }
70 :
71 0 : virtual void RenderLayer() override { RenderLayerWithReadback(nullptr); }
72 :
73 : virtual void RenderLayerWithReadback(ReadbackProcessor *aReadback) override;
74 :
75 0 : virtual void ClearCachedResources() override
76 : {
77 0 : if (mContentClient) {
78 0 : mContentClient->Clear();
79 : }
80 0 : ClearValidRegion();
81 0 : DestroyBackBuffer();
82 0 : }
83 :
84 0 : virtual void HandleMemoryPressure() override
85 : {
86 0 : if (mContentClient) {
87 0 : mContentClient->HandleMemoryPressure();
88 : }
89 0 : }
90 :
91 53 : virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) override
92 : {
93 53 : aAttrs = PaintedLayerAttributes(GetValidRegion());
94 53 : }
95 :
96 591 : ClientLayerManager* ClientManager()
97 : {
98 591 : return static_cast<ClientLayerManager*>(mManager);
99 : }
100 :
101 94 : virtual Layer* AsLayer() override { return this; }
102 73 : virtual ShadowableLayer* AsShadowableLayer() override { return this; }
103 :
104 0 : virtual CompositableClient* GetCompositableClient() override
105 : {
106 0 : return mContentClient;
107 : }
108 :
109 0 : virtual void Disconnect() override
110 : {
111 0 : mContentClient = nullptr;
112 0 : }
113 :
114 : protected:
115 : void PaintThebes(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates);
116 : void RecordThebes();
117 : bool CanRecordLayer(ReadbackProcessor* aReadback);
118 : bool HasMaskLayers();
119 : bool EnsureContentClient();
120 : uint32_t GetPaintFlags();
121 : void UpdateContentClient(PaintState& aState);
122 : bool UpdatePaintRegion(PaintState& aState);
123 : void PaintOffMainThread(gfx::DrawTargetCapture* aCapture);
124 : already_AddRefed<gfx::DrawTargetCapture> CapturePaintedContent();
125 :
126 : virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
127 :
128 0 : void DestroyBackBuffer()
129 : {
130 0 : mContentClient = nullptr;
131 0 : }
132 :
133 : RefPtr<ContentClient> mContentClient;
134 : };
135 :
136 : } // namespace layers
137 : } // namespace mozilla
138 :
139 : #endif
|