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 setBufferFormat(uint32_t format)105 void setBufferFormat(uint32_t format) { mBufferFormat = format; } 106 getBufferFormat()107 uint32_t getBufferFormat() const { return mBufferFormat; } 108 109 void draw(SkCanvas* canvas); 110 111 protected: 112 113 RenderState& mRenderState; 114 115 private: 116 /** 117 * Color filter used to draw this layer. Optional. 118 */ 119 sk_sp<SkColorFilter> mColorFilter; 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 transform. 138 */ 139 SkMatrix transform; 140 141 /** 142 * Optional crop 143 */ 144 SkRect mCurrentCropRect; 145 146 /** 147 * Optional transform 148 */ 149 uint32_t mWindowTransform; 150 151 /** 152 * An image backing the layer. 153 */ 154 sk_sp<SkImage> layerImage; 155 156 /** 157 * layer width. 158 */ 159 uint32_t mWidth = 0; 160 161 /** 162 * layer height. 163 */ 164 uint32_t mHeight = 0; 165 166 /** 167 * enable blending 168 */ 169 bool mBlend = false; 170 171 /** 172 * Max input luminance if the layer is HDR 173 */ 174 float mMaxLuminanceNits = -1; 175 176 uint32_t mBufferFormat = 0; 177 178 }; // struct Layer 179 180 } // namespace uirenderer 181 } // namespace android 182