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 getTexTransform()77 inline SkMatrix& getTexTransform() { return texTransform; } 78 getTransform()79 inline SkMatrix& getTransform() { return transform; } 80 81 /** 82 * Posts a decStrong call to the appropriate thread. 83 * Thread-safe. 84 */ 85 void postDecStrong(); 86 setImage(const sk_sp<SkImage> & image)87 inline void setImage(const sk_sp<SkImage>& image) { this->layerImage = image; } 88 getImage()89 inline sk_sp<SkImage> getImage() const { return this->layerImage; } 90 91 void draw(SkCanvas* canvas); 92 93 protected: 94 95 RenderState& mRenderState; 96 97 private: 98 /** 99 * Color filter used to draw this layer. Optional. 100 */ 101 sk_sp<SkColorFilter> mColorFilter; 102 103 /** 104 * Indicates raster data backing the layer is scaled, requiring filtration. 105 */ 106 bool forceFilter = false; 107 108 /** 109 * Opacity of the layer. 110 */ 111 int alpha; 112 113 /** 114 * Blending mode of the layer. 115 */ 116 SkBlendMode mode; 117 118 /** 119 * Optional texture coordinates transform. 120 */ 121 SkMatrix texTransform; 122 123 /** 124 * Optional transform. 125 */ 126 SkMatrix transform; 127 128 /** 129 * An image backing the layer. 130 */ 131 sk_sp<SkImage> layerImage; 132 133 /** 134 * layer width. 135 */ 136 uint32_t mWidth = 0; 137 138 /** 139 * layer height. 140 */ 141 uint32_t mHeight = 0; 142 143 /** 144 * enable blending 145 */ 146 bool mBlend = false; 147 148 }; // struct Layer 149 150 } // namespace uirenderer 151 } // namespace android 152