Layer.h revision 8cd3edfa15cc9cdbffa935d19ab894426b08d174
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 27namespace android { 28namespace uirenderer { 29 30/////////////////////////////////////////////////////////////////////////////// 31// Layers 32/////////////////////////////////////////////////////////////////////////////// 33 34class RenderState; 35 36/** 37 * A layer has dimensions and is backed by a backend specific texture or framebuffer. 38 */ 39class Layer : public VirtualLightRefBase, GpuMemoryTracker { 40public: 41 enum class Api { 42 OpenGL = 0, 43 Vulkan = 1, 44 }; 45 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 62 inline void setForceFilter(bool forceFilter) { 63 this->forceFilter = forceFilter; 64 } 65 66 inline bool getForceFilter() const { 67 return forceFilter; 68 } 69 70 inline void setAlpha(int alpha) { 71 this->alpha = alpha; 72 } 73 74 inline void setAlpha(int alpha, SkBlendMode mode) { 75 this->alpha = alpha; 76 this->mode = mode; 77 } 78 79 inline int getAlpha() const { 80 return alpha; 81 } 82 83 inline SkBlendMode getMode() const { 84 return mode; 85 } 86 87 inline SkColorFilter* getColorFilter() const { 88 return colorFilter; 89 } 90 91 void setColorFilter(SkColorFilter* filter); 92 93 inline mat4& getTexTransform() { 94 return texTransform; 95 } 96 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 107protected: 108 Layer(RenderState& renderState, Api api); 109 110 RenderState& mRenderState; 111 112private: 113 Api mApi; 114 115 /** 116 * Color filter used to draw this layer. Optional. 117 */ 118 SkColorFilter* colorFilter = nullptr; 119 120 /** 121 * Indicates raster data backing the layer is scaled, requiring filtration. 122 */ 123 bool forceFilter = false; 124 125 /** 126 * Opacity of the layer. 127 */ 128 int alpha = 255; 129 130 /** 131 * Blending mode of the layer. 132 */ 133 SkBlendMode mode = SkBlendMode::kSrcOver; 134 135 /** 136 * Optional texture coordinates transform. 137 */ 138 mat4 texTransform; 139 140 /** 141 * Optional transform. 142 */ 143 mat4 transform; 144 145}; // struct Layer 146 147}; // namespace uirenderer 148}; // namespace android 149