blob: e4f96e914c36b0ab78db11079ffa37251a119b63 [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>
John Reck1bcacfd2017-11-03 10:12:19 -070024#include <SkPaint.h>
Stan Iliev564ca3e2018-09-04 22:00:00 +000025#include <SkImage.h>
26#include <SkMatrix.h>
27#include <system/graphics.h>
Romain Guydda570202010-07-06 11:39:32 -070028
29namespace android {
30namespace uirenderer {
31
Romain Guy8550c4c2010-10-08 15:49:53 -070032///////////////////////////////////////////////////////////////////////////////
33// Layers
34///////////////////////////////////////////////////////////////////////////////
Romain Guydda570202010-07-06 11:39:32 -070035
John Reck3b202512014-06-23 13:13:08 -070036class RenderState;
Romain Guy2bf68f02012-03-02 13:37:47 -080037
Romain Guydda570202010-07-06 11:39:32 -070038/**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050039 * A layer has dimensions and is backed by a backend specific texture or framebuffer.
Romain Guydda570202010-07-06 11:39:32 -070040 */
Stan Iliev1a025a72018-09-05 16:35:11 -040041class Layer : public VirtualLightRefBase {
Chris Craik564acf72014-01-02 16:46:18 -080042public:
Stan Iliev564ca3e2018-09-04 22:00:00 +000043 Layer(RenderState& renderState, sk_sp<SkColorFilter>, int alpha, SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050044
Chet Haased15ebf22012-09-05 11:40:29 -070045 ~Layer();
Romain Guy8550c4c2010-10-08 15:49:53 -070046
Stan Iliev1a025a72018-09-05 16:35:11 -040047 uint32_t getWidth() const { return mWidth; }
Romain Guy9ace8f52011-07-07 20:50:11 -070048
Stan Iliev1a025a72018-09-05 16:35:11 -040049 uint32_t getHeight() const { return mHeight; }
Romain Guy9ace8f52011-07-07 20:50:11 -070050
Stan Iliev1a025a72018-09-05 16:35:11 -040051 void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; }
Romain Guy9ace8f52011-07-07 20:50:11 -070052
Stan Iliev1a025a72018-09-05 16:35:11 -040053 void setBlend(bool blend) { mBlend = blend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070054
Stan Iliev1a025a72018-09-05 16:35:11 -040055 bool isBlend() const { return mBlend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070056
John Reck1bcacfd2017-11-03 10:12:19 -070057 inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080058
John Reck1bcacfd2017-11-03 10:12:19 -070059 inline bool getForceFilter() const { return forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080060
John Reck1bcacfd2017-11-03 10:12:19 -070061 inline void setAlpha(int alpha) { this->alpha = alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070062
Mike Reed260ab722016-10-07 15:59:20 -040063 inline void setAlpha(int alpha, SkBlendMode mode) {
Romain Guy9ace8f52011-07-07 20:50:11 -070064 this->alpha = alpha;
65 this->mode = mode;
66 }
67
John Reck1bcacfd2017-11-03 10:12:19 -070068 inline int getAlpha() const { return alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070069
Stan Iliev8fc3d8e2018-09-28 18:44:26 -040070 SkBlendMode getMode() const;
Romain Guy9ace8f52011-07-07 20:50:11 -070071
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040072 inline SkColorFilter* getColorFilter() const { return mColorFilter.get(); }
Romain Guy9ace8f52011-07-07 20:50:11 -070073
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040074 void setColorFilter(sk_sp<SkColorFilter> filter);
75
76 void setDataSpace(android_dataspace dataspace);
77
78 void setColorSpace(sk_sp<SkColorSpace> colorSpace);
79
80 inline sk_sp<SkColorFilter> getColorSpaceWithFilter() const { return mColorSpaceWithFilter; }
Romain Guy9ace8f52011-07-07 20:50:11 -070081
Stan Iliev564ca3e2018-09-04 22:00:00 +000082 inline SkMatrix& getTexTransform() { return texTransform; }
Romain Guy9fc27812011-04-27 14:21:41 -070083
Stan Iliev564ca3e2018-09-04 22:00:00 +000084 inline SkMatrix& getTransform() { return transform; }
Romain Guy302a9df2011-08-16 13:55:02 -070085
Romain Guy9fc27812011-04-27 14:21:41 -070086 /**
John Reck0e89e2b2014-10-31 14:49:06 -070087 * Posts a decStrong call to the appropriate thread.
88 * Thread-safe.
89 */
90 void postDecStrong();
91
Stan Iliev564ca3e2018-09-04 22:00:00 +000092 inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; }
93
94 inline sk_sp<SkImage> getImage() const { return this->layerImage; }
95
Greg Daniel8cd3edf2017-01-09 14:15:41 -050096protected:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050097
98 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -080099
Romain Guy9ace8f52011-07-07 20:50:11 -0700100private:
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400101 void buildColorSpaceWithFilter();
102
Romain Guyaa6c24c2011-04-28 18:40:04 -0700103 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700104 * Color filter used to draw this layer. Optional.
105 */
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400106 sk_sp<SkColorFilter> mColorFilter;
107
108 /**
109 * Colorspace of the contents of the layer. Optional.
110 */
111 android_dataspace mCurrentDataspace = HAL_DATASPACE_UNKNOWN;
112
113 /**
114 * A color filter that is the combination of the mColorFilter and mColorSpace. Optional.
115 */
116 sk_sp<SkColorFilter> mColorSpaceWithFilter;
Romain Guy9ace8f52011-07-07 20:50:11 -0700117
118 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800119 * Indicates raster data backing the layer is scaled, requiring filtration.
120 */
Chris Craike5c65842015-03-02 17:50:26 -0800121 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800122
123 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700124 * Opacity of the layer.
125 */
sergeyv3e9999b2017-01-19 15:37:02 -0800126 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800127
Romain Guy9ace8f52011-07-07 20:50:11 -0700128 /**
129 * Blending mode of the layer.
130 */
sergeyv3e9999b2017-01-19 15:37:02 -0800131 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700132
133 /**
134 * Optional texture coordinates transform.
135 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000136 SkMatrix texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700137
Romain Guy302a9df2011-08-16 13:55:02 -0700138 /**
139 * Optional transform.
140 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000141 SkMatrix transform;
142
143 /**
144 * An image backing the layer.
145 */
146 sk_sp<SkImage> layerImage;
147
148 /**
149 * layer width.
150 */
151 uint32_t mWidth = 0;
152
153 /**
154 * layer height.
155 */
156 uint32_t mHeight = 0;
157
158 /**
159 * enable blending
160 */
161 bool mBlend = false;
Romain Guy302a9df2011-08-16 13:55:02 -0700162
John Reck1bcacfd2017-11-03 10:12:19 -0700163}; // struct Layer
Romain Guydda570202010-07-06 11:39:32 -0700164
John Reck1bcacfd2017-11-03 10:12:19 -0700165}; // namespace uirenderer
166}; // namespace android