OpenGLRenderer.h revision ac670c0433d19397d4e36ced2110475b6f54fe26
1e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy/* 2e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Copyright (C) 2010 The Android Open Source Project 3e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 4e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * you may not use this file except in compliance with the License. 6e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * You may obtain a copy of the License at 7e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 8e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * http://www.apache.org/licenses/LICENSE-2.0 9e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 10e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Unless required by applicable law or agreed to in writing, software 11e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * See the License for the specific language governing permissions and 14e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * limitations under the License. 15e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy */ 16e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 179d5316e3f56d138504565ff311145ac01621dff4Romain Guy#ifndef ANDROID_UI_OPENGL_RENDERER_H 189d5316e3f56d138504565ff311145ac01621dff4Romain Guy#define ANDROID_UI_OPENGL_RENDERER_H 199d5316e3f56d138504565ff311145ac01621dff4Romain Guy 209d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2.h> 219d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2ext.h> 2285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 23ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkBitmap.h> 24f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h> 25ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h> 26079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h> 27d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy#include <SkShader.h> 2885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h> 29e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 30bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h> 31deba785f122a47915756ffd991f5540d952cf937Romain Guy#include <utils/ResourceTypes.h> 32bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 3351769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h" 34f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h" 355cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h" 36bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h" 375cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h" 38ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include "TextureCache.h" 39dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include "LayerCache.h" 40c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy#include "GradientCache.h" 41f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "PatchCache.h" 42f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h" 43694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy#include "FontRenderer.h" 44ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#include "ProgramCache.h" 45bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 46e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android { 479d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer { 48e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 49f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 50f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Support 51f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 52f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 535cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 54026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * Structure mapping Skia xfermodes to OpenGL blending factors. 55026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 56026c5e16704e817cac7d9c382914c947e34f87e0Romain Guystruct Blender { 57026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy SkXfermode::Mode mode; 58026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy GLenum src; 59026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy GLenum dst; 60026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy}; // struct Blender 61026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 62f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 63f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer 64f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 65f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 665cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 675cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a 685cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API. 695cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 7085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer { 71e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic: 7285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy OpenGLRenderer(); 7385bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy ~OpenGLRenderer(); 74e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 75e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy void setViewport(int width, int height); 76e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy void prepare(); 7708ae317c21ec3086b5017672bba87420cc38a407Romain Guy 78bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int getSaveCount() const; 79bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int save(int flags); 80bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void restore(); 81bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void restoreToCount(int saveCount); 82bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 83bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy int saveLayer(float left, float top, float right, float bottom, const SkPaint* p, int flags); 84bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int flags); 85bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 86f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void translate(float dx, float dy); 87f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void rotate(float degrees); 88f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void scale(float sx, float sy); 89f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 90f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void setMatrix(SkMatrix* matrix); 91f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void getMatrix(SkMatrix* matrix); 92f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void concatMatrix(SkMatrix* matrix); 93f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 949d5316e3f56d138504565ff311145ac01621dff4Romain Guy const Rect& getClipBounds(); 95c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy bool quickReject(float left, float top, float right, float bottom); 96079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); 97bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 98c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy void drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint); 99f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy void drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint); 1008ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, 101f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint); 102deba785f122a47915756ffd991f5540d952cf937Romain Guy void drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, float left, float top, 103deba785f122a47915756ffd991f5540d952cf937Romain Guy float right, float bottom, const SkPaint* paint); 10485bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy void drawColor(int color, SkXfermode::Mode mode); 105bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy void drawRect(float left, float top, float right, float bottom, const SkPaint* paint); 10685bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 107d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy void resetShader(); 108d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy void setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tileX, SkShader::TileMode tileY, 109d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy SkMatrix* matrix, bool hasAlpha); 110f9764a4f532561f6e2e985ff3b25112f1132ce44Romain Guy void setupLinearGradientShader(SkShader* shader, float* bounds, uint32_t* colors, 111c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy float* positions, int count, SkShader::TileMode tileMode, 112c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy SkMatrix* matrix, bool hasAlpha); 113d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 114e8e62a4a032a80409114a37908b5f18ab0080848Romain Guy void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint); 115694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 11608ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate: 1175cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 118d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Type of Skia shader in use. 119d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy */ 120d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy enum ShaderType { 121d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderNone, 122d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderBitmap, 123d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderLinearGradient, 124d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderCircularGradient, 125d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderSweepGradient 126d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy }; 127d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 128d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy /** 1295cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Saves the current state of the renderer as a new snapshot. 1305cbbce535744b89df5ecea95de21ee3733298260Romain Guy * The new snapshot is saved in mSnapshot and the previous snapshot 1315cbbce535744b89df5ecea95de21ee3733298260Romain Guy * is linked from mSnapshot->previous. 1325cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1335cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @return The new save count. This value can be passed to #restoreToCount() 1345cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 135bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int saveSnapshot(); 1365cbbce535744b89df5ecea95de21ee3733298260Romain Guy 1375cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 1385cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Restores the current snapshot; mSnapshot becomes mSnapshot->previous. 1395cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1405cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @return True if the clip should be also reapplied by calling 1415cbbce535744b89df5ecea95de21ee3733298260Romain Guy * #setScissorFromClip(). 1425cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 143bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy bool restoreSnapshot(); 144bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 1455cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 1465cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Sets the clipping rectangle using glScissor. The clip is defined by 1475cbbce535744b89df5ecea95de21ee3733298260Romain Guy * the current snapshot's clipRect member. 1485cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 149bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void setScissorFromClip(); 150bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 1515cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 152d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Compose the layer defined in the current snapshot with the layer 153d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * defined by the previous snapshot. 154d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 155d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 156d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 157d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param curent The current snapshot containing the layer to compose 158d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param previous The previous snapshot to compose the current layer with 159d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 160d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy void composeLayer(sp<Snapshot> current, sp<Snapshot> previous); 161d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 162d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 163d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Creates a new layer stored in the specified snapshot. 164d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 165d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param snapshot The snapshot associated with the new layer 166d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param left The left coordinate of the layer 167d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param top The top coordinate of the layer 168d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param right The right coordinate of the layer 169d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param bottom The bottom coordinate of the layer 170d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param alpha The translucency of the layer 171d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode of the layer 172d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param flags The layer save flags 173d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 174d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @return True if the layer was successfully created, false otherwise 175d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 176d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom, 177d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy int alpha, SkXfermode::Mode mode, int flags); 178d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 179d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 1805cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a colored rectangle with the specified color. The specified coordinates 1815cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 1825cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1835cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 1845cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 1855cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 1865cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 1875cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param color The rectangle's ARGB color, defined as a packed 32 bits word 188026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param mode The Skia xfermode to use 1893d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy * @param ignoreTransform True if the current transform should be ignored 1905cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 191026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void drawColorRect(float left, float top, float right, float bottom, 1923d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy int color, SkXfermode::Mode mode, bool ignoreTransform = false); 1935cbbce535744b89df5ecea95de21ee3733298260Romain Guy 1945cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 1955cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 1965cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 1975cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1985cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 1995cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 2005cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 2015cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 2025cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param texture The texture name to map onto the rectangle 2035cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 204d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode 205c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy * @param blend True if the texture contains an alpha channel 2065cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 207bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy void drawTextureRect(float left, float top, float right, float bottom, GLuint texture, 208a979474f15b454c8e2963f239a3770e200bb227cRomain Guy float alpha, SkXfermode::Mode mode, bool blend); 209c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 210026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy /** 21182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 21282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * are transformed by the current snapshot's transform matrix. 21382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 21482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 21582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 21682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 21782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 21882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture to use 21982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param paint The paint containing the alpha, blending mode, etc. 22082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 221a979474f15b454c8e2963f239a3770e200bb227cRomain Guy void drawTextureRect(float left, float top, float right, float bottom, 222a979474f15b454c8e2963f239a3770e200bb227cRomain Guy const Texture* texture, const SkPaint* paint); 22382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 22482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy /** 22582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Draws a textured mesh with the specified texture. If the indices are omitted, the 22682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * mesh is drawn as a simple quad. 22782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 22882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 22982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 23082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 23182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 23282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture name to map onto the rectangle 23382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 23482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param mode The blending mode 23582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param blend True if the texture contains an alpha channel 23682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param vertices The vertices that define the mesh 23782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texCoords The texture coordinates of each vertex 23882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param indices The indices of the vertices, can be NULL 23982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param elementsCount The number of elements in the mesh, required by indices 240f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 241f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, 242a979474f15b454c8e2963f239a3770e200bb227cRomain Guy float alpha, SkXfermode::Mode mode, bool blend, 243f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy GLvoid* vertices, GLvoid* texCoords, GLvoid* indices, GLsizei elementsCount = 0); 244f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 245f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 246d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Fills the specified rectangle with the currently set bitmap shader. 247d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 248d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param left The left coordinate of the rectangle 249d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param top The top coordinate of the rectangle 250d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param right The right coordinate of the rectangle 251d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param bottom The bottom coordinate of the rectangle 252d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 253d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param mode The blending mode 254d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy */ 255d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy void drawBitmapShader(float left, float top, float right, float bottom, float alpha, 256d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy SkXfermode::Mode mode); 257d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 258d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy /** 259c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * Fills the specified rectangle with the currently set linear gradient shader. 260c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * 261c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param left The left coordinate of the rectangle 262c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param top The top coordinate of the rectangle 263c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param right The right coordinate of the rectangle 264c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param bottom The bottom coordinate of the rectangle 265c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 266c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param mode The blending mode 267c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy */ 268c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy void drawLinearGradientShader(float left, float top, float right, float bottom, float alpha, 269c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy SkXfermode::Mode mode); 270c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy 271c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy /** 272ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Resets the texture coordinates stored in mMeshVertices. Setting the values 273026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * back to default is achieved by calling: 274026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 2758ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 276026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 277026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u1 The left coordinate of the texture 278026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v1 The bottom coordinate of the texture 279026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u2 The right coordinate of the texture 280026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v2 The top coordinate of the texture 281026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 282026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 283026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 2848ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy /** 2858ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * Gets the alpha and xfermode out of a paint object. If the paint is null 2868ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * alpha will be 255 and the xfermode will be SRC_OVER. 2878ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * 2888ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * @param paint The paint to extract values from 2898ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * @param alpha Where to store the resulting alpha 2908ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * @param mode Where to store the resulting xfermode 2918ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy */ 2928ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode); 2938ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy 294f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 295a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy * Binds the specified texture with the specified wrap modes. 296a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy */ 297a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy inline void bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT); 298a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy 299a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy /** 30082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Enable or disable blending as necessary. This function sets the appropriate 30182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * blend function based on the specified xfermode. 30282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 303a979474f15b454c8e2963f239a3770e200bb227cRomain Guy inline void chooseBlending(bool blend, SkXfermode::Mode mode, bool isPremultiplied = true); 30482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 305260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy /** 306d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Use the specified program with the current GL context. If the program is already 307d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * in use, it will not be bound again. If it is not in use, the current program is 308d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * marked unused and the specified program becomes used and becomes the new 309d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * current program. 3106926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy * 311d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param program The program to use 312d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 313d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @return true If the specified program was already in use, false otherwise. 314260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy */ 315d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy inline bool useProgram(const sp<Program>& program); 316260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy 317bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Dimensions of the drawing surface 318bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int mWidth, mHeight; 319bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 32085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy // Matrix used for ortho projection in shaders 321260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy mat4 mOrthoMatrix; 322bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 323c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy // Model-view matrix used to position/size objects 324c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy mat4 mModelView; 325c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 326bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Number of saved states 327bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int mSaveCount; 328f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy // Base state 329f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy Snapshot mFirstSnapshot; 330bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Current state 331bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy sp<Snapshot> mSnapshot; 3329d5316e3f56d138504565ff311145ac01621dff4Romain Guy 3339d5316e3f56d138504565ff311145ac01621dff4Romain Guy // Shaders 334d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy sp<Program> mCurrentProgram; 335d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy sp<DrawColorProgram> mDrawColorProgram; 336d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy sp<DrawTextureProgram> mDrawTextureProgram; 337694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy sp<DrawTextProgram> mDrawTextProgram; 338f9764a4f532561f6e2e985ff3b25112f1132ce44Romain Guy sp<DrawLinearGradientProgram> mDrawLinearGradientProgram; 339026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 340026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy // Used to draw textured quads 341ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy TextureVertex mMeshVertices[4]; 342ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 3431e79386ba34f0db38c1b35b22cdf122632534354Romain Guy // Current texture state 3441e79386ba34f0db38c1b35b22cdf122632534354Romain Guy GLuint mLastTexture; 3451e79386ba34f0db38c1b35b22cdf122632534354Romain Guy 34682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Last known blend state 34782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy bool mBlend; 34882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy GLenum mLastSrcMode; 34982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy GLenum mLastDstMode; 35082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 3517fac2e18339f765320d759e8d4c090f92431959eRomain Guy // Skia shaders 352d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy ShaderType mShader; 353f9764a4f532561f6e2e985ff3b25112f1132ce44Romain Guy SkShader* mShaderKey; 354d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy bool mShaderBlend; 355a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy GLenum mShaderTileX; 356a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy GLenum mShaderTileY; 357d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy SkMatrix* mShaderMatrix; 3587fac2e18339f765320d759e8d4c090f92431959eRomain Guy // Bitmaps 3597fac2e18339f765320d759e8d4c090f92431959eRomain Guy SkBitmap* mShaderBitmap; 3607fac2e18339f765320d759e8d4c090f92431959eRomain Guy // Gradients 3617fac2e18339f765320d759e8d4c090f92431959eRomain Guy float* mShaderBounds; 3627fac2e18339f765320d759e8d4c090f92431959eRomain Guy uint32_t* mShaderColors; 3637fac2e18339f765320d759e8d4c090f92431959eRomain Guy float* mShaderPositions; 364c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy int mShaderCount; 365d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 36651769a68a5cb34e9564740c6a854fcb93018789dRomain Guy // GL extensions 36751769a68a5cb34e9564740c6a854fcb93018789dRomain Guy Extensions mExtensions; 36851769a68a5cb34e9564740c6a854fcb93018789dRomain Guy 369694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy // Font renderer 370694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy FontRenderer mFontRenderer; 371694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 37282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Various caches 373ce0537b80087a6225273040a987414b1dd081aa0Romain Guy TextureCache mTextureCache; 374dda570201ac851dd85af3861f7e575721d3345daRomain Guy LayerCache mLayerCache; 375c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy GradientCache mGradientCache; 376ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy ProgramCache mProgramCache; 377f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy PatchCache mPatchCache; 378bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer 379e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 3809d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer 381e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android 382e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 3839d5316e3f56d138504565ff311145ac01621dff4Romain Guy#endif // ANDROID_UI_OPENGL_RENDERER_H 384