blob: 345749b6d9208c6586c6934f57beae0b0c5a3fe9 [file] [log] [blame]
Romain Guydda570202010-07-06 11:39:32 -07001/*
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 Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Romain Guydda570202010-07-06 11:39:32 -070018
John Reck1bcacfd2017-11-03 10:12:19 -070019#include <utils/RefBase.h>
Romain Guydda570202010-07-06 11:39:32 -070020
John Recke170fb62018-05-07 08:12:07 -070021#include <SkBlendMode.h>
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040022#include <SkColorFilter.h>
23#include <SkColorSpace.h>
Nader Jawad55f19762020-11-25 15:30:20 -080024#include <SkCanvas.h>
John Reck1bcacfd2017-11-03 10:12:19 -070025#include <SkPaint.h>
Stan Iliev564ca3e2018-09-04 22:00:00 +000026#include <SkImage.h>
27#include <SkMatrix.h>
28#include <system/graphics.h>
Romain Guydda570202010-07-06 11:39:32 -070029
30namespace android {
31namespace uirenderer {
32
Romain Guy8550c4c2010-10-08 15:49:53 -070033///////////////////////////////////////////////////////////////////////////////
34// Layers
35///////////////////////////////////////////////////////////////////////////////
Romain Guydda570202010-07-06 11:39:32 -070036
John Reck3b202512014-06-23 13:13:08 -070037class RenderState;
Romain Guy2bf68f02012-03-02 13:37:47 -080038
Romain Guydda570202010-07-06 11:39:32 -070039/**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050040 * A layer has dimensions and is backed by a backend specific texture or framebuffer.
Romain Guydda570202010-07-06 11:39:32 -070041 */
Stan Iliev1a025a72018-09-05 16:35:11 -040042class Layer : public VirtualLightRefBase {
Chris Craik564acf72014-01-02 16:46:18 -080043public:
Stan Iliev564ca3e2018-09-04 22:00:00 +000044 Layer(RenderState& renderState, sk_sp<SkColorFilter>, int alpha, SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050045
Chet Haased15ebf22012-09-05 11:40:29 -070046 ~Layer();
Romain Guy8550c4c2010-10-08 15:49:53 -070047
Stan Iliev1a025a72018-09-05 16:35:11 -040048 uint32_t getWidth() const { return mWidth; }
Romain Guy9ace8f52011-07-07 20:50:11 -070049
Stan Iliev1a025a72018-09-05 16:35:11 -040050 uint32_t getHeight() const { return mHeight; }
Romain Guy9ace8f52011-07-07 20:50:11 -070051
Stan Iliev1a025a72018-09-05 16:35:11 -040052 void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; }
Romain Guy9ace8f52011-07-07 20:50:11 -070053
Stan Iliev1a025a72018-09-05 16:35:11 -040054 void setBlend(bool blend) { mBlend = blend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070055
Stan Iliev1a025a72018-09-05 16:35:11 -040056 bool isBlend() const { return mBlend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070057
John Reck1bcacfd2017-11-03 10:12:19 -070058 inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080059
John Reck1bcacfd2017-11-03 10:12:19 -070060 inline bool getForceFilter() const { return forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080061
John Reck1bcacfd2017-11-03 10:12:19 -070062 inline void setAlpha(int alpha) { this->alpha = alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070063
Mike Reed260ab722016-10-07 15:59:20 -040064 inline void setAlpha(int alpha, SkBlendMode mode) {
Romain Guy9ace8f52011-07-07 20:50:11 -070065 this->alpha = alpha;
66 this->mode = mode;
67 }
68
John Reck1bcacfd2017-11-03 10:12:19 -070069 inline int getAlpha() const { return alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070070
Stan Iliev8fc3d8e2018-09-28 18:44:26 -040071 SkBlendMode getMode() const;
Romain Guy9ace8f52011-07-07 20:50:11 -070072
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040073 inline sk_sp<SkColorFilter> getColorFilter() const { return mColorFilter; }
Romain Guy9ace8f52011-07-07 20:50:11 -070074
Derek Sollenbergerd01b5912018-10-19 15:55:33 -040075 void setColorFilter(sk_sp<SkColorFilter> filter) { mColorFilter = filter; };
Romain Guy9ace8f52011-07-07 20:50:11 -070076
Stan Iliev564ca3e2018-09-04 22:00:00 +000077 inline SkMatrix& getTransform() { return transform; }
Romain Guy302a9df2011-08-16 13:55:02 -070078
ramindani3952ed62021-08-12 15:55:12 +000079 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 Guy9fc27812011-04-27 14:21:41 -070089 /**
John Reck0e89e2b2014-10-31 14:49:06 -070090 * Posts a decStrong call to the appropriate thread.
91 * Thread-safe.
92 */
93 void postDecStrong();
94
Stan Iliev564ca3e2018-09-04 22:00:00 +000095 inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; }
96
97 inline sk_sp<SkImage> getImage() const { return this->layerImage; }
98
Alec Mourid0001fe2021-11-22 10:09:22 -080099 inline void setMaxLuminanceNits(float maxLuminanceNits) {
100 mMaxLuminanceNits = maxLuminanceNits;
101 }
102
103 inline float getMaxLuminanceNits() { return mMaxLuminanceNits; }
104
John Reck8df7f3c2022-09-29 13:19:54 -0400105 void setBufferFormat(uint32_t format) { mBufferFormat = format; }
106
107 uint32_t getBufferFormat() const { return mBufferFormat; }
108
Nader Jawad55f19762020-11-25 15:30:20 -0800109 void draw(SkCanvas* canvas);
110
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500111protected:
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500112
113 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -0800114
Romain Guy9ace8f52011-07-07 20:50:11 -0700115private:
Romain Guyaa6c24c2011-04-28 18:40:04 -0700116 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700117 * Color filter used to draw this layer. Optional.
118 */
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400119 sk_sp<SkColorFilter> mColorFilter;
120
121 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800122 * Indicates raster data backing the layer is scaled, requiring filtration.
123 */
Chris Craike5c65842015-03-02 17:50:26 -0800124 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800125
126 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700127 * Opacity of the layer.
128 */
sergeyv3e9999b2017-01-19 15:37:02 -0800129 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800130
Romain Guy9ace8f52011-07-07 20:50:11 -0700131 /**
132 * Blending mode of the layer.
133 */
sergeyv3e9999b2017-01-19 15:37:02 -0800134 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700135
136 /**
Romain Guy302a9df2011-08-16 13:55:02 -0700137 * Optional transform.
138 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000139 SkMatrix transform;
140
141 /**
ramindani3952ed62021-08-12 15:55:12 +0000142 * Optional crop
143 */
144 SkRect mCurrentCropRect;
145
146 /**
147 * Optional transform
148 */
149 uint32_t mWindowTransform;
150
151 /**
Stan Iliev564ca3e2018-09-04 22:00:00 +0000152 * 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 Guy302a9df2011-08-16 13:55:02 -0700170
Alec Mourid0001fe2021-11-22 10:09:22 -0800171 /**
172 * Max input luminance if the layer is HDR
173 */
174 float mMaxLuminanceNits = -1;
175
John Reck8df7f3c2022-09-29 13:19:54 -0400176 uint32_t mBufferFormat = 0;
177
John Reck1bcacfd2017-11-03 10:12:19 -0700178}; // struct Layer
Romain Guydda570202010-07-06 11:39:32 -0700179
Chris Blume7b8a8082018-11-30 15:51:58 -0800180} // namespace uirenderer
181} // namespace android