Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 17 | #pragma once |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 18 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 19 | #include <utils/RefBase.h> |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 20 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 21 | #include <SkBlendMode.h> |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 22 | #include <SkColorFilter.h> |
| 23 | #include <SkColorSpace.h> |
Nader Jawad | 55f1976 | 2020-11-25 15:30:20 -0800 | [diff] [blame] | 24 | #include <SkCanvas.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 25 | #include <SkPaint.h> |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 26 | #include <SkImage.h> |
| 27 | #include <SkMatrix.h> |
| 28 | #include <system/graphics.h> |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 33 | /////////////////////////////////////////////////////////////////////////////// |
| 34 | // Layers |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 36 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 37 | class RenderState; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 38 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 39 | /** |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 40 | * A layer has dimensions and is backed by a backend specific texture or framebuffer. |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 41 | */ |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 42 | class Layer : public VirtualLightRefBase { |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 43 | public: |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 44 | Layer(RenderState& renderState, sk_sp<SkColorFilter>, int alpha, SkBlendMode mode); |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 45 | |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 46 | ~Layer(); |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 47 | |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 48 | uint32_t getWidth() const { return mWidth; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 49 | |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 50 | uint32_t getHeight() const { return mHeight; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 51 | |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 52 | void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 53 | |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 54 | void setBlend(bool blend) { mBlend = blend; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 55 | |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 56 | bool isBlend() const { return mBlend; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 57 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 58 | inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; } |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 59 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 60 | inline bool getForceFilter() const { return forceFilter; } |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 61 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 62 | inline void setAlpha(int alpha) { this->alpha = alpha; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 63 | |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 64 | inline void setAlpha(int alpha, SkBlendMode mode) { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 65 | this->alpha = alpha; |
| 66 | this->mode = mode; |
| 67 | } |
| 68 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 69 | inline int getAlpha() const { return alpha; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 70 | |
Stan Iliev | 8fc3d8e | 2018-09-28 18:44:26 -0400 | [diff] [blame] | 71 | SkBlendMode getMode() const; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 72 | |
Derek Sollenberger | d01b591 | 2018-10-19 15:55:33 -0400 | [diff] [blame] | 73 | inline sk_sp<SkColorFilter> getColorFilter() const { return mColorFilter; } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 74 | |
Derek Sollenberger | d01b591 | 2018-10-19 15:55:33 -0400 | [diff] [blame] | 75 | void setColorFilter(sk_sp<SkColorFilter> filter) { mColorFilter = filter; }; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 76 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 77 | inline SkMatrix& getTransform() { return transform; } |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 78 | |
ramindani | 3952ed6 | 2021-08-12 15:55:12 +0000 | [diff] [blame] | 79 | inline SkRect getCurrentCropRect() { return mCurrentCropRect; } |
| 80 | |
| 81 | inline void setCurrentCropRect(const SkRect currentCropRect) { |
| 82 | mCurrentCropRect = currentCropRect; |
| 83 | } |
| 84 | |
| 85 | inline void setWindowTransform(uint32_t windowTransform) { mWindowTransform = windowTransform; } |
| 86 | |
| 87 | inline uint32_t getWindowTransform() { return mWindowTransform; } |
| 88 | |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 89 | /** |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 90 | * Posts a decStrong call to the appropriate thread. |
| 91 | * Thread-safe. |
| 92 | */ |
| 93 | void postDecStrong(); |
| 94 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 95 | inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; } |
| 96 | |
| 97 | inline sk_sp<SkImage> getImage() const { return this->layerImage; } |
| 98 | |
Alec Mouri | d0001fe | 2021-11-22 10:09:22 -0800 | [diff] [blame] | 99 | inline void setMaxLuminanceNits(float maxLuminanceNits) { |
| 100 | mMaxLuminanceNits = maxLuminanceNits; |
| 101 | } |
| 102 | |
| 103 | inline float getMaxLuminanceNits() { return mMaxLuminanceNits; } |
| 104 | |
John Reck | 8df7f3c | 2022-09-29 13:19:54 -0400 | [diff] [blame] | 105 | void setBufferFormat(uint32_t format) { mBufferFormat = format; } |
| 106 | |
| 107 | uint32_t getBufferFormat() const { return mBufferFormat; } |
| 108 | |
Nader Jawad | 55f1976 | 2020-11-25 15:30:20 -0800 | [diff] [blame] | 109 | void draw(SkCanvas* canvas); |
| 110 | |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 111 | protected: |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 112 | |
| 113 | RenderState& mRenderState; |
John Reck | 5799801 | 2015-01-29 10:17:57 -0800 | [diff] [blame] | 114 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 115 | private: |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 116 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 117 | * Color filter used to draw this layer. Optional. |
| 118 | */ |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 119 | sk_sp<SkColorFilter> mColorFilter; |
| 120 | |
| 121 | /** |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 122 | * Indicates raster data backing the layer is scaled, requiring filtration. |
| 123 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 124 | bool forceFilter = false; |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 125 | |
| 126 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 127 | * Opacity of the layer. |
| 128 | */ |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 129 | int alpha; |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 130 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Blending mode of the layer. |
| 133 | */ |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 134 | SkBlendMode mode; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 137 | * Optional transform. |
| 138 | */ |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 139 | SkMatrix transform; |
| 140 | |
| 141 | /** |
ramindani | 3952ed6 | 2021-08-12 15:55:12 +0000 | [diff] [blame] | 142 | * Optional crop |
| 143 | */ |
| 144 | SkRect mCurrentCropRect; |
| 145 | |
| 146 | /** |
| 147 | * Optional transform |
| 148 | */ |
| 149 | uint32_t mWindowTransform; |
| 150 | |
| 151 | /** |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 152 | * An image backing the layer. |
| 153 | */ |
| 154 | sk_sp<SkImage> layerImage; |
| 155 | |
| 156 | /** |
| 157 | * layer width. |
| 158 | */ |
| 159 | uint32_t mWidth = 0; |
| 160 | |
| 161 | /** |
| 162 | * layer height. |
| 163 | */ |
| 164 | uint32_t mHeight = 0; |
| 165 | |
| 166 | /** |
| 167 | * enable blending |
| 168 | */ |
| 169 | bool mBlend = false; |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 170 | |
Alec Mouri | d0001fe | 2021-11-22 10:09:22 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Max input luminance if the layer is HDR |
| 173 | */ |
| 174 | float mMaxLuminanceNits = -1; |
| 175 | |
John Reck | 8df7f3c | 2022-09-29 13:19:54 -0400 | [diff] [blame] | 176 | uint32_t mBufferFormat = 0; |
| 177 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 178 | }; // struct Layer |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 179 | |
Chris Blume | 7b8a808 | 2018-11-30 15:51:58 -0800 | [diff] [blame] | 180 | } // namespace uirenderer |
| 181 | } // namespace android |