blob: 0789344f970e6f808e4bbba9d3df04081a245ed5 [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
Nader Jawad55f19762020-11-25 15:30:20 -080099 void draw(SkCanvas* canvas);
100
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500101protected:
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500102
103 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -0800104
Romain Guy9ace8f52011-07-07 20:50:11 -0700105private:
Romain Guyaa6c24c2011-04-28 18:40:04 -0700106 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700107 * Color filter used to draw this layer. Optional.
108 */
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400109 sk_sp<SkColorFilter> mColorFilter;
110
111 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800112 * Indicates raster data backing the layer is scaled, requiring filtration.
113 */
Chris Craike5c65842015-03-02 17:50:26 -0800114 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800115
116 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700117 * Opacity of the layer.
118 */
sergeyv3e9999b2017-01-19 15:37:02 -0800119 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800120
Romain Guy9ace8f52011-07-07 20:50:11 -0700121 /**
122 * Blending mode of the layer.
123 */
sergeyv3e9999b2017-01-19 15:37:02 -0800124 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700125
126 /**
Romain Guy302a9df2011-08-16 13:55:02 -0700127 * Optional transform.
128 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000129 SkMatrix transform;
130
131 /**
ramindani3952ed62021-08-12 15:55:12 +0000132 * Optional crop
133 */
134 SkRect mCurrentCropRect;
135
136 /**
137 * Optional transform
138 */
139 uint32_t mWindowTransform;
140
141 /**
Stan Iliev564ca3e2018-09-04 22:00:00 +0000142 * An image backing the layer.
143 */
144 sk_sp<SkImage> layerImage;
145
146 /**
147 * layer width.
148 */
149 uint32_t mWidth = 0;
150
151 /**
152 * layer height.
153 */
154 uint32_t mHeight = 0;
155
156 /**
157 * enable blending
158 */
159 bool mBlend = false;
Romain Guy302a9df2011-08-16 13:55:02 -0700160
John Reck1bcacfd2017-11-03 10:12:19 -0700161}; // struct Layer
Romain Guydda570202010-07-06 11:39:32 -0700162
Chris Blume7b8a8082018-11-30 15:51:58 -0800163} // namespace uirenderer
164} // namespace android