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