blob: 89bcddcc96d0b8acabc5c3e94a126dbf0ec42208 [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 Sollenbergerbe3876c2018-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
John Reck1bcacfd2017-11-03 10:12:19 -070075 inline SkBlendMode getMode() const { return mode; }
Romain Guy9ace8f52011-07-07 20:50:11 -070076
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040077 inline SkColorFilter* getColorFilter() const { return mColorFilter.get(); }
Romain Guy9ace8f52011-07-07 20:50:11 -070078
Derek Sollenbergerbe3876c2018-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
Greg Daniel8cd3edf2017-01-09 14:15:41 -050097protected:
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040098 Layer(RenderState& renderState, Api api, sk_sp<SkColorFilter>, int alpha,
John Reck1bcacfd2017-11-03 10:12:19 -070099 SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500100
101 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -0800102
Romain Guy9ace8f52011-07-07 20:50:11 -0700103private:
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400104 void buildColorSpaceWithFilter();
105
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500106 Api mApi;
Romain Guy9ace8f52011-07-07 20:50:11 -0700107
Romain Guyaa6c24c2011-04-28 18:40:04 -0700108 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700109 * Color filter used to draw this layer. Optional.
110 */
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -0400111 sk_sp<SkColorFilter> mColorFilter;
112
113 /**
114 * Colorspace of the contents of the layer. Optional.
115 */
116 android_dataspace mCurrentDataspace = HAL_DATASPACE_UNKNOWN;
117
118 /**
119 * A color filter that is the combination of the mColorFilter and mColorSpace. Optional.
120 */
121 sk_sp<SkColorFilter> mColorSpaceWithFilter;
Romain Guy9ace8f52011-07-07 20:50:11 -0700122
123 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800124 * Indicates raster data backing the layer is scaled, requiring filtration.
125 */
Chris Craike5c65842015-03-02 17:50:26 -0800126 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800127
128 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700129 * Opacity of the layer.
130 */
sergeyv3e9999b2017-01-19 15:37:02 -0800131 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800132
Romain Guy9ace8f52011-07-07 20:50:11 -0700133 /**
134 * Blending mode of the layer.
135 */
sergeyv3e9999b2017-01-19 15:37:02 -0800136 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700137
138 /**
139 * Optional texture coordinates transform.
140 */
141 mat4 texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700142
Romain Guy302a9df2011-08-16 13:55:02 -0700143 /**
144 * Optional transform.
145 */
146 mat4 transform;
147
John Reck1bcacfd2017-11-03 10:12:19 -0700148}; // struct Layer
Romain Guydda57022010-07-06 11:39:32 -0700149
John Reck1bcacfd2017-11-03 10:12:19 -0700150}; // namespace uirenderer
151}; // namespace android