blob: c4e4c1c96ba6b830f8f88e5df5ae3e95259afb56 [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 Reck38e0c322015-11-10 12:19:17 -080019#include <GpuMemoryTracker.h>
John Reck1bcacfd2017-11-03 10:12:19 -070020#include <utils/RefBase.h>
Romain Guydda570202010-07-06 11:39:32 -070021
John Recke170fb62018-05-07 08:12:07 -070022#include <SkBlendMode.h>
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040023#include <SkColorFilter.h>
24#include <SkColorSpace.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 */
John Reck38e0c322015-11-10 12:19:17 -080042class Layer : public VirtualLightRefBase, GpuMemoryTracker {
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 Iliev564ca3e2018-09-04 22:00:00 +000048 virtual uint32_t getWidth() const { return mWidth; }
Romain Guy9ace8f52011-07-07 20:50:11 -070049
Stan Iliev564ca3e2018-09-04 22:00:00 +000050 virtual uint32_t getHeight() const { return mHeight; }
Romain Guy9ace8f52011-07-07 20:50:11 -070051
Stan Iliev564ca3e2018-09-04 22:00:00 +000052 virtual void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; }
Romain Guy9ace8f52011-07-07 20:50:11 -070053
Stan Iliev564ca3e2018-09-04 22:00:00 +000054 virtual void setBlend(bool blend) { mBlend = blend; }
Romain Guy9ace8f52011-07-07 20:50:11 -070055
Stan Iliev564ca3e2018-09-04 22:00:00 +000056 virtual 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
John Reck1bcacfd2017-11-03 10:12:19 -070071 inline SkBlendMode getMode() const { return mode; }
Romain Guy9ace8f52011-07-07 20:50:11 -070072
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040073 inline SkColorFilter* getColorFilter() const { return mColorFilter.get(); }
Romain Guy9ace8f52011-07-07 20:50:11 -070074
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040075 void setColorFilter(sk_sp<SkColorFilter> filter);
76
77 void setDataSpace(android_dataspace dataspace);
78
79 void setColorSpace(sk_sp<SkColorSpace> colorSpace);
80
81 inline sk_sp<SkColorFilter> getColorSpaceWithFilter() const { return mColorSpaceWithFilter; }
Romain Guy9ace8f52011-07-07 20:50:11 -070082
Stan Iliev564ca3e2018-09-04 22:00:00 +000083 inline SkMatrix& getTexTransform() { return texTransform; }
Romain Guy9fc27812011-04-27 14:21:41 -070084
Stan Iliev564ca3e2018-09-04 22:00:00 +000085 inline SkMatrix& getTransform() { return transform; }
Romain Guy302a9df2011-08-16 13:55:02 -070086
Romain Guy9fc27812011-04-27 14:21:41 -070087 /**
John Reck0e89e2b2014-10-31 14:49:06 -070088 * Posts a decStrong call to the appropriate thread.
89 * Thread-safe.
90 */
91 void postDecStrong();
92
Stan Iliev564ca3e2018-09-04 22:00:00 +000093 inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; }
94
95 inline sk_sp<SkImage> getImage() const { return this->layerImage; }
96
Greg Daniel8cd3edf2017-01-09 14:15:41 -050097protected:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050098
99 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -0800100
Romain Guy9ace8f52011-07-07 20:50:11 -0700101private:
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400102 void buildColorSpaceWithFilter();
103
Romain Guyaa6c24c2011-04-28 18:40:04 -0700104 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700105 * Color filter used to draw this layer. Optional.
106 */
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400107 sk_sp<SkColorFilter> mColorFilter;
108
109 /**
110 * Colorspace of the contents of the layer. Optional.
111 */
112 android_dataspace mCurrentDataspace = HAL_DATASPACE_UNKNOWN;
113
114 /**
115 * A color filter that is the combination of the mColorFilter and mColorSpace. Optional.
116 */
117 sk_sp<SkColorFilter> mColorSpaceWithFilter;
Romain Guy9ace8f52011-07-07 20:50:11 -0700118
119 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800120 * Indicates raster data backing the layer is scaled, requiring filtration.
121 */
Chris Craike5c65842015-03-02 17:50:26 -0800122 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800123
124 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700125 * Opacity of the layer.
126 */
sergeyv3e9999b2017-01-19 15:37:02 -0800127 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800128
Romain Guy9ace8f52011-07-07 20:50:11 -0700129 /**
130 * Blending mode of the layer.
131 */
sergeyv3e9999b2017-01-19 15:37:02 -0800132 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700133
134 /**
135 * Optional texture coordinates transform.
136 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000137 SkMatrix texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700138
Romain Guy302a9df2011-08-16 13:55:02 -0700139 /**
140 * Optional transform.
141 */
Stan Iliev564ca3e2018-09-04 22:00:00 +0000142 SkMatrix transform;
143
144 /**
145 * An image backing the layer.
146 */
147 sk_sp<SkImage> layerImage;
148
149 /**
150 * layer width.
151 */
152 uint32_t mWidth = 0;
153
154 /**
155 * layer height.
156 */
157 uint32_t mHeight = 0;
158
159 /**
160 * enable blending
161 */
162 bool mBlend = false;
Romain Guy302a9df2011-08-16 13:55:02 -0700163
John Reck1bcacfd2017-11-03 10:12:19 -0700164}; // struct Layer
Romain Guydda570202010-07-06 11:39:32 -0700165
John Reck1bcacfd2017-11-03 10:12:19 -0700166}; // namespace uirenderer
167}; // namespace android