1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <math/mat4.h>
20 #include <math/vec3.h>
21 #include <renderengine/Texture.h>
22 #include <ui/Fence.h>
23 #include <ui/FloatRect.h>
24 #include <ui/GraphicBuffer.h>
25 #include <ui/GraphicTypes.h>
26 #include <ui/Rect.h>
27 #include <ui/Region.h>
28 #include <ui/Transform.h>
29 
30 namespace android {
31 namespace renderengine {
32 
33 // Metadata describing the input buffer to render from.
34 struct Buffer {
35     // Buffer containing the image that we will render.
36     // If buffer == nullptr, then the rest of the fields in this struct will be
37     // ignored.
38     sp<GraphicBuffer> buffer = nullptr;
39 
40     // Fence that will fire when the buffer is ready to be bound.
41     sp<Fence> fence = nullptr;
42 
43     // Texture identifier to bind the external texture to.
44     // TODO(alecmouri): This is GL-specific...make the type backend-agnostic.
45     uint32_t textureName = 0;
46 
47     // Whether to use filtering when rendering the texture.
48     bool useTextureFiltering = false;
49 
50     // Transform matrix to apply to texture coordinates.
51     mat4 textureTransform = mat4();
52 
53     // Wheteher to use pre-multiplied alpha
54     bool usePremultipliedAlpha = true;
55 
56     // Override flag that alpha for each pixel in the buffer *must* be 1.0.
57     // LayerSettings::alpha is still used if isOpaque==true - this flag only
58     // overrides the alpha channel of the buffer.
59     bool isOpaque = false;
60 
61     // HDR color-space setting for Y410.
62     bool isY410BT2020 = false;
63 };
64 
65 // Metadata describing the layer geometry.
66 struct Geometry {
67     // Boundaries of the layer.
68     FloatRect boundaries = FloatRect();
69 
70     // Transform matrix to apply to mesh coordinates.
71     mat4 positionTransform = mat4();
72 
73     // Radius of rounded corners, if greater than 0. Otherwise, this layer's
74     // corners are not rounded.
75     // Having corner radius will force GPU composition on the layer and its children, drawing it
76     // with a special shader. The shader will receive the radius and the crop rectangle as input,
77     // modifying the opacity of the destination texture, multiplying it by a number between 0 and 1.
78     // We query Layer#getRoundedCornerState() to retrieve the radius as well as the rounded crop
79     // rectangle to figure out how to apply the radius for this layer. The crop rectangle will be
80     // in local layer coordinate space, so we have to take the layer transform into account when
81     // walking up the tree.
82     float roundedCornersRadius = 0.0;
83 
84     // Rectangle within which corners will be rounded.
85     FloatRect roundedCornersCrop = FloatRect();
86 };
87 
88 // Descriptor of the source pixels for this layer.
89 struct PixelSource {
90     // Source buffer
91     Buffer buffer = Buffer();
92 
93     // The solid color with which to fill the layer.
94     // This should only be populated if we don't render from an application
95     // buffer.
96     half3 solidColor = half3(0.0f, 0.0f, 0.0f);
97 };
98 
99 // The settings that RenderEngine requires for correctly rendering a Layer.
100 struct LayerSettings {
101     // Geometry information
102     Geometry geometry = Geometry();
103 
104     // Source pixels for this layer.
105     PixelSource source = PixelSource();
106 
107     // Alpha option to blend with the source pixels
108     half alpha = half(0.0);
109 
110     // Color space describing how the source pixels should be interpreted.
111     ui::Dataspace sourceDataspace = ui::Dataspace::UNKNOWN;
112 
113     // Additional layer-specific color transform to be applied before the global
114     // transform.
115     mat4 colorTransform = mat4();
116 
117     // True if blending will be forced to be disabled.
118     bool disableBlending = false;
119 };
120 
121 } // namespace renderengine
122 } // namespace android
123