blob: 56ac71416a8b2eb2c824fe2fc15e0d29a07de12a [file] [log] [blame]
Alec Mouri6e57f682018-09-29 20:45:08 -07001/*
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>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080022#include <ui/Fence.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070023#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
30namespace android {
31namespace renderengine {
32
33// Metadata describing the input buffer to render from.
34struct Buffer {
Alec Mouri539319f2018-12-19 17:56:23 -080035 // Hint for whether to use the Image cache or not.
36 // If NO_CACHE is specified, then upload the contents of the GraphicBuffer
37 // to the GPU, without checking against any implementation defined cache.
38 // If USE_CACHE is specified, then check against an implementation defined
39 // cache first. If there is an Image cached for the given GraphicBuffer id,
40 // then use that instead of the provided buffer contents. If there is no
41 // cached image or the RenderEngine implementation does not support caching,
42 // then use the GraphicBuffer contents.
43 enum class CachingHint { NO_CACHE, USE_CACHE };
44
Alec Mouri6e57f682018-09-29 20:45:08 -070045 // Buffer containing the image that we will render.
46 // If buffer == nullptr, then the rest of the fields in this struct will be
47 // ignored.
Alec Mouri1441bf72018-12-03 19:55:28 -080048 sp<GraphicBuffer> buffer = nullptr;
Alec Mouri6e57f682018-09-29 20:45:08 -070049
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080050 // Fence that will fire when the buffer is ready to be bound.
51 sp<Fence> fence = nullptr;
52
Alec Mouri539319f2018-12-19 17:56:23 -080053 // Caching hint to use when uploading buffer contents.
54 CachingHint cacheHint = CachingHint::NO_CACHE;
55
Alec Mouri6e57f682018-09-29 20:45:08 -070056 // Texture identifier to bind the external texture to.
57 // TODO(alecmouri): This is GL-specific...make the type backend-agnostic.
Alec Mouri1441bf72018-12-03 19:55:28 -080058 uint32_t textureName = 0;
Alec Mouri6e57f682018-09-29 20:45:08 -070059
60 // Whether to use filtering when rendering the texture.
Alec Mouri1441bf72018-12-03 19:55:28 -080061 bool useTextureFiltering = false;
Alec Mouri6e57f682018-09-29 20:45:08 -070062
63 // Transform matrix to apply to texture coordinates.
Alec Mouri1441bf72018-12-03 19:55:28 -080064 mat4 textureTransform = mat4();
Alec Mouri6e57f682018-09-29 20:45:08 -070065
66 // Wheteher to use pre-multiplied alpha
Alec Mouri1441bf72018-12-03 19:55:28 -080067 bool usePremultipliedAlpha = true;
Alec Mouri6e57f682018-09-29 20:45:08 -070068
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080069 // Override flag that alpha for each pixel in the buffer *must* be 1.0.
70 // LayerSettings::alpha is still used if isOpaque==true - this flag only
71 // overrides the alpha channel of the buffer.
72 bool isOpaque = false;
73
Alec Mouri6e57f682018-09-29 20:45:08 -070074 // HDR color-space setting for Y410.
Alec Mouri1441bf72018-12-03 19:55:28 -080075 bool isY410BT2020 = false;
Alec Mouri6e57f682018-09-29 20:45:08 -070076};
77
78// Metadata describing the layer geometry.
79struct Geometry {
80 // Boundaries of the layer.
Alec Mouri1441bf72018-12-03 19:55:28 -080081 FloatRect boundaries = FloatRect();
Alec Mouri6e57f682018-09-29 20:45:08 -070082
83 // Transform matrix to apply to mesh coordinates.
Alec Mouri1441bf72018-12-03 19:55:28 -080084 mat4 positionTransform = mat4();
Alec Mouri7c94edb2018-12-03 21:23:26 -080085
86 // Radius of rounded corners, if greater than 0. Otherwise, this layer's
87 // corners are not rounded.
88 // Having corner radius will force GPU composition on the layer and its children, drawing it
89 // with a special shader. The shader will receive the radius and the crop rectangle as input,
90 // modifying the opacity of the destination texture, multiplying it by a number between 0 and 1.
91 // We query Layer#getRoundedCornerState() to retrieve the radius as well as the rounded crop
92 // rectangle to figure out how to apply the radius for this layer. The crop rectangle will be
93 // in local layer coordinate space, so we have to take the layer transform into account when
94 // walking up the tree.
95 float roundedCornersRadius = 0.0;
96
97 // Rectangle within which corners will be rounded.
98 FloatRect roundedCornersCrop = FloatRect();
Alec Mouri6e57f682018-09-29 20:45:08 -070099};
100
101// Descriptor of the source pixels for this layer.
102struct PixelSource {
103 // Source buffer
Alec Mouri1441bf72018-12-03 19:55:28 -0800104 Buffer buffer = Buffer();
Alec Mouri6e57f682018-09-29 20:45:08 -0700105
106 // The solid color with which to fill the layer.
107 // This should only be populated if we don't render from an application
108 // buffer.
Alec Mouri1441bf72018-12-03 19:55:28 -0800109 half3 solidColor = half3(0.0f, 0.0f, 0.0f);
Alec Mouri6e57f682018-09-29 20:45:08 -0700110};
111
112// The settings that RenderEngine requires for correctly rendering a Layer.
113struct LayerSettings {
114 // Geometry information
Alec Mouri1441bf72018-12-03 19:55:28 -0800115 Geometry geometry = Geometry();
Alec Mouri6e57f682018-09-29 20:45:08 -0700116
117 // Source pixels for this layer.
Alec Mouri1441bf72018-12-03 19:55:28 -0800118 PixelSource source = PixelSource();
Alec Mouri6e57f682018-09-29 20:45:08 -0700119
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800120 // Alpha option to blend with the source pixels
Alec Mouri1441bf72018-12-03 19:55:28 -0800121 half alpha = half(0.0);
Alec Mouri6e57f682018-09-29 20:45:08 -0700122
123 // Color space describing how the source pixels should be interpreted.
Alec Mouriac335532018-11-12 15:01:33 -0800124 ui::Dataspace sourceDataspace = ui::Dataspace::UNKNOWN;
Alec Mouri1089aed2018-10-25 21:33:57 -0700125
126 // Additional layer-specific color transform to be applied before the global
127 // transform.
Alec Mouriac335532018-11-12 15:01:33 -0800128 mat4 colorTransform = mat4();
Alec Mouri6e57f682018-09-29 20:45:08 -0700129};
130
131} // namespace renderengine
132} // namespace android