Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #ifndef GFX_CLIENTTILEDPAINTEDLAYER_H
6 : #define GFX_CLIENTTILEDPAINTEDLAYER_H
7 :
8 : #include "ClientLayerManager.h" // for ClientLayer, etc
9 : #include "Layers.h" // for PaintedLayer, etc
10 : #include "mozilla/RefPtr.h" // for RefPtr
11 : #include "mozilla/layers/TiledContentClient.h"
12 : #include "nsDebug.h" // for NS_RUNTIMEABORT
13 : #include "nsRegion.h" // for nsIntRegion
14 :
15 : namespace mozilla {
16 : namespace layers {
17 :
18 : class ShadowableLayer;
19 : class SpecificLayerAttributes;
20 :
21 : /**
22 : * An implementation of PaintedLayer that ONLY supports remote
23 : * composition that is backed by tiles. This painted layer implementation
24 : * is better suited to mobile hardware to work around slow implementation
25 : * of glTexImage2D (for OGL compositors), and restrait memory bandwidth.
26 : *
27 : * Tiled PaintedLayers use a different protocol compared with other
28 : * layers. A copy of the tiled buffer is made and sent to the compositing
29 : * thread via the layers protocol. Tiles are uploaded by the buffers
30 : * asynchonously without using IPC, that means they are not safe for cross-
31 : * process use (bug 747811). Each tile has a TextureHost/Client pair but
32 : * they communicate directly rather than using the Texture protocol.
33 : *
34 : * There is no ContentClient for tiled layers. There is a ContentHost, however.
35 : */
36 : class ClientTiledPaintedLayer : public PaintedLayer,
37 : public ClientLayer
38 : {
39 : typedef PaintedLayer Base;
40 :
41 : public:
42 : explicit ClientTiledPaintedLayer(ClientLayerManager* const aManager,
43 : ClientLayerManager::PaintedLayerCreationHint aCreationHint = LayerManager::NONE);
44 :
45 : protected:
46 : ~ClientTiledPaintedLayer();
47 :
48 : virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
49 :
50 : public:
51 : // Override name to distinguish it from ClientPaintedLayer in layer dumps
52 0 : virtual const char* Name() const override { return "TiledPaintedLayer"; }
53 :
54 : // PaintedLayer
55 0 : virtual Layer* AsLayer() override { return this; }
56 0 : virtual void InvalidateRegion(const nsIntRegion& aRegion) override {
57 0 : mInvalidRegion.Add(aRegion);
58 0 : UpdateValidRegionAfterInvalidRegionChanged();
59 0 : if (!mLowPrecisionValidRegion.IsEmpty()) {
60 : // Also update mLowPrecisionValidRegion. Unfortunately we call
61 : // mInvalidRegion.GetRegion() here, which is expensive.
62 0 : mLowPrecisionValidRegion.SubOut(mInvalidRegion.GetRegion());
63 : }
64 0 : }
65 :
66 : // Shadow methods
67 : virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) override;
68 0 : virtual ShadowableLayer* AsShadowableLayer() override { return this; }
69 :
70 : virtual void RenderLayer() override;
71 :
72 : virtual void ClearCachedResources() override;
73 :
74 0 : virtual void HandleMemoryPressure() override
75 : {
76 0 : if (mContentClient) {
77 0 : mContentClient->HandleMemoryPressure();
78 : }
79 0 : }
80 :
81 : /**
82 : * Helper method to find the nearest ancestor layers which
83 : * scroll and have a displayport. The parameters are out-params
84 : * which hold the return values; the values passed in may be null.
85 : */
86 : void GetAncestorLayers(LayerMetricsWrapper* aOutScrollAncestor,
87 : LayerMetricsWrapper* aOutDisplayPortAncestor,
88 : bool* aOutHasTransformAnimation);
89 :
90 : virtual bool IsOptimizedFor(LayerManager::PaintedLayerCreationHint aCreationHint) override;
91 :
92 : private:
93 0 : ClientLayerManager* ClientManager()
94 : {
95 0 : return static_cast<ClientLayerManager*>(mManager);
96 : }
97 :
98 : /**
99 : * For the initial PaintThebes of a transaction, calculates all the data
100 : * needed for that paint and any repeated transactions.
101 : */
102 : void BeginPaint();
103 :
104 : /**
105 : * Check if the layer is being scrolled by APZ on the compositor.
106 : */
107 : bool IsScrollingOnCompositor(const FrameMetrics& aParentMetrics);
108 :
109 : /**
110 : * Check if we should use progressive draw on this layer. We will
111 : * disable progressive draw based on a preference or if the layer
112 : * is not being scrolled.
113 : */
114 : bool UseProgressiveDraw();
115 :
116 : /**
117 : * Helper function to do the high-precision paint.
118 : * This function returns true if it updated the paint buffer.
119 : */
120 : bool RenderHighPrecision(const nsIntRegion& aInvalidRegion,
121 : const nsIntRegion& aVisibleRegion,
122 : LayerManager::DrawPaintedLayerCallback aCallback,
123 : void* aCallbackData);
124 :
125 : /**
126 : * Helper function to do the low-precision paint.
127 : * This function returns true if it updated the paint buffer.
128 : */
129 : bool RenderLowPrecision(const nsIntRegion& aInvalidRegion,
130 : const nsIntRegion& aVisibleRegion,
131 : LayerManager::DrawPaintedLayerCallback aCallback,
132 : void* aCallbackData);
133 :
134 : /**
135 : * This causes the paint to be marked as finished, and updates any data
136 : * necessary to persist until the next paint.
137 : */
138 : void EndPaint();
139 :
140 : RefPtr<TiledContentClient> mContentClient;
141 : // Flag to indicate if mContentClient is a SingleTiledContentClient. This is
142 : // only valid when mContentClient is non-null.
143 : bool mHaveSingleTiledContentClient;
144 : nsIntRegion mLowPrecisionValidRegion;
145 : BasicTiledLayerPaintData mPaintData;
146 : };
147 :
148 : } // namespace layers
149 : } // namespace mozilla
150 :
151 : #endif
|