| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 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> |
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 22 | #include <ui/Fence.h> |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 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 { |
| Alec Mouri | 539319f | 2018-12-19 17:56:23 -0800 | [diff] [blame] | 35 | // 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 Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 45 | // 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 Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 48 | sp<GraphicBuffer> buffer = nullptr; |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 49 | |
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 50 | // Fence that will fire when the buffer is ready to be bound. |
| 51 | sp<Fence> fence = nullptr; |
| 52 | |
| Alec Mouri | 539319f | 2018-12-19 17:56:23 -0800 | [diff] [blame] | 53 | // Caching hint to use when uploading buffer contents. |
| 54 | CachingHint cacheHint = CachingHint::NO_CACHE; |
| 55 | |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 56 | // Texture identifier to bind the external texture to. |
| 57 | // TODO(alecmouri): This is GL-specific...make the type backend-agnostic. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 58 | uint32_t textureName = 0; |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 59 | |
| 60 | // Whether to use filtering when rendering the texture. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 61 | bool useTextureFiltering = false; |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 62 | |
| 63 | // Transform matrix to apply to texture coordinates. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 64 | mat4 textureTransform = mat4(); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 65 | |
| 66 | // Wheteher to use pre-multiplied alpha |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 67 | bool usePremultipliedAlpha = true; |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 68 | |
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 69 | // 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 Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 74 | // HDR color-space setting for Y410. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 75 | bool isY410BT2020 = false; |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | // Metadata describing the layer geometry. |
| 79 | struct Geometry { |
| 80 | // Boundaries of the layer. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 81 | FloatRect boundaries = FloatRect(); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 82 | |
| 83 | // Transform matrix to apply to mesh coordinates. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 84 | mat4 positionTransform = mat4(); |
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 85 | |
| 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 Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | // Descriptor of the source pixels for this layer. |
| 102 | struct PixelSource { |
| 103 | // Source buffer |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 104 | Buffer buffer = Buffer(); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 105 | |
| 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 Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 109 | half3 solidColor = half3(0.0f, 0.0f, 0.0f); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | // The settings that RenderEngine requires for correctly rendering a Layer. |
| 113 | struct LayerSettings { |
| 114 | // Geometry information |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 115 | Geometry geometry = Geometry(); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 116 | |
| 117 | // Source pixels for this layer. |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 118 | PixelSource source = PixelSource(); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 119 | |
| Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 120 | // Alpha option to blend with the source pixels |
| Alec Mouri | 1441bf7 | 2018-12-03 19:55:28 -0800 | [diff] [blame] | 121 | half alpha = half(0.0); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 122 | |
| 123 | // Color space describing how the source pixels should be interpreted. |
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 124 | ui::Dataspace sourceDataspace = ui::Dataspace::UNKNOWN; |
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 125 | |
| 126 | // Additional layer-specific color transform to be applied before the global |
| 127 | // transform. |
| Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 128 | mat4 colorTransform = mat4(); |
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | } // namespace renderengine |
| 132 | } // namespace android |