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