blob: d41c9703e9087601311469644a0fb8d422c7da10 [file] [log] [blame]
Romain Guydda57022010-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 Guydda57022010-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 Guydda57022010-07-06 11:39:32 -070021
Derek Sollenberger551d08e2018-04-20 16:13:31 -040022#include <SkColorFilter.h>
23#include <SkColorSpace.h>
Mike Reed260ab722016-10-07 15:59:20 -040024#include <SkBlendMode.h>
John Reck1bcacfd2017-11-03 10:12:19 -070025#include <SkPaint.h>
Romain Guydda57022010-07-06 11:39:32 -070026
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050027#include "Matrix.h"
Romain Guydda57022010-07-06 11:39:32 -070028
29namespace android {
30namespace uirenderer {
31
Romain Guy8550c4c2010-10-08 15:49:53 -070032///////////////////////////////////////////////////////////////////////////////
33// Layers
34///////////////////////////////////////////////////////////////////////////////
Romain Guydda57022010-07-06 11:39:32 -070035
John Reck3b202512014-06-23 13:13:08 -070036class RenderState;
Romain Guy2bf68f02012-03-02 13:37:47 -080037
Romain Guydda57022010-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 Guydda57022010-07-06 11:39:32 -070040 */
John Reck38e0c322015-11-10 12:19:17 -080041class Layer : public VirtualLightRefBase, GpuMemoryTracker {
Chris Craik564acf72014-01-02 16:46:18 -080042public:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050043 enum class Api {
44 OpenGL = 0,
45 Vulkan = 1,
Chris Craikbfd1cd62014-09-10 13:04:31 -070046 };
Chris Craikbfd1cd62014-09-10 13:04:31 -070047
John Reck1bcacfd2017-11-03 10:12:19 -070048 Api getApi() const { return mApi; }
Greg Daniel8cd3edf2017-01-09 14:15:41 -050049
Chet Haased15ebf22012-09-05 11:40:29 -070050 ~Layer();
Romain Guy8550c4c2010-10-08 15:49:53 -070051
Greg Daniel8cd3edf2017-01-09 14:15:41 -050052 virtual uint32_t getWidth() const = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070053
Greg Daniel8cd3edf2017-01-09 14:15:41 -050054 virtual uint32_t getHeight() const = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070055
Greg Daniel8cd3edf2017-01-09 14:15:41 -050056 virtual void setSize(uint32_t width, uint32_t height) = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070057
Greg Daniel8cd3edf2017-01-09 14:15:41 -050058 virtual void setBlend(bool blend) = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070059
Greg Daniel8cd3edf2017-01-09 14:15:41 -050060 virtual bool isBlend() const = 0;
Romain Guy9ace8f52011-07-07 20:50:11 -070061
John Reck1bcacfd2017-11-03 10:12:19 -070062 inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080063
John Reck1bcacfd2017-11-03 10:12:19 -070064 inline bool getForceFilter() const { return forceFilter; }
Chris Craik9757ac02014-02-25 18:50:17 -080065
John Reck1bcacfd2017-11-03 10:12:19 -070066 inline void setAlpha(int alpha) { this->alpha = alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070067
Mike Reed260ab722016-10-07 15:59:20 -040068 inline void setAlpha(int alpha, SkBlendMode mode) {
Romain Guy9ace8f52011-07-07 20:50:11 -070069 this->alpha = alpha;
70 this->mode = mode;
71 }
72
John Reck1bcacfd2017-11-03 10:12:19 -070073 inline int getAlpha() const { return alpha; }
Romain Guy9ace8f52011-07-07 20:50:11 -070074
Stan Iliev9b788772018-09-28 18:44:26 -040075 virtual SkBlendMode getMode() const { return mode; }
Romain Guy9ace8f52011-07-07 20:50:11 -070076
Derek Sollenberger551d08e2018-04-20 16:13:31 -040077 inline SkColorFilter* getColorFilter() const { return mColorFilter.get(); }
Romain Guy9ace8f52011-07-07 20:50:11 -070078
Derek Sollenberger551d08e2018-04-20 16:13:31 -040079 void setColorFilter(sk_sp<SkColorFilter> filter);
80
81 void setDataSpace(android_dataspace dataspace);
82
83 void setColorSpace(sk_sp<SkColorSpace> colorSpace);
84
85 inline sk_sp<SkColorFilter> getColorSpaceWithFilter() const { return mColorSpaceWithFilter; }
Romain Guy9ace8f52011-07-07 20:50:11 -070086
John Reck1bcacfd2017-11-03 10:12:19 -070087 inline mat4& getTexTransform() { return texTransform; }
Romain Guy9fc27812011-04-27 14:21:41 -070088
John Reck1bcacfd2017-11-03 10:12:19 -070089 inline mat4& getTransform() { return transform; }
Romain Guy302a9df2011-08-16 13:55:02 -070090
Romain Guy9fc27812011-04-27 14:21:41 -070091 /**
John Reck0e89e2b2014-10-31 14:49:06 -070092 * Posts a decStrong call to the appropriate thread.
93 * Thread-safe.
94 */
95 void postDecStrong();
96
Stan Iliev93ac4012018-09-10 14:48:38 -040097 inline void setBufferSize(uint32_t width, uint32_t height) {
98 mBufferWidth = width;
99 mBufferHeight = height;
100 }
101
102 inline uint32_t getBufferWidth() const { return mBufferWidth; }
103
104 inline uint32_t getBufferHeight() const { return mBufferHeight; }
105
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500106protected:
Derek Sollenberger551d08e2018-04-20 16:13:31 -0400107 Layer(RenderState& renderState, Api api, sk_sp<SkColorFilter>, int alpha,
John Reck1bcacfd2017-11-03 10:12:19 -0700108 SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500109
110 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -0800111
Stan Iliev9b788772018-09-28 18:44:26 -0400112 /**
113 * Blending mode of the layer.
114 */
115 SkBlendMode mode;
116
Romain Guy9ace8f52011-07-07 20:50:11 -0700117private:
Derek Sollenberger551d08e2018-04-20 16:13:31 -0400118 void buildColorSpaceWithFilter();
119
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500120 Api mApi;
Romain Guy9ace8f52011-07-07 20:50:11 -0700121
Romain Guyaa6c24c2011-04-28 18:40:04 -0700122 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700123 * Color filter used to draw this layer. Optional.
124 */
Derek Sollenberger551d08e2018-04-20 16:13:31 -0400125 sk_sp<SkColorFilter> mColorFilter;
126
127 /**
128 * Colorspace of the contents of the layer. Optional.
129 */
130 android_dataspace mCurrentDataspace = HAL_DATASPACE_UNKNOWN;
131
132 /**
133 * A color filter that is the combination of the mColorFilter and mColorSpace. Optional.
134 */
135 sk_sp<SkColorFilter> mColorSpaceWithFilter;
Romain Guy9ace8f52011-07-07 20:50:11 -0700136
137 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800138 * Indicates raster data backing the layer is scaled, requiring filtration.
139 */
Chris Craike5c65842015-03-02 17:50:26 -0800140 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800141
142 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700143 * Opacity of the layer.
144 */
sergeyv3e9999b2017-01-19 15:37:02 -0800145 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800146
Romain Guy9ace8f52011-07-07 20:50:11 -0700147 /**
Romain Guyaa6c24c2011-04-28 18:40:04 -0700148 * Optional texture coordinates transform.
149 */
150 mat4 texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700151
Romain Guy302a9df2011-08-16 13:55:02 -0700152 /**
153 * Optional transform.
154 */
155 mat4 transform;
156
Stan Iliev93ac4012018-09-10 14:48:38 -0400157 uint32_t mBufferWidth = 0;
158
159 uint32_t mBufferHeight = 0;
John Reck1bcacfd2017-11-03 10:12:19 -0700160}; // struct Layer
Romain Guydda57022010-07-06 11:39:32 -0700161
John Reck1bcacfd2017-11-03 10:12:19 -0700162}; // namespace uirenderer
163}; // namespace android