Coverage Report

Created: 2018-09-25 14:53

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