Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_LAYER_H |
| 18 | #define ANDROID_HWUI_LAYER_H |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 19 | |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 20 | #include <cutils/compiler.h> |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 22 | #include <utils/StrongPointer.h> |
Nick Kralevich | bfed827 | 2014-11-01 18:37:39 -0700 | [diff] [blame] | 23 | #include <utils/RefBase.h> |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 24 | #include <memory> |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 25 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 26 | #include <GLES2/gl2.h> |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 27 | #include <GpuMemoryTracker.h> |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 28 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 29 | #include <ui/Region.h> |
| 30 | |
Derek Sollenberger | ca79cf6 | 2012-08-14 16:44:52 -0400 | [diff] [blame] | 31 | #include <SkPaint.h> |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 32 | #include <SkXfermode.h> |
| 33 | |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 34 | #include "Matrix.h" |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 35 | #include "Rect.h" |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 36 | #include "RenderBuffer.h" |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 37 | #include "Texture.h" |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 38 | #include "Vertex.h" |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 39 | |
| 40 | namespace android { |
| 41 | namespace uirenderer { |
| 42 | |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 43 | /////////////////////////////////////////////////////////////////////////////// |
| 44 | // Layers |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 46 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 47 | // Forward declarations |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 48 | class Caches; |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 49 | class RenderNode; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 50 | class RenderState; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 51 | class OpenGLRenderer; |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 52 | class DeferredDisplayList; |
Chih-Hung Hsieh | d3448e4 | 2014-09-15 14:28:52 -0700 | [diff] [blame] | 53 | struct DeferStateStruct; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 54 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 55 | /** |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 56 | * A layer has dimensions and is backed by an OpenGL texture or FBO. |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 57 | */ |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 58 | class Layer : public VirtualLightRefBase, GpuMemoryTracker { |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 59 | public: |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 60 | enum class Type { |
| 61 | Texture, |
| 62 | DisplayList, |
Chris Craik | 8a226d2 | 2014-09-08 16:40:21 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Chris Craik | bfd1cd6 | 2014-09-10 13:04:31 -0700 | [diff] [blame] | 65 | // layer lifecycle, controlled from outside |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 66 | enum class State { |
| 67 | Uncached = 0, |
| 68 | InCache = 1, |
| 69 | FailedToCache = 2, |
| 70 | RemovedFromCache = 3, |
| 71 | DeletedFromCache = 4, |
| 72 | InGarbageList = 5, |
Chris Craik | bfd1cd6 | 2014-09-10 13:04:31 -0700 | [diff] [blame] | 73 | }; |
| 74 | State state; // public for logging/debugging purposes |
| 75 | |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 76 | Layer(Type type, RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight); |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 77 | ~Layer(); |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 78 | |
Romain Guy | 2055aba | 2013-01-18 16:42:51 -0800 | [diff] [blame] | 79 | static uint32_t computeIdealWidth(uint32_t layerWidth); |
| 80 | static uint32_t computeIdealHeight(uint32_t layerHeight); |
| 81 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 82 | /** |
| 83 | * Calling this method will remove (either by recycling or |
| 84 | * destroying) the associated FBO, if present, and any render |
| 85 | * buffer (stencil for instance.) |
| 86 | */ |
| 87 | void removeFbo(bool flush = true); |
Dave Burke | 56257af | 2012-09-25 20:30:09 -0700 | [diff] [blame] | 88 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 89 | /** |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 90 | * Sets this layer's region to a rectangle. Computes the appropriate |
| 91 | * texture coordinates. |
| 92 | */ |
| 93 | void setRegionAsRect() { |
| 94 | const android::Rect& bounds = region.getBounds(); |
| 95 | regionRect.set(bounds.leftTop().x, bounds.leftTop().y, |
| 96 | bounds.rightBottom().x, bounds.rightBottom().y); |
| 97 | |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 98 | const float texX = 1.0f / float(texture.mWidth); |
| 99 | const float texY = 1.0f / float(texture.mHeight); |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 100 | const float height = layer.getHeight(); |
| 101 | texCoords.set( |
| 102 | regionRect.left * texX, (height - regionRect.top) * texY, |
| 103 | regionRect.right * texX, (height - regionRect.bottom) * texY); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 104 | |
| 105 | regionRect.translate(layer.left, layer.top); |
| 106 | } |
| 107 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 108 | void setWindowTransform(Matrix4& windowTransform) { |
| 109 | cachedInvTransformInWindow.loadInverse(windowTransform); |
| 110 | rendererLightPosDirty = true; |
| 111 | } |
| 112 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 113 | void updateDeferred(RenderNode* renderNode, int left, int top, int right, int bottom); |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 114 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 115 | inline uint32_t getWidth() const { |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 116 | return texture.mWidth; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 119 | inline uint32_t getHeight() const { |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 120 | return texture.mHeight; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Romain Guy | 2055aba | 2013-01-18 16:42:51 -0800 | [diff] [blame] | 123 | /** |
| 124 | * Resize the layer and its texture if needed. |
| 125 | * |
| 126 | * @param width The new width of the layer |
| 127 | * @param height The new height of the layer |
| 128 | * |
| 129 | * @return True if the layer was resized or nothing happened, false if |
| 130 | * a failure occurred during the resizing operation |
| 131 | */ |
| 132 | bool resize(const uint32_t width, const uint32_t height); |
| 133 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 134 | void setSize(uint32_t width, uint32_t height) { |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 135 | texture.updateSize(width, height, texture.format()); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Derek Sollenberger | 674554f | 2014-02-19 16:47:32 +0000 | [diff] [blame] | 138 | ANDROID_API void setPaint(const SkPaint* paint); |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 139 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 140 | inline void setBlend(bool blend) { |
| 141 | texture.blend = blend; |
| 142 | } |
| 143 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 144 | inline bool isBlend() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 145 | return texture.blend; |
| 146 | } |
| 147 | |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 148 | inline void setForceFilter(bool forceFilter) { |
| 149 | this->forceFilter = forceFilter; |
| 150 | } |
| 151 | |
| 152 | inline bool getForceFilter() const { |
| 153 | return forceFilter; |
| 154 | } |
| 155 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 156 | inline void setAlpha(int alpha) { |
| 157 | this->alpha = alpha; |
| 158 | } |
| 159 | |
| 160 | inline void setAlpha(int alpha, SkXfermode::Mode mode) { |
| 161 | this->alpha = alpha; |
| 162 | this->mode = mode; |
| 163 | } |
| 164 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 165 | inline int getAlpha() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 166 | return alpha; |
| 167 | } |
| 168 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 169 | inline SkXfermode::Mode getMode() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 170 | return mode; |
| 171 | } |
| 172 | |
| 173 | inline void setEmpty(bool empty) { |
| 174 | this->empty = empty; |
| 175 | } |
| 176 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 177 | inline bool isEmpty() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 178 | return empty; |
| 179 | } |
| 180 | |
| 181 | inline void setFbo(GLuint fbo) { |
| 182 | this->fbo = fbo; |
| 183 | } |
| 184 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 185 | inline GLuint getFbo() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 186 | return fbo; |
| 187 | } |
| 188 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 189 | inline void setStencilRenderBuffer(RenderBuffer* renderBuffer) { |
| 190 | if (RenderBuffer::isStencilBuffer(renderBuffer->getFormat())) { |
| 191 | this->stencil = renderBuffer; |
| 192 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, |
| 193 | GL_RENDERBUFFER, stencil->getName()); |
| 194 | } else { |
| 195 | ALOGE("The specified render buffer is not a stencil buffer"); |
| 196 | } |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 199 | inline RenderBuffer* getStencilRenderBuffer() const { |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 200 | return stencil; |
| 201 | } |
| 202 | |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 203 | inline GLuint getTextureId() const { |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 204 | return texture.id(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 207 | inline Texture& getTexture() { |
| 208 | return texture; |
| 209 | } |
| 210 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 211 | inline GLenum getRenderTarget() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 212 | return renderTarget; |
| 213 | } |
| 214 | |
| 215 | inline void setRenderTarget(GLenum renderTarget) { |
| 216 | this->renderTarget = renderTarget; |
| 217 | } |
| 218 | |
John Reck | 417ed6d | 2016-03-22 16:01:08 -0700 | [diff] [blame] | 219 | inline bool isRenderable() const { |
| 220 | return renderTarget != GL_NONE; |
| 221 | } |
| 222 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 223 | void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) { |
| 224 | texture.setWrap(wrap, bindTexture, force, renderTarget); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 227 | void setFilter(GLenum filter, bool bindTexture = false, bool force = false) { |
| 228 | texture.setFilter(filter, bindTexture, force, renderTarget); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 231 | inline bool isCacheable() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 232 | return cacheable; |
| 233 | } |
| 234 | |
| 235 | inline void setCacheable(bool cacheable) { |
| 236 | this->cacheable = cacheable; |
| 237 | } |
| 238 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 239 | inline bool isDirty() const { |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 240 | return dirty; |
| 241 | } |
| 242 | |
| 243 | inline void setDirty(bool dirty) { |
| 244 | this->dirty = dirty; |
| 245 | } |
| 246 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 247 | inline bool isTextureLayer() const { |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 248 | return type == Type::Texture; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 251 | inline SkColorFilter* getColorFilter() const { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 252 | return colorFilter; |
| 253 | } |
| 254 | |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 255 | ANDROID_API void setColorFilter(SkColorFilter* filter); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 256 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 257 | inline void setConvexMask(const SkPath* convexMask) { |
| 258 | this->convexMask = convexMask; |
| 259 | } |
| 260 | |
| 261 | inline const SkPath* getConvexMask() { |
| 262 | return convexMask; |
| 263 | } |
| 264 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 265 | void bindStencilRenderBuffer() const; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 266 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 267 | void bindTexture() const; |
| 268 | void generateTexture(); |
| 269 | void allocateTexture(); |
Romain Guy | ef09a21 | 2012-09-25 12:17:14 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * When the caller frees the texture itself, the caller |
| 273 | * must call this method to tell this layer that it lost |
| 274 | * the texture. |
| 275 | */ |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 276 | ANDROID_API void clearTexture(); |
Romain Guy | 2055aba | 2013-01-18 16:42:51 -0800 | [diff] [blame] | 277 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 278 | inline mat4& getTexTransform() { |
| 279 | return texTransform; |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 282 | inline mat4& getTransform() { |
| 283 | return transform; |
| 284 | } |
| 285 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 286 | void defer(const OpenGLRenderer& rootRenderer); |
Romain Guy | e93482f | 2013-06-17 13:14:51 -0700 | [diff] [blame] | 287 | void cancelDefer(); |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 288 | void flush(); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 289 | void render(const OpenGLRenderer& rootRenderer); |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 290 | |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 291 | /** |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 292 | * Posts a decStrong call to the appropriate thread. |
| 293 | * Thread-safe. |
| 294 | */ |
| 295 | void postDecStrong(); |
| 296 | |
| 297 | /** |
John Reck | 5799801 | 2015-01-29 10:17:57 -0800 | [diff] [blame] | 298 | * Lost the GL context but the layer is still around, mark it invalid internally |
| 299 | * so the dtor knows not to do any GL work |
| 300 | */ |
| 301 | void onGlContextLost(); |
| 302 | |
| 303 | /** |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 304 | * Bounds of the layer. |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 305 | */ |
| 306 | Rect layer; |
| 307 | /** |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 308 | * Texture coordinates of the layer. |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 309 | */ |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 310 | Rect texCoords; |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 311 | /** |
| 312 | * Clipping rectangle. |
| 313 | */ |
| 314 | Rect clipRect; |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 315 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 316 | /** |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 317 | * Dirty region indicating what parts of the layer |
| 318 | * have been drawn. |
| 319 | */ |
| 320 | Region region; |
Romain Guy | 4066767 | 2011-03-18 14:34:03 -0700 | [diff] [blame] | 321 | /** |
| 322 | * If the region is a rectangle, coordinates of the |
| 323 | * region are stored here. |
| 324 | */ |
| 325 | Rect regionRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 326 | |
| 327 | /** |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 328 | * If the layer can be rendered as a mesh, this is non-null. |
| 329 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 330 | TextureVertex* mesh = nullptr; |
| 331 | GLsizei meshElementCount = 0; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 332 | |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 333 | /** |
| 334 | * Used for deferred updates. |
| 335 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 336 | bool deferredUpdateScheduled = false; |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 337 | std::unique_ptr<OpenGLRenderer> renderer; |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 338 | sp<RenderNode> renderNode; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 339 | Rect dirtyRect; |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 340 | bool debugDrawUpdate = false; |
| 341 | bool hasDrawnSinceUpdate = false; |
| 342 | bool wasBuildLayered = false; |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 343 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 344 | private: |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 345 | void requireRenderer(); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 346 | void updateLightPosFromRenderer(const OpenGLRenderer& rootRenderer); |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 347 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 348 | Caches& caches; |
| 349 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 350 | RenderState& renderState; |
| 351 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 352 | /** |
| 353 | * Name of the FBO used to render the layer. If the name is 0 |
| 354 | * this layer is not backed by an FBO, but a simple texture. |
| 355 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 356 | GLuint fbo = 0; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 357 | |
| 358 | /** |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 359 | * The render buffer used as the stencil buffer. |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 360 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 361 | RenderBuffer* stencil = nullptr; |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 362 | |
| 363 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 364 | * Indicates whether this layer has been used already. |
| 365 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 366 | bool empty = true; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * The texture backing this layer. |
| 370 | */ |
| 371 | Texture texture; |
| 372 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 373 | /** |
| 374 | * If set to true (by default), the layer can be reused. |
| 375 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 376 | bool cacheable = true; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 377 | |
| 378 | /** |
Chris Craik | 8a226d2 | 2014-09-08 16:40:21 -0700 | [diff] [blame] | 379 | * Denotes whether the layer is a DisplayList, or Texture layer. |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 380 | */ |
Chris Craik | 8a226d2 | 2014-09-08 16:40:21 -0700 | [diff] [blame] | 381 | const Type type; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 382 | |
| 383 | /** |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 384 | * When set to true, this layer is dirty and should be cleared |
| 385 | * before any rendering occurs. |
| 386 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 387 | bool dirty = false; |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 388 | |
| 389 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 390 | * Indicates the render target. |
| 391 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 392 | GLenum renderTarget = GL_TEXTURE_2D; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 393 | |
| 394 | /** |
| 395 | * Color filter used to draw this layer. Optional. |
| 396 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 397 | SkColorFilter* colorFilter = nullptr; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 398 | |
| 399 | /** |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 400 | * Indicates raster data backing the layer is scaled, requiring filtration. |
| 401 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 402 | bool forceFilter = false; |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 403 | |
| 404 | /** |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 405 | * Opacity of the layer. |
| 406 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 407 | int alpha = 255; |
Chris Craik | 9757ac0 | 2014-02-25 18:50:17 -0800 | [diff] [blame] | 408 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 409 | /** |
| 410 | * Blending mode of the layer. |
| 411 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 412 | SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 413 | |
| 414 | /** |
| 415 | * Optional texture coordinates transform. |
| 416 | */ |
| 417 | mat4 texTransform; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 418 | |
Romain Guy | 302a9df | 2011-08-16 13:55:02 -0700 | [diff] [blame] | 419 | /** |
| 420 | * Optional transform. |
| 421 | */ |
| 422 | mat4 transform; |
| 423 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 424 | /** |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 425 | * Cached transform of layer in window, updated only on creation / resize |
| 426 | */ |
| 427 | mat4 cachedInvTransformInWindow; |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 428 | bool rendererLightPosDirty = true; |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 429 | |
| 430 | /** |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 431 | * Used to defer display lists when the layer is updated with a |
| 432 | * display list. |
| 433 | */ |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 434 | std::unique_ptr<DeferredDisplayList> deferredList; |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 435 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 436 | /** |
| 437 | * This convex path should be used to mask the layer's draw to the screen. |
| 438 | * |
| 439 | * Data not owned/managed by layer object. |
| 440 | */ |
Chris Craik | e5c6584 | 2015-03-02 17:50:26 -0800 | [diff] [blame] | 441 | const SkPath* convexMask = nullptr; |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 442 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 443 | }; // struct Layer |
| 444 | |
| 445 | }; // namespace uirenderer |
| 446 | }; // namespace android |
| 447 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 448 | #endif // ANDROID_HWUI_LAYER_H |