OpenGLRenderer.h revision 51769a68a5cb34e9564740c6a854fcb93018789d
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" 44bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 45e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android { 469d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer { 47e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 48f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 49f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Support 50f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 51f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 525cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 53026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * Structure mapping Skia xfermodes to OpenGL blending factors. 54026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 55026c5e16704e817cac7d9c382914c947e34f87e0Romain Guystruct Blender { 56026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy SkXfermode::Mode mode; 57026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy GLenum src; 58026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy GLenum dst; 59026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy}; // struct Blender 60026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 61f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 62f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer 63f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 64f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 655cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 665cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a 675cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API. 685cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 6985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer { 70e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic: 7185bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy OpenGLRenderer(); 7285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy ~OpenGLRenderer(); 73e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 74e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy void setViewport(int width, int height); 75e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy void prepare(); 7608ae317c21ec3086b5017672bba87420cc38a407Romain Guy 77bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int getSaveCount() const; 78bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int save(int flags); 79bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void restore(); 80bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void restoreToCount(int saveCount); 81bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 82bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy int saveLayer(float left, float top, float right, float bottom, const SkPaint* p, int flags); 83bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int flags); 84bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 85f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void translate(float dx, float dy); 86f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void rotate(float degrees); 87f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void scale(float sx, float sy); 88f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 89f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void setMatrix(SkMatrix* matrix); 90f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void getMatrix(SkMatrix* matrix); 91f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void concatMatrix(SkMatrix* matrix); 92f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 939d5316e3f56d138504565ff311145ac01621dff4Romain Guy const Rect& getClipBounds(); 94c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy bool quickReject(float left, float top, float right, float bottom); 95079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); 96bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 97c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy void drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint); 98f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy void drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint); 998ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, 100f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint); 101deba785f122a47915756ffd991f5540d952cf937Romain Guy void drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, float left, float top, 102deba785f122a47915756ffd991f5540d952cf937Romain Guy float right, float bottom, const SkPaint* paint); 10385bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy void drawColor(int color, SkXfermode::Mode mode); 104bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy void drawRect(float left, float top, float right, float bottom, const SkPaint* paint); 10585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 106d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy void resetShader(); 107d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy void setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tileX, SkShader::TileMode tileY, 108d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy SkMatrix* matrix, bool hasAlpha); 109f9764a4f532561f6e2e985ff3b25112f1132ce44Romain Guy void setupLinearGradientShader(SkShader* shader, float* bounds, uint32_t* colors, 110c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy float* positions, int count, SkShader::TileMode tileMode, 111c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy SkMatrix* matrix, bool hasAlpha); 112d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 113694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy void drawText(const char* text, int count, float x, float y, SkPaint* paint); 114694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 11508ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate: 1165cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 117d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Type of Skia shader in use. 118d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy */ 119d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy enum ShaderType { 120d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderNone, 121d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderBitmap, 122d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderLinearGradient, 123d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderCircularGradient, 124d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy kShaderSweepGradient 125d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy }; 126d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 127d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy /** 1285cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Saves the current state of the renderer as a new snapshot. 1295cbbce535744b89df5ecea95de21ee3733298260Romain Guy * The new snapshot is saved in mSnapshot and the previous snapshot 1305cbbce535744b89df5ecea95de21ee3733298260Romain Guy * is linked from mSnapshot->previous. 1315cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1325cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @return The new save count. This value can be passed to #restoreToCount() 1335cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 134bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int saveSnapshot(); 1355cbbce535744b89df5ecea95de21ee3733298260Romain Guy 1365cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 1375cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Restores the current snapshot; mSnapshot becomes mSnapshot->previous. 1385cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1395cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @return True if the clip should be also reapplied by calling 1405cbbce535744b89df5ecea95de21ee3733298260Romain Guy * #setScissorFromClip(). 1415cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 142bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy bool restoreSnapshot(); 143bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 1445cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 1455cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Sets the clipping rectangle using glScissor. The clip is defined by 1465cbbce535744b89df5ecea95de21ee3733298260Romain Guy * the current snapshot's clipRect member. 1475cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 148bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void setScissorFromClip(); 149bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 1505cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 151d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Compose the layer defined in the current snapshot with the layer 152d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * defined by the previous snapshot. 153d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 154d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 155d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 156d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param curent The current snapshot containing the layer to compose 157d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param previous The previous snapshot to compose the current layer with 158d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 159d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy void composeLayer(sp<Snapshot> current, sp<Snapshot> previous); 160d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 161d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 162d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Creates a new layer stored in the specified snapshot. 163d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 164d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param snapshot The snapshot associated with the new layer 165d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param left The left coordinate of the layer 166d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param top The top coordinate of the layer 167d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param right The right coordinate of the layer 168d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param bottom The bottom coordinate of the layer 169d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param alpha The translucency of the layer 170d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode of the layer 171d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param flags The layer save flags 172d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 173d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @return True if the layer was successfully created, false otherwise 174d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 175d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom, 176d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy int alpha, SkXfermode::Mode mode, int flags); 177d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 178d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 1795cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a colored rectangle with the specified color. The specified coordinates 1805cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 1815cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1825cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 1835cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 1845cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 1855cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 1865cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param color The rectangle's ARGB color, defined as a packed 32 bits word 187026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param mode The Skia xfermode to use 1883d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy * @param ignoreTransform True if the current transform should be ignored 1895cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 190026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void drawColorRect(float left, float top, float right, float bottom, 1913d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy int color, SkXfermode::Mode mode, bool ignoreTransform = false); 1925cbbce535744b89df5ecea95de21ee3733298260Romain Guy 1935cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 1945cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 1955cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 1965cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 1975cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 1985cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 1995cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 2005cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 2015cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param texture The texture name to map onto the rectangle 2025cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 203d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode 204c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy * @param blend True if the texture contains an alpha channel 2055cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 206bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy void drawTextureRect(float left, float top, float right, float bottom, GLuint texture, 207a979474f15b454c8e2963f239a3770e200bb227cRomain Guy float alpha, SkXfermode::Mode mode, bool blend); 208c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 209026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy /** 21082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 21182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * are transformed by the current snapshot's transform matrix. 21282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 21382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 21482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 21582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 21682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 21782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture to use 21882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param paint The paint containing the alpha, blending mode, etc. 21982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 220a979474f15b454c8e2963f239a3770e200bb227cRomain Guy void drawTextureRect(float left, float top, float right, float bottom, 221a979474f15b454c8e2963f239a3770e200bb227cRomain Guy const Texture* texture, const SkPaint* paint); 22282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 22382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy /** 22482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Draws a textured mesh with the specified texture. If the indices are omitted, the 22582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * mesh is drawn as a simple quad. 22682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 22782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 22882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 22982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 23082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 23182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture name to map onto the rectangle 23282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 23382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param mode The blending mode 23482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param blend True if the texture contains an alpha channel 23582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param vertices The vertices that define the mesh 23682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texCoords The texture coordinates of each vertex 23782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param indices The indices of the vertices, can be NULL 23882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param elementsCount The number of elements in the mesh, required by indices 239f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 240f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, 241a979474f15b454c8e2963f239a3770e200bb227cRomain Guy float alpha, SkXfermode::Mode mode, bool blend, 242f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy GLvoid* vertices, GLvoid* texCoords, GLvoid* indices, GLsizei elementsCount = 0); 243f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 244f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 245d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Fills the specified rectangle with the currently set bitmap shader. 246d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 247d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param left The left coordinate of the rectangle 248d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param top The top coordinate of the rectangle 249d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param right The right coordinate of the rectangle 250d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param bottom The bottom coordinate of the rectangle 251d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 252d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param mode The blending mode 253d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy */ 254d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy void drawBitmapShader(float left, float top, float right, float bottom, float alpha, 255d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy SkXfermode::Mode mode); 256d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 257d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy /** 258c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * Fills the specified rectangle with the currently set linear gradient shader. 259c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * 260c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param left The left coordinate of the rectangle 261c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param top The top coordinate of the rectangle 262c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param right The right coordinate of the rectangle 263c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param bottom The bottom coordinate of the rectangle 264c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 265c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * @param mode The blending mode 266c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy */ 267c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy void drawLinearGradientShader(float left, float top, float right, float bottom, float alpha, 268c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy SkXfermode::Mode mode); 269c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy 270c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy /** 271026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * Resets the texture coordinates stored in mDrawTextureVertices. Setting the values 272026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * back to default is achieved by calling: 273026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 2748ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 275026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 276026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u1 The left coordinate of the texture 277026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v1 The bottom coordinate of the texture 278026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u2 The right coordinate of the texture 279026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v2 The top coordinate of the texture 280026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 281026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 282026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 2838ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy /** 2848ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * Gets the alpha and xfermode out of a paint object. If the paint is null 2858ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * alpha will be 255 and the xfermode will be SRC_OVER. 2868ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * 2878ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * @param paint The paint to extract values from 2888ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * @param alpha Where to store the resulting alpha 2898ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * @param mode Where to store the resulting xfermode 2908ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy */ 2918ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode); 2928ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy 293f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 294a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy * Binds the specified texture with the specified wrap modes. 295a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy */ 296a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy inline void bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT); 297a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy 298a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy /** 29982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Enable or disable blending as necessary. This function sets the appropriate 30082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * blend function based on the specified xfermode. 30182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 302a979474f15b454c8e2963f239a3770e200bb227cRomain Guy inline void chooseBlending(bool blend, SkXfermode::Mode mode, bool isPremultiplied = true); 30382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 304260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy /** 305d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Use the specified program with the current GL context. If the program is already 306d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * in use, it will not be bound again. If it is not in use, the current program is 307d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * marked unused and the specified program becomes used and becomes the new 308d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * current program. 3096926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy * 310d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param program The program to use 311d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 312d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @return true If the specified program was already in use, false otherwise. 313260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy */ 314d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy inline bool useProgram(const sp<Program>& program); 315260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy 316bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Dimensions of the drawing surface 317bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int mWidth, mHeight; 318bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 31985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy // Matrix used for ortho projection in shaders 320260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy mat4 mOrthoMatrix; 321bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 322c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy // Model-view matrix used to position/size objects 323c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy mat4 mModelView; 324c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 325bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Number of saved states 326bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int mSaveCount; 327f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy // Base state 328f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy Snapshot mFirstSnapshot; 329bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Current state 330bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy sp<Snapshot> mSnapshot; 3319d5316e3f56d138504565ff311145ac01621dff4Romain Guy 3329d5316e3f56d138504565ff311145ac01621dff4Romain Guy // Shaders 333d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy sp<Program> mCurrentProgram; 334d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy sp<DrawColorProgram> mDrawColorProgram; 335d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy sp<DrawTextureProgram> mDrawTextureProgram; 336694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy sp<DrawTextProgram> mDrawTextProgram; 337f9764a4f532561f6e2e985ff3b25112f1132ce44Romain Guy sp<DrawLinearGradientProgram> mDrawLinearGradientProgram; 338026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 339026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy // Used to draw textured quads 340026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy TextureVertex mDrawTextureVertices[4]; 341ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 3421e79386ba34f0db38c1b35b22cdf122632534354Romain Guy // Current texture state 3431e79386ba34f0db38c1b35b22cdf122632534354Romain Guy GLuint mLastTexture; 3441e79386ba34f0db38c1b35b22cdf122632534354Romain Guy 34582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Last known blend state 34682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy bool mBlend; 34782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy GLenum mLastSrcMode; 34882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy GLenum mLastDstMode; 34982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 3507fac2e18339f765320d759e8d4c090f92431959eRomain Guy // Skia shaders 351d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy ShaderType mShader; 352f9764a4f532561f6e2e985ff3b25112f1132ce44Romain Guy SkShader* mShaderKey; 353d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy bool mShaderBlend; 354a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy GLenum mShaderTileX; 355a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy GLenum mShaderTileY; 356d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy SkMatrix* mShaderMatrix; 3577fac2e18339f765320d759e8d4c090f92431959eRomain Guy // Bitmaps 3587fac2e18339f765320d759e8d4c090f92431959eRomain Guy SkBitmap* mShaderBitmap; 3597fac2e18339f765320d759e8d4c090f92431959eRomain Guy // Gradients 3607fac2e18339f765320d759e8d4c090f92431959eRomain Guy float* mShaderBounds; 3617fac2e18339f765320d759e8d4c090f92431959eRomain Guy uint32_t* mShaderColors; 3627fac2e18339f765320d759e8d4c090f92431959eRomain Guy float* mShaderPositions; 363c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy int mShaderCount; 364d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 36551769a68a5cb34e9564740c6a854fcb93018789dRomain Guy // GL extensions 36651769a68a5cb34e9564740c6a854fcb93018789dRomain Guy Extensions mExtensions; 36751769a68a5cb34e9564740c6a854fcb93018789dRomain Guy 368694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy // Font renderer 369694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy FontRenderer mFontRenderer; 370694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 37182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Various caches 372ce0537b80087a6225273040a987414b1dd081aa0Romain Guy TextureCache mTextureCache; 373dda570201ac851dd85af3861f7e575721d3345daRomain Guy LayerCache mLayerCache; 374c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy GradientCache mGradientCache; 375f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy PatchCache mPatchCache; 376bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer 377e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 3789d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer 379e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android 380e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 3819d5316e3f56d138504565ff311145ac01621dff4Romain Guy#endif // ANDROID_UI_OPENGL_RENDERER_H 382