Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/mlgpu/ShaderDefinitionsMLGPU.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_SHADERDEFINITIONSMLGPU_H
8
#define MOZILLA_GFX_SHADERDEFINITIONSMLGPU_H
9
10
#include "mozilla/gfx/Point.h"
11
#include "mozilla/gfx/Triangle.h"
12
#include "mozilla/gfx/Types.h"
13
#include "mozilla/layers/LayersHelpers.h"
14
#include "nsTArray.h"
15
16
namespace mozilla {
17
namespace layers {
18
19
struct ItemInfo;
20
class ShaderRenderPass;
21
22
namespace mlg {
23
24
// These may need to move into run-time values determined by MLGDevice.
25
static const size_t kConstantBufferElementSize = 16;
26
static const size_t kMaxConstantBufferSize = 4096 * kConstantBufferElementSize;
27
28
// Vertex shader slots. We reverse the first two slots across all shaders,
29
// and the first three slots free across all RenderPass shaders, for
30
// uniformity.
31
static const uint32_t kWorldConstantBufferSlot = 0;
32
static const uint32_t kLayerBufferSlot = 1;
33
static const uint32_t kMaskBufferSlot = 3;
34
static const uint32_t kBlendConstantBufferSlot = 4;
35
static const uint32_t kClearConstantBufferSlot = 2;
36
37
// This is specified in common-ps.hlsl.
38
static const uint32_t kMaskLayerTextureSlot = 4;
39
static const uint32_t kDefaultSamplerSlot = 0;
40
static const uint32_t kMaskSamplerSlot = 1;
41
42
// These are the maximum slot numbers we bind. We assert that no binding
43
// happens above the max slot, since we try to clear buffer bindings at
44
// the end of each frame.
45
static const uint32_t kMaxVertexShaderConstantBuffers = 5;
46
static const uint32_t kMaxPixelShaderConstantBuffers = 2;
47
48
// Maximum depth in the depth buffer. This must match common-vs.hlsl.
49
static const int32_t kDepthLimit = 1000000;
50
51
struct WorldConstants
52
{
53
  float projection[4][4];
54
  gfx::Point targetOffset;
55
  int sortIndexOffset;
56
  unsigned debugFrameNumber;
57
};
58
59
struct ClearConstants
60
{
61
  explicit ClearConstants(int aDepth) : depth(aDepth)
62
0
  {}
63
  int depth;
64
  int padding[3];
65
};
66
67
struct LayerConstants
68
{
69
  float transform[4][4];
70
  gfx::Rect clipRect;
71
  uint32_t maskIndex;
72
  uint32_t padding[3];
73
};
74
75
struct MaskCombineInput
76
{
77
  float texCoords[4];
78
};
79
80
struct MaskInformation
81
{
82
  MaskInformation(float aOpacity, bool aHasMask)
83
   : opacity(aOpacity),
84
     hasMask(aHasMask ? 1 : 0)
85
0
  {}
86
  float opacity;
87
  uint32_t hasMask;
88
  uint32_t padding[2];
89
};
90
91
struct YCbCrShaderConstants {
92
  float yuvColorMatrix[3][4];
93
};
94
95
struct BlendVertexShaderConstants {
96
  float backdropTransform[4][4];
97
};
98
99
template <typename T>
100
static inline nsTArray<gfx::IntRect>
101
ToRectArray(const T& aRegion)
102
0
{
103
0
  nsTArray<gfx::IntRect> rects;
104
0
  for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
105
0
    rects.AppendElement(iter.Get().ToUnknownRect());
106
0
  }
107
0
  return rects;
108
0
}
Unexecuted instantiation: Unified_cpp_gfx_layers10.cpp:nsTArray<mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> > mozilla::layers::mlg::ToRectArray<mozilla::gfx::IntRegionTyped<mozilla::LayerPixel> >(mozilla::gfx::IntRegionTyped<mozilla::LayerPixel> const&)
Unexecuted instantiation: Unified_cpp_gfx_layers10.cpp:nsTArray<mozilla::gfx::IntRectTyped<mozilla::gfx::UnknownUnits> > mozilla::layers::mlg::ToRectArray<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> >(mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> const&)
109
110
struct SimpleTraits
111
{
112
  explicit SimpleTraits(const ItemInfo& aItem, const gfx::Rect& aRect)
113
   : mItem(aItem),
114
     mRect(aRect)
115
0
  {}
116
117
  // Helper nonce structs so functions can break vertex data up by each
118
  // triangle in a quad, or return vertex info for a unit quad.
119
  struct AnyTriangle { };
120
  struct FirstTriangle : AnyTriangle { };
121
  struct SecondTriangle : AnyTriangle { };
122
  struct UnitQuad { };
123
124
  // This is the base vertex layout used by all unit quad shaders.
125
  struct UnitQuadVertex {
126
    gfx::Rect rect;
127
    uint32_t layerIndex;
128
    int depth;
129
  };
130
131
  // This is the base vertex layout used by all unit triangle shaders.
132
  struct TriangleVertices {
133
    gfx::Point p1, p2, p3;
134
    uint32_t layerIndex;
135
    int depth;
136
  };
137
138
  // Helper functions for populating a TriangleVertices. The first two use mRect
139
  // to generate triangles, the third function uses coordinates from an already
140
  // computed triangle.
141
  TriangleVertices MakeVertex(const FirstTriangle& aIgnore) const;
142
  TriangleVertices MakeVertex(const SecondTriangle& aIgnore) const;
143
  TriangleVertices MakeVertex(const gfx::Triangle& aTriangle) const;
144
145
  UnitQuadVertex MakeUnitQuadVertex() const;
146
147
  // This default GenerateTriangles only computes the 3 points of each triangle
148
  // in the polygon. If needed, shaders can override this and return a more
149
  // complex triangle, to encode dependent information in extended vertex data.
150
  //
151
  // AddShaderVertices will deduce this return type. It should be an nsTArray<T>
152
  // where T inherits from Triangle.
153
  nsTArray<gfx::Triangle> GenerateTriangles(const gfx::Polygon& aPolygon) const;
154
155
  // Accessors.
156
  const Maybe<gfx::Polygon>& geometry() const;
157
0
  const gfx::Rect& rect() const {
158
0
    return mRect;
159
0
  }
160
161
  const ItemInfo& mItem;
162
  gfx::Rect mRect;
163
};
164
165
struct ColorTraits : public SimpleTraits
166
{
167
  ColorTraits(const ItemInfo& aItem, const gfx::Rect& aRect, const gfx::Color& aColor)
168
   : SimpleTraits(aItem, aRect), mColor(aColor)
169
0
  {}
170
171
  // Color data is the same across all vertex types.
172
  template <typename VertexType>
173
0
  const gfx::Color& MakeVertexData(const VertexType& aIgnore) const {
174
0
    return mColor;
175
0
  }
Unexecuted instantiation: mozilla::gfx::Color const& mozilla::layers::mlg::ColorTraits::MakeVertexData<mozilla::layers::mlg::SimpleTraits::FirstTriangle>(mozilla::layers::mlg::SimpleTraits::FirstTriangle const&) const
Unexecuted instantiation: mozilla::gfx::Color const& mozilla::layers::mlg::ColorTraits::MakeVertexData<mozilla::layers::mlg::SimpleTraits::SecondTriangle>(mozilla::layers::mlg::SimpleTraits::SecondTriangle const&) const
Unexecuted instantiation: mozilla::gfx::Color const& mozilla::layers::mlg::ColorTraits::MakeVertexData<mozilla::gfx::TriangleTyped<mozilla::gfx::UnknownUnits, float> >(mozilla::gfx::TriangleTyped<mozilla::gfx::UnknownUnits, float> const&) const
Unexecuted instantiation: mozilla::gfx::Color const& mozilla::layers::mlg::ColorTraits::MakeVertexData<mozilla::layers::mlg::SimpleTraits::UnitQuad>(mozilla::layers::mlg::SimpleTraits::UnitQuad const&) const
176
177
  gfx::Color mColor;
178
};
179
180
struct TexturedTraits : public SimpleTraits
181
{
182
  TexturedTraits(const ItemInfo& aItem, const gfx::Rect& aRect, const gfx::Rect& aTexCoords)
183
   : SimpleTraits(aItem, aRect), mTexCoords(aTexCoords)
184
0
  {}
185
186
  // Textured triangles need to compute a texture coordinate for each vertex.
187
  nsTArray<gfx::TexturedTriangle> GenerateTriangles(const gfx::Polygon& aPolygon) const;
188
189
  struct VertexData {
190
    gfx::Point p1, p2, p3;
191
  };
192
  VertexData MakeVertexData(const FirstTriangle& aIgnore) const;
193
  VertexData MakeVertexData(const SecondTriangle& aIgnore) const;
194
  VertexData MakeVertexData(const gfx::TexturedTriangle& aTriangle) const;
195
0
  const gfx::Rect& MakeVertexData(const UnitQuad& aIgnore) const {
196
0
    return mTexCoords;
197
0
  }
198
199
  gfx::Rect mTexCoords;
200
};
201
202
} // namespace mlg
203
} // namespace layers
204
} // namespace mozilla
205
206
#endif