• 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 
21 #include <SkBlendMode.h>
22 #include <SkColorFilter.h>
23 #include <SkColorSpace.h>
24 #include <SkCanvas.h>
25 #include <SkPaint.h>
26 #include <SkImage.h>
27 #include <SkMatrix.h>
28 #include <system/graphics.h>
29 
30 namespace android {
31 namespace uirenderer {
32 
33 ///////////////////////////////////////////////////////////////////////////////
34 // Layers
35 ///////////////////////////////////////////////////////////////////////////////
36 
37 class RenderState;
38 
39 /**
40  * A layer has dimensions and is backed by a backend specific texture or framebuffer.
41  */
42 class Layer : public VirtualLightRefBase {
43 public:
44     Layer(RenderState& renderState, sk_sp<SkColorFilter>, int alpha, SkBlendMode mode);
45 
46     ~Layer();
47 
getWidth()48     uint32_t getWidth() const { return mWidth; }
49 
getHeight()50     uint32_t getHeight() const { return mHeight; }
51 
setSize(uint32_t width,uint32_t height)52     void setSize(uint32_t width, uint32_t height) { mWidth = width; mHeight = height; }
53 
setBlend(bool blend)54     void setBlend(bool blend) { mBlend = blend; }
55 
isBlend()56     bool isBlend() const { return mBlend; }
57 
setForceFilter(bool forceFilter)58     inline void setForceFilter(bool forceFilter) { this->forceFilter = forceFilter; }
59 
getForceFilter()60     inline bool getForceFilter() const { return forceFilter; }
61 
setAlpha(int alpha)62     inline void setAlpha(int alpha) { this->alpha = alpha; }
63 
setAlpha(int alpha,SkBlendMode mode)64     inline void setAlpha(int alpha, SkBlendMode mode) {
65         this->alpha = alpha;
66         this->mode = mode;
67     }
68 
getAlpha()69     inline int getAlpha() const { return alpha; }
70 
71     SkBlendMode getMode() const;
72 
getColorFilter()73     inline sk_sp<SkColorFilter> getColorFilter() const { return mColorFilter; }
74 
setColorFilter(sk_sp<SkColorFilter> filter)75     void setColorFilter(sk_sp<SkColorFilter> filter) { mColorFilter = filter; };
76 
getTransform()77     inline SkMatrix& getTransform() { return transform; }
78 
getCurrentCropRect()79     inline SkRect getCurrentCropRect() { return mCurrentCropRect; }
80 
setCurrentCropRect(const SkRect currentCropRect)81     inline void setCurrentCropRect(const SkRect currentCropRect) {
82         mCurrentCropRect = currentCropRect;
83     }
84 
setWindowTransform(uint32_t windowTransform)85     inline void setWindowTransform(uint32_t windowTransform) { mWindowTransform = windowTransform; }
86 
getWindowTransform()87     inline uint32_t getWindowTransform() { return mWindowTransform; }
88 
89     /**
90      * Posts a decStrong call to the appropriate thread.
91      * Thread-safe.
92      */
93     void postDecStrong();
94 
setImage(const sk_sp<SkImage> & image)95     inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; }
96 
getImage()97     inline sk_sp<SkImage> getImage() const { return this->layerImage; }
98 
setMaxLuminanceNits(float maxLuminanceNits)99     inline void setMaxLuminanceNits(float maxLuminanceNits) {
100         mMaxLuminanceNits = maxLuminanceNits;
101     }
102 
getMaxLuminanceNits()103     inline float getMaxLuminanceNits() { return mMaxLuminanceNits; }
104 
105     void draw(SkCanvas* canvas);
106 
107 protected:
108 
109     RenderState& mRenderState;
110 
111 private:
112     /**
113      * Color filter used to draw this layer. Optional.
114      */
115     sk_sp<SkColorFilter> mColorFilter;
116 
117     /**
118      * Indicates raster data backing the layer is scaled, requiring filtration.
119      */
120     bool forceFilter = false;
121 
122     /**
123      * Opacity of the layer.
124      */
125     int alpha;
126 
127     /**
128      * Blending mode of the layer.
129      */
130     SkBlendMode mode;
131 
132     /**
133      * Optional transform.
134      */
135     SkMatrix transform;
136 
137     /**
138      * Optional crop
139      */
140     SkRect mCurrentCropRect;
141 
142     /**
143      * Optional transform
144      */
145     uint32_t mWindowTransform;
146 
147     /**
148      * An image backing the layer.
149      */
150     sk_sp<SkImage> layerImage;
151 
152     /**
153      * layer width.
154      */
155     uint32_t mWidth = 0;
156 
157     /**
158      * layer height.
159      */
160     uint32_t mHeight = 0;
161 
162     /**
163      * enable blending
164      */
165     bool mBlend = false;
166 
167     /**
168      * Max input luminance if the layer is HDR
169      */
170     float mMaxLuminanceNits = -1;
171 
172 };  // struct Layer
173 
174 }  // namespace uirenderer
175 }  // namespace android
176