• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #pragma once
18 
19 #include <utils/RefBase.h>
20 #include <GpuMemoryTracker.h>
21 
22 #include <SkPaint.h>
23 #include <SkBlendMode.h>
24 
25 #include "Matrix.h"
26 
27 namespace android {
28 namespace uirenderer {
29 
30 ///////////////////////////////////////////////////////////////////////////////
31 // Layers
32 ///////////////////////////////////////////////////////////////////////////////
33 
34 class RenderState;
35 
36 /**
37  * A layer has dimensions and is backed by a backend specific texture or framebuffer.
38  */
39 class Layer : public VirtualLightRefBase, GpuMemoryTracker {
40 public:
41     enum class Api {
42         OpenGL = 0,
43         Vulkan = 1,
44     };
45 
getApi()46     Api getApi() const {
47         return mApi;
48     }
49 
50     ~Layer();
51 
52     virtual uint32_t getWidth() const = 0;
53 
54     virtual uint32_t getHeight() const = 0;
55 
56     virtual void setSize(uint32_t width, uint32_t height) = 0;
57 
58     virtual void setBlend(bool blend) = 0;
59 
60     virtual bool isBlend() const = 0;
61 
setForceFilter(bool forceFilter)62     inline void setForceFilter(bool forceFilter) {
63         this->forceFilter = forceFilter;
64     }
65 
getForceFilter()66     inline bool getForceFilter() const {
67         return forceFilter;
68     }
69 
setAlpha(int alpha)70     inline void setAlpha(int alpha) {
71         this->alpha = alpha;
72     }
73 
setAlpha(int alpha,SkBlendMode mode)74     inline void setAlpha(int alpha, SkBlendMode mode) {
75         this->alpha = alpha;
76         this->mode = mode;
77     }
78 
getAlpha()79     inline int getAlpha() const {
80         return alpha;
81     }
82 
getMode()83     inline SkBlendMode getMode() const {
84         return mode;
85     }
86 
getColorFilter()87     inline SkColorFilter* getColorFilter() const {
88         return colorFilter;
89     }
90 
91     void setColorFilter(SkColorFilter* filter);
92 
getTexTransform()93     inline mat4& getTexTransform() {
94         return texTransform;
95     }
96 
getTransform()97     inline mat4& getTransform() {
98         return transform;
99     }
100 
101     /**
102      * Posts a decStrong call to the appropriate thread.
103      * Thread-safe.
104      */
105     void postDecStrong();
106 
107 protected:
108     Layer(RenderState& renderState, Api api, SkColorFilter* colorFilter, int alpha,
109             SkBlendMode mode);
110 
111     RenderState& mRenderState;
112 
113 private:
114     Api mApi;
115 
116     /**
117      * Color filter used to draw this layer. Optional.
118      */
119     SkColorFilter* colorFilter;
120 
121     /**
122      * Indicates raster data backing the layer is scaled, requiring filtration.
123      */
124     bool forceFilter = false;
125 
126     /**
127      * Opacity of the layer.
128      */
129     int alpha;
130 
131     /**
132      * Blending mode of the layer.
133      */
134     SkBlendMode mode;
135 
136     /**
137      * Optional texture coordinates transform.
138      */
139     mat4 texTransform;
140 
141     /**
142      * Optional transform.
143      */
144     mat4 transform;
145 
146 }; // struct Layer
147 
148 }; // namespace uirenderer
149 }; // namespace android
150