blob: e5520ea0e811ca2989eb6bfb939c23ac9eb1d433 [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
Nick Kralevichbfed8272014-11-01 18:37:39 -070019#include <utils/RefBase.h>
John Reck38e0c322015-11-10 12:19:17 -080020#include <GpuMemoryTracker.h>
Romain Guydda57022010-07-06 11:39:32 -070021
Derek Sollenbergerca79cf62012-08-14 16:44:52 -040022#include <SkPaint.h>
Mike Reed260ab722016-10-07 15:59:20 -040023#include <SkBlendMode.h>
Romain Guydda57022010-07-06 11:39:32 -070024
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050025#include "Matrix.h"
Romain Guydda57022010-07-06 11:39:32 -070026
27namespace android {
28namespace uirenderer {
29
Romain Guy8550c4c2010-10-08 15:49:53 -070030///////////////////////////////////////////////////////////////////////////////
31// Layers
32///////////////////////////////////////////////////////////////////////////////
Romain Guydda57022010-07-06 11:39:32 -070033
John Reck3b202512014-06-23 13:13:08 -070034class RenderState;
Romain Guy2bf68f02012-03-02 13:37:47 -080035
Romain Guydda57022010-07-06 11:39:32 -070036/**
Greg Daniel8cd3edf2017-01-09 14:15:41 -050037 * A layer has dimensions and is backed by a backend specific texture or framebuffer.
Romain Guydda57022010-07-06 11:39:32 -070038 */
John Reck38e0c322015-11-10 12:19:17 -080039class Layer : public VirtualLightRefBase, GpuMemoryTracker {
Chris Craik564acf72014-01-02 16:46:18 -080040public:
Greg Daniel8cd3edf2017-01-09 14:15:41 -050041 enum class Api {
42 OpenGL = 0,
43 Vulkan = 1,
Chris Craikbfd1cd62014-09-10 13:04:31 -070044 };
Chris Craikbfd1cd62014-09-10 13:04:31 -070045
Greg Daniel8cd3edf2017-01-09 14:15:41 -050046 Api getApi() const {
47 return mApi;
48 }
49
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
Chris Craik9757ac02014-02-25 18:50:17 -080062 inline void setForceFilter(bool forceFilter) {
63 this->forceFilter = forceFilter;
64 }
65
66 inline bool getForceFilter() const {
67 return forceFilter;
68 }
69
Romain Guy9ace8f52011-07-07 20:50:11 -070070 inline void setAlpha(int alpha) {
71 this->alpha = alpha;
72 }
73
Mike Reed260ab722016-10-07 15:59:20 -040074 inline void setAlpha(int alpha, SkBlendMode mode) {
Romain Guy9ace8f52011-07-07 20:50:11 -070075 this->alpha = alpha;
76 this->mode = mode;
77 }
78
Romain Guy3bbacf22013-02-06 16:51:04 -080079 inline int getAlpha() const {
Romain Guy9ace8f52011-07-07 20:50:11 -070080 return alpha;
81 }
82
Mike Reed260ab722016-10-07 15:59:20 -040083 inline SkBlendMode getMode() const {
Romain Guy9ace8f52011-07-07 20:50:11 -070084 return mode;
85 }
86
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050087 inline SkColorFilter* getColorFilter() const {
Romain Guy9ace8f52011-07-07 20:50:11 -070088 return colorFilter;
89 }
90
Chris Craik5e00c7c2016-07-06 16:10:09 -070091 void setColorFilter(SkColorFilter* filter);
Romain Guy9ace8f52011-07-07 20:50:11 -070092
Romain Guy9ace8f52011-07-07 20:50:11 -070093 inline mat4& getTexTransform() {
94 return texTransform;
Romain Guy9fc27812011-04-27 14:21:41 -070095 }
96
Romain Guy302a9df2011-08-16 13:55:02 -070097 inline mat4& getTransform() {
98 return transform;
99 }
100
Romain Guy9fc27812011-04-27 14:21:41 -0700101 /**
John Reck0e89e2b2014-10-31 14:49:06 -0700102 * Posts a decStrong call to the appropriate thread.
103 * Thread-safe.
104 */
105 void postDecStrong();
106
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500107protected:
sergeyv3e9999b2017-01-19 15:37:02 -0800108 Layer(RenderState& renderState, Api api, SkColorFilter* colorFilter, int alpha,
109 SkBlendMode mode);
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500110
111 RenderState& mRenderState;
John Reck57998012015-01-29 10:17:57 -0800112
Romain Guy9ace8f52011-07-07 20:50:11 -0700113private:
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500114 Api mApi;
Romain Guy9ace8f52011-07-07 20:50:11 -0700115
Romain Guyaa6c24c2011-04-28 18:40:04 -0700116 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700117 * Color filter used to draw this layer. Optional.
118 */
sergeyv3e9999b2017-01-19 15:37:02 -0800119 SkColorFilter* colorFilter;
Romain Guy9ace8f52011-07-07 20:50:11 -0700120
121 /**
Chris Craik9757ac02014-02-25 18:50:17 -0800122 * Indicates raster data backing the layer is scaled, requiring filtration.
123 */
Chris Craike5c65842015-03-02 17:50:26 -0800124 bool forceFilter = false;
Chris Craik9757ac02014-02-25 18:50:17 -0800125
126 /**
Romain Guy9ace8f52011-07-07 20:50:11 -0700127 * Opacity of the layer.
128 */
sergeyv3e9999b2017-01-19 15:37:02 -0800129 int alpha;
Chris Craik9757ac02014-02-25 18:50:17 -0800130
Romain Guy9ace8f52011-07-07 20:50:11 -0700131 /**
132 * Blending mode of the layer.
133 */
sergeyv3e9999b2017-01-19 15:37:02 -0800134 SkBlendMode mode;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700135
136 /**
137 * Optional texture coordinates transform.
138 */
139 mat4 texTransform;
Romain Guy8f0095c2011-05-02 17:24:22 -0700140
Romain Guy302a9df2011-08-16 13:55:02 -0700141 /**
142 * Optional transform.
143 */
144 mat4 transform;
145
Romain Guydda57022010-07-06 11:39:32 -0700146}; // struct Layer
147
148}; // namespace uirenderer
149}; // namespace android