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_CLIENTCANVASLAYER_H
7 : #define GFX_CLIENTCANVASLAYER_H
8 :
9 : #include "CanvasClient.h" // for CanvasClient, etc
10 : #include "ClientLayerManager.h" // for ClientLayerManager, etc
11 : #include "Layers.h" // for CanvasLayer, etc
12 : #include "mozilla/Attributes.h" // for override
13 : #include "mozilla/layers/LayersMessages.h" // for CanvasLayerAttributes, etc
14 : #include "mozilla/mozalloc.h" // for operator delete
15 : #include "nsDebug.h" // for NS_ASSERTION
16 : #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
17 : #include "ShareableCanvasLayer.h"
18 :
19 : namespace mozilla {
20 : namespace layers {
21 :
22 : class CompositableClient;
23 : class ShadowableLayer;
24 :
25 : class ClientCanvasLayer : public ShareableCanvasLayer,
26 : public ClientLayer
27 : {
28 : public:
29 0 : explicit ClientCanvasLayer(ClientLayerManager* aLayerManager) :
30 0 : ShareableCanvasLayer(aLayerManager, static_cast<ClientLayer*>(this))
31 : {
32 0 : MOZ_COUNT_CTOR(ClientCanvasLayer);
33 0 : }
34 :
35 : protected:
36 : virtual ~ClientCanvasLayer();
37 :
38 : public:
39 0 : virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
40 : {
41 0 : NS_ASSERTION(ClientManager()->InConstruction(),
42 : "Can only set properties in construction phase");
43 0 : CanvasLayer::SetVisibleRegion(aRegion);
44 0 : }
45 :
46 : virtual void RenderLayer() override;
47 :
48 0 : virtual void ClearCachedResources() override
49 : {
50 0 : if (mBufferProvider) {
51 0 : mBufferProvider->ClearCachedResources();
52 : }
53 0 : if (mCanvasClient) {
54 0 : mCanvasClient->Clear();
55 : }
56 0 : }
57 :
58 0 : virtual void HandleMemoryPressure() override
59 : {
60 0 : if (mBufferProvider) {
61 0 : mBufferProvider->ClearCachedResources();
62 : }
63 0 : if (mCanvasClient) {
64 0 : mCanvasClient->HandleMemoryPressure();
65 : }
66 0 : }
67 :
68 0 : virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) override
69 : {
70 0 : aAttrs = CanvasLayerAttributes(mSamplingFilter, mBounds);
71 0 : }
72 :
73 0 : virtual Layer* AsLayer() override { return this; }
74 0 : virtual ShadowableLayer* AsShadowableLayer() override { return this; }
75 :
76 0 : virtual void Disconnect() override
77 : {
78 0 : if (mBufferProvider) {
79 0 : mBufferProvider->ClearCachedResources();
80 : }
81 0 : mCanvasClient = nullptr;
82 0 : }
83 :
84 0 : virtual CompositableForwarder* GetForwarder() override
85 : {
86 0 : return mManager->AsShadowForwarder();
87 : }
88 :
89 0 : virtual CompositableClient* GetCompositableClient() override
90 : {
91 0 : return mCanvasClient;
92 : }
93 :
94 0 : virtual void AttachCompositable() override
95 : {
96 0 : if (HasShadow()) {
97 0 : if (mAsyncRenderer) {
98 0 : static_cast<CanvasClientBridge*>(mCanvasClient.get())->SetLayer(this);
99 : } else {
100 0 : mCanvasClient->Connect();
101 0 : ClientManager()->AsShadowForwarder()->Attach(mCanvasClient, this);
102 : }
103 : }
104 0 : }
105 :
106 : protected:
107 0 : ClientLayerManager* ClientManager()
108 : {
109 0 : return static_cast<ClientLayerManager*>(mManager);
110 : }
111 : };
112 :
113 : } // namespace layers
114 : } // namespace mozilla
115 :
116 : #endif
|