1dda570201ac851dd85af3861f7e575721d3345daRomain Guy/* 2dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Copyright (C) 2010 The Android Open Source Project 3dda570201ac851dd85af3861f7e575721d3345daRomain Guy * 4dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5dda570201ac851dd85af3861f7e575721d3345daRomain Guy * you may not use this file except in compliance with the License. 6dda570201ac851dd85af3861f7e575721d3345daRomain Guy * You may obtain a copy of the License at 7dda570201ac851dd85af3861f7e575721d3345daRomain Guy * 8dda570201ac851dd85af3861f7e575721d3345daRomain Guy * http://www.apache.org/licenses/LICENSE-2.0 9dda570201ac851dd85af3861f7e575721d3345daRomain Guy * 10dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Unless required by applicable law or agreed to in writing, software 11dda570201ac851dd85af3861f7e575721d3345daRomain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12dda570201ac851dd85af3861f7e575721d3345daRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13dda570201ac851dd85af3861f7e575721d3345daRomain Guy * See the License for the specific language governing permissions and 14dda570201ac851dd85af3861f7e575721d3345daRomain Guy * limitations under the License. 15dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 16dda570201ac851dd85af3861f7e575721d3345daRomain Guy 175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_LAYER_H 185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_LAYER_H 19dda570201ac851dd85af3861f7e575721d3345daRomain Guy 20f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include <sys/types.h> 21f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 22dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include <GLES2/gl2.h> 23dda570201ac851dd85af3861f7e575721d3345daRomain Guy 245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#include <ui/Region.h> 255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 26ca79cf69d09efa0c327e9b1237d86a119aea5da7Derek Sollenberger#include <SkPaint.h> 27dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include <SkXfermode.h> 28dda570201ac851dd85af3861f7e575721d3345daRomain Guy 29dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include "Rect.h" 303bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy#include "RenderBuffer.h" 31171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy#include "SkiaColorFilter.h" 329ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy#include "Texture.h" 33f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy#include "Vertex.h" 34dda570201ac851dd85af3861f7e575721d3345daRomain Guy 35dda570201ac851dd85af3861f7e575721d3345daRomain Guynamespace android { 36dda570201ac851dd85af3861f7e575721d3345daRomain Guynamespace uirenderer { 37dda570201ac851dd85af3861f7e575721d3345daRomain Guy 388550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy/////////////////////////////////////////////////////////////////////////////// 398550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy// Layers 408550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy/////////////////////////////////////////////////////////////////////////////// 41dda570201ac851dd85af3861f7e575721d3345daRomain Guy 422bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy// Forward declarations 438aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guyclass Caches; 442bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guyclass OpenGLRenderer; 452bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guyclass DisplayList; 4696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guyclass DeferredDisplayList; 4796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guyclass DeferStateStruct; 482bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy 49dda570201ac851dd85af3861f7e575721d3345daRomain Guy/** 50eb99356a0548684a501766e6a524529ab93304c8Romain Guy * A layer has dimensions and is backed by an OpenGL texture or FBO. 51dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 52dda570201ac851dd85af3861f7e575721d3345daRomain Guystruct Layer { 53603f6de35f21d74ae242d52d501f4f5c25ff4f4cChet Haase Layer(const uint32_t layerWidth, const uint32_t layerHeight); 54d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase ~Layer(); 558550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 562055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy static uint32_t computeIdealWidth(uint32_t layerWidth); 572055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy static uint32_t computeIdealHeight(uint32_t layerHeight); 582055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy 598ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 608ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Calling this method will remove (either by recycling or 618ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * destroying) the associated FBO, if present, and any render 628ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * buffer (stencil for instance.) 638ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 648ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void removeFbo(bool flush = true); 6556257aff8a55c847be72be9924c392033fd8151dDave Burke 66dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 679fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy * Sets this layer's region to a rectangle. Computes the appropriate 689fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy * texture coordinates. 699fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy */ 709fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy void setRegionAsRect() { 719fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy const android::Rect& bounds = region.getBounds(); 729fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy regionRect.set(bounds.leftTop().x, bounds.leftTop().y, 739fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy bounds.rightBottom().x, bounds.rightBottom().y); 749fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy 759ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy const float texX = 1.0f / float(texture.width); 769ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy const float texY = 1.0f / float(texture.height); 779fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy const float height = layer.getHeight(); 789fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy texCoords.set( 799fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy regionRect.left * texX, (height - regionRect.top) * texY, 809fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy regionRect.right * texX, (height - regionRect.bottom) * texY); 819ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 829ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy regionRect.translate(layer.left, layer.top); 839ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 849ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 852bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy void updateDeferred(OpenGLRenderer* renderer, DisplayList* displayList, 862bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy int left, int top, int right, int bottom) { 872bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy this->renderer = renderer; 882bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy this->displayList = displayList; 892bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy const Rect r(left, top, right, bottom); 902bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy dirtyRect.unionWith(r); 912bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy deferredUpdateScheduled = true; 922bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy } 932bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy 943bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline uint32_t getWidth() const { 959ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return texture.width; 969ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 979ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 983bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline uint32_t getHeight() const { 999ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return texture.height; 1009ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1019ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1022055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy /** 1032055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * Resize the layer and its texture if needed. 1042055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * 1052055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * @param width The new width of the layer 1062055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * @param height The new height of the layer 1072055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * 1082055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * @return True if the layer was resized or nothing happened, false if 1092055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy * a failure occurred during the resizing operation 1102055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy */ 1112055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy bool resize(const uint32_t width, const uint32_t height); 1122055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy 1139ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy void setSize(uint32_t width, uint32_t height) { 1149ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy texture.width = width; 1159ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy texture.height = height; 1169ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1179ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 118d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase ANDROID_API void setPaint(SkPaint* paint); 119d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase 1209ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setBlend(bool blend) { 1219ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy texture.blend = blend; 1229ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1239ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1243bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline bool isBlend() const { 1259ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return texture.blend; 1269ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1279ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1289ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setAlpha(int alpha) { 1299ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->alpha = alpha; 1309ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1319ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1329ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setAlpha(int alpha, SkXfermode::Mode mode) { 1339ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->alpha = alpha; 1349ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->mode = mode; 1359ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1369ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1373bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline int getAlpha() const { 1389ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return alpha; 1399ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1409ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1413bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline SkXfermode::Mode getMode() const { 1429ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return mode; 1439ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1449ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1459ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setEmpty(bool empty) { 1469ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->empty = empty; 1479ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1489ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1493bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline bool isEmpty() const { 1509ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return empty; 1519ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1529ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1539ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setFbo(GLuint fbo) { 1549ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->fbo = fbo; 1559ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1569ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1573bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline GLuint getFbo() const { 1589ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return fbo; 1599ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1609ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1613bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline void setStencilRenderBuffer(RenderBuffer* renderBuffer) { 1623bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy if (RenderBuffer::isStencilBuffer(renderBuffer->getFormat())) { 1633bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy this->stencil = renderBuffer; 1643bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, 1653bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy GL_RENDERBUFFER, stencil->getName()); 1663bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy } else { 1673bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy ALOGE("The specified render buffer is not a stencil buffer"); 1683bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy } 1698ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy } 1708ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 1713bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline RenderBuffer* getStencilRenderBuffer() const { 1728ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy return stencil; 1738ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy } 1748ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 1753bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline GLuint getTexture() const { 1769ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return texture.id; 1779ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1789ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1793bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline GLenum getRenderTarget() const { 1809ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return renderTarget; 1819ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1829ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1839ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setRenderTarget(GLenum renderTarget) { 1849ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->renderTarget = renderTarget; 1859ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1869ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 187d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) { 188d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy texture.setWrap(wrap, bindTexture, force, renderTarget); 1899ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1909ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 191d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy void setFilter(GLenum filter, bool bindTexture = false, bool force = false) { 192d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy texture.setFilter(filter, bindTexture, force, renderTarget); 1939ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1949ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1953bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline bool isCacheable() const { 1969ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return cacheable; 1979ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 1989ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 1999ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setCacheable(bool cacheable) { 2009ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->cacheable = cacheable; 2019ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 2029ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 2033bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline bool isDirty() const { 2047c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy return dirty; 2057c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy } 2067c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 2077c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy inline void setDirty(bool dirty) { 2087c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy this->dirty = dirty; 2097c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy } 2107c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 2113bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline bool isTextureLayer() const { 2129ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return textureLayer; 2139ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 2149ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 2159ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline void setTextureLayer(bool textureLayer) { 2169ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy this->textureLayer = textureLayer; 2179ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 2189ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 2193bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy inline SkiaColorFilter* getColorFilter() const { 2209ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return colorFilter; 2219ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy } 2229ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 223d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase ANDROID_API void setColorFilter(SkiaColorFilter* filter); 2249ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 2258aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy void bindStencilRenderBuffer() const; 2262055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy 2278aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy void bindTexture() const; 2288aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy void generateTexture(); 2298aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy void allocateTexture(); 2308aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy void deleteTexture(); 231ef09a210dd6ea481158b7028ec2424a7f5769ed2Romain Guy 232ef09a210dd6ea481158b7028ec2424a7f5769ed2Romain Guy /** 233ef09a210dd6ea481158b7028ec2424a7f5769ed2Romain Guy * When the caller frees the texture itself, the caller 234ef09a210dd6ea481158b7028ec2424a7f5769ed2Romain Guy * must call this method to tell this layer that it lost 235ef09a210dd6ea481158b7028ec2424a7f5769ed2Romain Guy * the texture. 236ef09a210dd6ea481158b7028ec2424a7f5769ed2Romain Guy */ 2378aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy ANDROID_API void clearTexture(); 2382055abaa0a590c35e27e1ae2e7d7cfccdfb98b59Romain Guy 2399ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy inline mat4& getTexTransform() { 2409ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy return texTransform; 2419fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy } 2429fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy 243302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy inline mat4& getTransform() { 244302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy return transform; 245302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy } 246302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy 24796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void defer(); 248e93482f5eac3df581d57e64c2a771a96aa868585Romain Guy void cancelDefer(); 24996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void flush(); 25002b49b70ede0b9eb760ff334823aee1d9520ed85Romain Guy void render(); 25196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 2529fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy /** 2538550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Bounds of the layer. 254dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 255dda570201ac851dd85af3861f7e575721d3345daRomain Guy Rect layer; 256dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 2578550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Texture coordinates of the layer. 258dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 2598550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy Rect texCoords; 260c3fedafc5f50100219449125a000e3138f6fb987Romain Guy /** 261c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * Clipping rectangle. 262c3fedafc5f50100219449125a000e3138f6fb987Romain Guy */ 263c3fedafc5f50100219449125a000e3138f6fb987Romain Guy Rect clipRect; 2648550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 265dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 2669ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * Dirty region indicating what parts of the layer 2679ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * have been drawn. 268eb99356a0548684a501766e6a524529ab93304c8Romain Guy */ 2699ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy Region region; 270eb99356a0548684a501766e6a524529ab93304c8Romain Guy /** 2719ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * If the region is a rectangle, coordinates of the 2729ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * region are stored here. 273dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 2749ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy Rect regionRect; 2759ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 276dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 2779ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * If the layer can be rendered as a mesh, this is non-null. 278dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 2799ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy TextureVertex* mesh; 2809ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy GLsizei meshElementCount; 2819ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 2822bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy /** 2832bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy * Used for deferred updates. 2842bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy */ 2852bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy bool deferredUpdateScheduled; 2862bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy OpenGLRenderer* renderer; 2872bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy DisplayList* displayList; 2882bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy Rect dirtyRect; 2895bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guy bool debugDrawUpdate; 29034416eaa1c07b3d7a139e780cea8f8d73219650eChris Craik bool hasDrawnSinceUpdate; 2912bf68f063b0077ddef6ebfe54f2ae5e063c2c229Romain Guy 2929ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guyprivate: 2938aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy Caches& caches; 2948aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy 295dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 2969ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * Name of the FBO used to render the layer. If the name is 0 2979ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * this layer is not backed by an FBO, but a simple texture. 298dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 2999ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy GLuint fbo; 3008550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 30138c85b907a478af96d71b9a5df5a2066b8475311Romain Guy /** 3023bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy * The render buffer used as the stencil buffer. 3038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 3043bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy RenderBuffer* stencil; 3058ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 3068ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 3070bb5667b4ef91fefd0500fae0186789d15d54e0eRomain Guy * Indicates whether this layer has been used already. 30838c85b907a478af96d71b9a5df5a2066b8475311Romain Guy */ 30938c85b907a478af96d71b9a5df5a2066b8475311Romain Guy bool empty; 3108550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 3118550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy /** 3129ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * The texture backing this layer. 3138550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy */ 3149ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy Texture texture; 3159ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 3168550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy /** 3179ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * If set to true (by default), the layer can be reused. 3188550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy */ 3199ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy bool cacheable; 3205b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 3215b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 3229ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * When set to true, this layer must be treated as a texture 3239ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * layer. 3245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 3259ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy bool textureLayer; 3269ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy 32740667676e542a9daeafeac9904c30004e8706fd3Romain Guy /** 3287c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy * When set to true, this layer is dirty and should be cleared 3297c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy * before any rendering occurs. 3307c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy */ 3317c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy bool dirty; 3327c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 3337c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy /** 3349ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * Indicates the render target. 33540667676e542a9daeafeac9904c30004e8706fd3Romain Guy */ 3369ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy GLenum renderTarget; 337171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy 338171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy /** 339171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy * Color filter used to draw this layer. Optional. 340171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy */ 341171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy SkiaColorFilter* colorFilter; 342f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 343f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 3449ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * Opacity of the layer. 345aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 3469ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy int alpha; 347aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 3489ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy * Blending mode of the layer. 349aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 3509ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy SkXfermode::Mode mode; 351aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 352aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 353aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Optional texture coordinates transform. 354aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 355aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy mat4 texTransform; 3568f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy 357302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy /** 358302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy * Optional transform. 359302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy */ 360302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy mat4 transform; 361302a9df1d50373c82923bb84ff665dfce584fb22Romain Guy 36296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 36396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Used to defer display lists when the layer is updated with a 36496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * display list. 36596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 36696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy DeferredDisplayList* deferredList; 36796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 368dda570201ac851dd85af3861f7e575721d3345daRomain Guy}; // struct Layer 369dda570201ac851dd85af3861f7e575721d3345daRomain Guy 370dda570201ac851dd85af3861f7e575721d3345daRomain Guy}; // namespace uirenderer 371dda570201ac851dd85af3861f7e575721d3345daRomain Guy}; // namespace android 372dda570201ac851dd85af3861f7e575721d3345daRomain Guy 3735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_LAYER_H 374