Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/mlgpu/FrameBuilder.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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_gfx_layers_mlgpu_FrameBuilder_h
8
#define mozilla_gfx_layers_mlgpu_FrameBuilder_h
9
10
#include "mozilla/RefPtr.h"
11
#include "mozilla/gfx/Point.h"
12
#include "mozilla/gfx/Types.h"
13
#include "MaskOperation.h"
14
#include "MLGDevice.h"
15
#include "nsDataHashtable.h"
16
#include "nsRefPtrHashtable.h"
17
#include "ShaderDefinitionsMLGPU.h"
18
#include "SharedBufferMLGPU.h"
19
#include "Units.h"
20
#include <map>
21
#include <vector>
22
23
namespace mozilla {
24
namespace layers {
25
26
class ContainerLayer;
27
class ContainerLayerMLGPU;
28
class Layer;
29
class LayerMLGPU;
30
class LayerManagerMLGPU;
31
class MLGDevice;
32
class MLGRenderTarget;
33
class MLGSwapChain;
34
class RenderViewMLGPU;
35
struct ItemInfo;
36
37
class FrameBuilder final
38
{
39
public:
40
  FrameBuilder(LayerManagerMLGPU* aManager, MLGSwapChain* aSwapChain);
41
  ~FrameBuilder();
42
43
  bool Build();
44
  void Render();
45
46
  bool AddLayerToConstantBuffer(ItemInfo& aItem);
47
48
0
  LayerManagerMLGPU* GetManager() const {
49
0
    return mManager;
50
0
  }
51
0
  MLGDevice* GetDevice() const {
52
0
    return mDevice;
53
0
  }
54
0
  const ConstantBufferSection& GetDefaultMaskInfo() const {
55
0
    return mDefaultMaskInfo;
56
0
  }
57
58
  // Called during tile construction. Finds or adds a mask layer chain to the
59
  // cache, that will be flattened as a dependency to rendering batches.
60
  MaskOperation* AddMaskOperation(LayerMLGPU* aLayer);
61
62
  // Note: These should only be called during batch construction.
63
  size_t CurrentLayerBufferIndex() const;
64
  size_t CurrentMaskRectBufferIndex() const;
65
66
  // These are called during rendering, and may return null if a buffer
67
  // couldn't be allocated.
68
  ConstantBufferSection GetLayerBufferByIndex(size_t aIndex) const;
69
  ConstantBufferSection GetMaskRectBufferByIndex(size_t aIndex) const;
70
71
  // Hold a layer alive until the frame ends.
72
  void RetainTemporaryLayer(LayerMLGPU* aLayer);
73
74
private:
75
  void AssignLayer(Layer* aLayer,
76
                   RenderViewMLGPU* aView,
77
                   const RenderTargetIntRect& aClipRect,
78
                   Maybe<gfx::Polygon>&& aGeometry);
79
80
  void ProcessChildList(ContainerLayer* aContainer,
81
                        RenderViewMLGPU* aView,
82
                        const RenderTargetIntRect& aParentClipRect,
83
                        const Maybe<gfx::Polygon>& aParentGeometry);
84
85
  mlg::LayerConstants* AllocateLayerInfo(ItemInfo& aItem);
86
  bool AddMaskRect(const gfx::Rect& aRect, uint32_t* aOutIndex);
87
  void FinishCurrentLayerBuffer();
88
  void FinishCurrentMaskRectBuffer();
89
90
  // Returns true to continue, false to stop - false does not indicate
91
  // failure.
92
  bool ProcessContainerLayer(ContainerLayer* aLayer,
93
                             RenderViewMLGPU* aView,
94
                             const RenderTargetIntRect& aClipRect,
95
                             Maybe<gfx::Polygon>& aGeometry);
96
97
private:
98
  RefPtr<LayerManagerMLGPU> mManager;
99
  RefPtr<MLGDevice> mDevice;
100
  RefPtr<MLGSwapChain> mSwapChain;
101
  RefPtr<RenderViewMLGPU> mWidgetRenderView;
102
  LayerMLGPU* mRoot;
103
104
  // Each time we consume a layer in a tile, we make sure a constant buffer
105
  // exists that contains information about the layer. The mapping is valid
106
  // for the most recent buffer, and once the buffer fills, we begin a new
107
  // one and clear the map.
108
  nsTArray<ConstantBufferSection> mLayerBuffers;
109
  nsTArray<mlg::LayerConstants> mCurrentLayerBuffer;
110
  nsDataHashtable<nsPtrHashKey<LayerMLGPU>, uint32_t> mLayerBufferMap;
111
112
  // We keep mask rects in a separate buffer since they're rare.
113
  nsTArray<ConstantBufferSection> mMaskRectBuffers;
114
  nsTArray<gfx::Rect> mCurrentMaskRectList;
115
116
  // For values that *can* change every render pass, but almost certainly do
117
  // not, we pre-fill and cache some buffers.
118
  ConstantBufferSection mDefaultMaskInfo;
119
120
  // Cache for MaskOperations.
121
  nsRefPtrHashtable<nsRefPtrHashKey<TextureSource>, MaskOperation> mSingleTextureMasks;
122
  std::map<MaskTextureList, RefPtr<MaskCombineOperation>> mCombinedTextureMasks;
123
124
  // This list of temporary layers is wiped out when the frame is completed.
125
  std::vector<RefPtr<Layer>> mTemporaryLayers;
126
};
127
128
} // namespace layers
129
} // namespace mozilla
130
131
#endif // mozilla_gfx_layers_mlgpu_FrameBuilder_h