OpenGLRenderer.h revision 735738c4ddf3229caa5f6e634bf591953ac29944
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 175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_OPENGL_RENDERER_H 185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_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 30daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h> 31bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h> 32ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h> 338694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h> 34bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 357953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h> 367953745dd565167113f8cbfc461bc0521d32d870Romain Guy 37c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h" 3851769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h" 39f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h" 405cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h" 41bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h" 425cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h" 43f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h" 4406f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h" 45db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h" 46fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h" 47bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 48e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android { 499d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer { 50e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 51f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 52f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer 53f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 54f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 550fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList; 56b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy 575cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 585cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a 595cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API. 605cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 6185bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer { 62e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic: 637953745dd565167113f8cbfc461bc0521d32d870Romain Guy ANDROID_API OpenGLRenderer(); 64e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual ~OpenGLRenderer(); 65e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 6617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 6787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy * Read externally defined properties to control the behavior 6887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy * of the renderer. 6987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy */ 7087e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy ANDROID_API void initProperties(); 7187e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 7287e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy /** 7317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Indicates whether this renderer executes drawing commands immediately. 7417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * If this method returns true, the drawing commands will be executed 7517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * later. 7617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 7749c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy virtual bool isDeferred(); 7849c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy 7917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 8017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Sets the dimension of the underlying drawing surface. This method must 8117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * be called at least once every time the drawing surface changes size. 8217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * 8317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param width The width in pixels of the underlysing surface 8417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param height The height in pixels of the underlysing surface 8517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 86b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy virtual void setViewport(int width, int height); 87e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy 8817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 8917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Prepares the renderer to draw a frame. This method must be invoked 9017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * at the beginning of each frame. When this method is invoked, the 9117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * entire drawing surface is assumed to be redrawn. 9217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * 9317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param opaque If true, the target surface is considered opaque 9417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * and will not be cleared. If false, the target surface 9517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * will be cleared 9617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 977c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy ANDROID_API status_t prepare(bool opaque); 9817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 9917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 10017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Prepares the renderer to draw a frame. This method must be invoked 10117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * at the beginning of each frame. Only the specified rectangle of the 10217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * frame is assumed to be dirty. A clip will automatically be set to 10317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * the specified rectangle. 10417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * 10517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param left The left coordinate of the dirty rectangle 10617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param top The top coordinate of the dirty rectangle 10717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param right The right coordinate of the dirty rectangle 10817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param bottom The bottom coordinate of the dirty rectangle 10917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * @param opaque If true, the target surface is considered opaque 11017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * and will not be cleared. If false, the target surface 11117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * will be cleared in the specified dirty rectangle 11217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 1137c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque); 114e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy 11517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 11617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Indicates the end of a frame. This method must be invoked whenever 11717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * the caller is done rendering a frame. 11817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 11917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy virtual void finish(); 1206c319ca1275c8db892c39b48fc54864c949f9171Romain Guy 121c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy /** 122c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * This method must be invoked before handing control over to a draw functor. 123c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * See callDrawGLFunction() for instance. 124c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * 125c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * This command must not be recorded inside display lists. 126c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy */ 127c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy virtual void interrupt(); 128c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy 129c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy /** 130c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * This method must be invoked after getting control back from a draw functor. 131c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * 132c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy * This command must not be recorded inside display lists. 133c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy */ 134c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy virtual void resume(); 135c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy 1368f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy ANDROID_API status_t invokeFunctors(Rect& dirty); 137ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy ANDROID_API void detachFunctor(Functor* functor); 138ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy ANDROID_API void attachFunctor(Functor* functor); 1398f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty); 14008ae317c21ec3086b5017672bba87420cc38a407Romain Guy 14111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy ANDROID_API void pushLayerUpdate(Layer* layer); 14211cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy ANDROID_API void clearLayerUpdates(); 14311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 1447953745dd565167113f8cbfc461bc0521d32d870Romain Guy ANDROID_API int getSaveCount() const; 1454aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual int save(int flags); 1464aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void restore(); 1474aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void restoreToCount(int saveCount); 148bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 149e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual int saveLayer(float left, float top, float right, float bottom, 1505c13d89c1332fcc499379b9064b891187b75ca32Chet Haase SkPaint* p, int flags); 151e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual int saveLayerAlpha(float left, float top, float right, float bottom, 152e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy int alpha, int flags); 153bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 1544aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void translate(float dx, float dy); 1554aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void rotate(float degrees); 1564aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void scale(float sx, float sy); 157807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy virtual void skew(float sx, float sy); 158f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 1597953745dd565167113f8cbfc461bc0521d32d870Romain Guy ANDROID_API void getMatrix(SkMatrix* matrix); 1604aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void setMatrix(SkMatrix* matrix); 1614aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void concatMatrix(SkMatrix* matrix); 162f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy 1637953745dd565167113f8cbfc461bc0521d32d870Romain Guy ANDROID_API const Rect& getClipBounds(); 1647953745dd565167113f8cbfc461bc0521d32d870Romain Guy ANDROID_API bool quickReject(float left, float top, float right, float bottom); 1658a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy bool quickRejectNoScissor(float left, float top, float right, float bottom); 1664aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); 167735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy virtual bool clipPath(SkPath* path, SkRegion::Op op); 168735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy virtual bool clipRegion(SkRegion* region, SkRegion::Op op); 169a23eed808a1ae4ec0d818c0a9238385e797fd056Chet Haase virtual Rect* getClipRect(); 170bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 1711271e2cc80b01d577e9db339459ef0222bb9320dChet Haase virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t flags, 1721271e2cc80b01d577e9db339459ef0222bb9320dChet Haase uint32_t level = 0); 173ed30fd8e9a2d65ee5c8520de55b0089c219f390cChet Haase virtual void outputDisplayList(DisplayList* displayList, uint32_t level = 0); 174486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawLayer(Layer* layer, float x, float y, SkPaint* paint); 175486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint); 176486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint); 177486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, 178e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy float srcRight, float srcBottom, float dstLeft, float dstTop, 1795c13d89c1332fcc499379b9064b891187b75ca32Chet Haase float dstRight, float dstBottom, SkPaint* paint); 180486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint); 181486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, 1825a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy float* vertices, int* colors, SkPaint* paint); 183486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, 1844bb942083a0d4db746adf95349108dd8ef842e32Romain Guy const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, 1855c13d89c1332fcc499379b9064b891187b75ca32Chet Haase float left, float top, float right, float bottom, SkPaint* paint); 186be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, 187be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, 188be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode); 189486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawColor(int color, SkXfermode::Mode mode); 190486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint); 191486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawRoundRect(float left, float top, float right, float bottom, 19201d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy float rx, float ry, SkPaint* paint); 193486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint); 194486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint); 195486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawArc(float left, float top, float right, float bottom, 1968b2f5267f16c295f12faab810527cd6311997e34Romain Guy float startAngle, float sweepAngle, bool useCenter, SkPaint* paint); 197486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawPath(SkPath* path, SkPaint* paint); 198486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawLines(float* points, int count, SkPaint* paint); 199486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawPoints(float* points, int count, SkPaint* paint); 200486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path, 201325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy float hOffset, float vOffset, SkPaint* paint); 202486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawPosText(const char* text, int bytesCount, int count, 203325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy const float* positions, SkPaint* paint); 204c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y, 205996e57c84368058be793897ebc355b917a59abc2Raph Levien const float* positions, SkPaint* paint, float length = -1.0f); 206672433d90fab7383cd28beac9d4485b566a90940Romain Guy virtual status_t drawRects(const float* rects, int count, SkPaint* paint); 20785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 2084aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void resetShader(); 2094aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void setupShader(SkiaShader* shader); 210d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 2114aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void resetColorFilter(); 2124aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void setupColorFilter(SkiaColorFilter* filter); 213db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy 2144aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void resetShadow(); 2154aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void setupShadow(float radius, float dx, float dy, int color); 2161e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 2175ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy virtual void resetPaintFilter(); 2185ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy virtual void setupPaintFilter(int clearBits, int setBits); 2195ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 2205ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy SkPaint* filterPaint(SkPaint* paint); 2215ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 222672433d90fab7383cd28beac9d4485b566a90940Romain Guy ANDROID_API bool isCurrentTransformSimple() { 223672433d90fab7383cd28beac9d4485b566a90940Romain Guy return mSnapshot->transform->isSimple(); 224672433d90fab7383cd28beac9d4485b566a90940Romain Guy } 225672433d90fab7383cd28beac9d4485b566a90940Romain Guy 22617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 22717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Sets the alpha on the current snapshot. This alpha value will be modulated 22817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * with other alpha values when drawing primitives. 22917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 23017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy void setAlpha(float alpha) { 23117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy mSnapshot->alpha = alpha; 23217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy } 23317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 23417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 23517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Inserts a named group marker in the stream of GL commands. This marker 23617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * can be used by tools to group commands into logical groups. A call to 23717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * this method must always be followed later on by a call to endMark(). 23817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 23913631f3da855f200a151e7837ed9f6b079622b58Romain Guy void startMark(const char* name) const; 24017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 24117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 24217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Closes the last group marker opened by startMark(). 24317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 24413631f3da855f200a151e7837ed9f6b079622b58Romain Guy void endMark() const; 24513631f3da855f200a151e7837ed9f6b079622b58Romain Guy 246d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase /** 247d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Gets the alpha and xfermode out of a paint object. If the paint is null 248d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * alpha will be 255 and the xfermode will be SRC_OVER. This method does 249d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * not multiply the paint's alpha by the current snapshot's alpha. 250d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * 251d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param paint The paint to extract values from 252d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param alpha Where to store the resulting alpha 253d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param mode Where to store the resulting xfermode 254d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase */ 255d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase static inline void getAlphaAndModeDirect(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) { 256d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase if (paint) { 257d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *mode = getXfermode(paint->getXfermode()); 258d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase 259d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase // Skia draws using the color's alpha channel if < 255 260d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase // Otherwise, it uses the paint's alpha 261d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase int color = paint->getColor(); 262d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *alpha = (color >> 24) & 0xFF; 263d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase if (*alpha == 255) { 264d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *alpha = paint->getAlpha(); 265d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } 266d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } else { 267d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *mode = SkXfermode::kSrcOver_Mode; 268d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *alpha = 255; 269d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } 270d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } 271d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase 272e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected: 273e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy /** 27435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Computes the projection matrix, initialize the first snapshot 27535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * and stores the dimensions of the render target. 27635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 27735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy void initViewport(int width, int height); 27835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 27935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 2807c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy * Clears the underlying surface if needed. 2817c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy */ 2827c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy virtual status_t clear(float left, float top, float right, float bottom, bool opaque); 2837c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 2847c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy /** 28535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Call this method after updating a layer during a drawing pass. 28635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 28735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy void resumeAfterLayer(); 28835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 28935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 290e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * Compose the layer defined in the current snapshot with the layer 291e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * defined by the previous snapshot. 292e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 293e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 294e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 295e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param curent The current snapshot containing the layer to compose 296e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param previous The previous snapshot to compose the current layer with 297e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy */ 298e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous); 299694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 300ada830f639591b99c3e40de22b07296c7932a33fRomain Guy /** 301f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Marks the specified region as dirty at the specified bounds. 302ada830f639591b99c3e40de22b07296c7932a33fRomain Guy */ 303f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayerUnchecked(Rect& bounds, Region* region); 304ada830f639591b99c3e40de22b07296c7932a33fRomain Guy 305ada830f639591b99c3e40de22b07296c7932a33fRomain Guy /** 306f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Returns the current snapshot. 307ada830f639591b99c3e40de22b07296c7932a33fRomain Guy */ 308f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy sp<Snapshot> getSnapshot() { 309f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return mSnapshot; 310f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 311ada830f639591b99c3e40de22b07296c7932a33fRomain Guy 31242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 31342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the region of the current layer. 31442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 315f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy virtual Region* getRegion() { 316f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return mSnapshot->region; 317f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 318f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 31942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 32042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Indicates whether rendering is currently targeted at a layer. 32142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 322f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy virtual bool hasLayer() { 323f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region; 324f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 3251bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy 32642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 32742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the name of the FBO this renderer is rendering into. 32842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 32942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy virtual GLint getTargetFbo() { 33042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy return 0; 33142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy } 33242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy 33377a811610f99e21da7f88dafef60d09f345d0506Romain Guy /** 33477a811610f99e21da7f88dafef60d09f345d0506Romain Guy * Renders the specified layer as a textured quad. 33577a811610f99e21da7f88dafef60d09f345d0506Romain Guy * 33677a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param layer The layer to render 33777a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param rect The bounds of the layer 33877a811610f99e21da7f88dafef60d09f345d0506Romain Guy */ 33977a811610f99e21da7f88dafef60d09f345d0506Romain Guy void drawTextureLayer(Layer* layer, const Rect& rect); 34077a811610f99e21da7f88dafef60d09f345d0506Romain Guy 341be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 342be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * Gets the alpha and xfermode out of a paint object. If the paint is null 343be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * alpha will be 255 and the xfermode will be SRC_OVER. 344be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * 345be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param paint The paint to extract values from 346be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param alpha Where to store the resulting alpha 347be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param mode Where to store the resulting xfermode 348be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 349be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode); 350be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 351be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 352be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * Safely retrieves the mode from the specified xfermode. If the specified 353be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode. 354be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 355be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy static inline SkXfermode::Mode getXfermode(SkXfermode* mode) { 356be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy SkXfermode::Mode resultMode; 357be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy if (!SkXfermode::AsMode(mode, &resultMode)) { 358be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy resultMode = SkXfermode::kSrcOver_Mode; 359be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy } 360be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy return resultMode; 361be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy } 362be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 36311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy /** 36411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy * Set to true to suppress error checks at the end of a frame. 36511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy */ 36611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy virtual bool suppressErrorChecks() { 36711cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy return false; 36811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy } 36911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 3707c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy Caches& getCaches() { 3717c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy return mCaches; 3727c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy } 3737c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 37408ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate: 3755cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 376dcfc836b457a87881da409e1acf251515f121446Romain Guy * Discards the content of the framebuffer if supported by the driver. 377dcfc836b457a87881da409e1acf251515f121446Romain Guy * This method should be called at the beginning of a frame to optimize 378dcfc836b457a87881da409e1acf251515f121446Romain Guy * rendering on some tiler architectures. 379dcfc836b457a87881da409e1acf251515f121446Romain Guy */ 380dcfc836b457a87881da409e1acf251515f121446Romain Guy void discardFramebuffer(float left, float top, float right, float bottom); 381dcfc836b457a87881da409e1acf251515f121446Romain Guy 382dcfc836b457a87881da409e1acf251515f121446Romain Guy /** 383ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * Ensures the state of the renderer is the same as the state of 384ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * the GL context. 385ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy */ 386ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy void syncState(); 387ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy 388ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy /** 3892b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 3902b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * This method needs to be invoked every time getTargetFbo() is 3912b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * bound again. 3922b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 39357b5268708c3b974296c7d4e58a02a957979224aRomain Guy void startTiling(const sp<Snapshot>& snapshot, bool opaque = false); 3942b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 3952b7028eabac80cec170572bc0e945a1d4224e595Romain Guy /** 3962b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU that we are done drawing the frame or that we 3972b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * are switching to another render target. 3982b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 3992b7028eabac80cec170572bc0e945a1d4224e595Romain Guy void endTiling(); 4002b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 4012b7028eabac80cec170572bc0e945a1d4224e595Romain Guy /** 4025cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Saves the current state of the renderer as a new snapshot. 4035cbbce535744b89df5ecea95de21ee3733298260Romain Guy * The new snapshot is saved in mSnapshot and the previous snapshot 4045cbbce535744b89df5ecea95de21ee3733298260Romain Guy * is linked from mSnapshot->previous. 4055cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 4068aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy * @param flags The save flags; see SkCanvas for more information 4078aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy * 4085cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @return The new save count. This value can be passed to #restoreToCount() 4095cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 4108aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy int saveSnapshot(int flags); 4115cbbce535744b89df5ecea95de21ee3733298260Romain Guy 4125cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 4135cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Restores the current snapshot; mSnapshot becomes mSnapshot->previous. 4145cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 4152542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy * @return True if the clip was modified. 4165cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 417bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy bool restoreSnapshot(); 418bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 4195cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 4205cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Sets the clipping rectangle using glScissor. The clip is defined by 4215cbbce535744b89df5ecea95de21ee3733298260Romain Guy * the current snapshot's clipRect member. 4225cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 423bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void setScissorFromClip(); 424bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 4255cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 42635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Performs a quick reject but does not affect the scissor. Returns 42735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * the transformed rect to test and the current clip. 42835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 42935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy bool quickRejectNoScissor(float left, float top, float right, float bottom, 43035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy Rect& transformed, Rect& clip); 43135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 43235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 433cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik * Performs a quick reject but adjust the bounds to account for stroke width if necessary 434cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik */ 435cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik bool quickRejectPreStroke(float left, float top, float right, float bottom, SkPaint* paint); 436cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik 437cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik /** 438d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Creates a new layer stored in the specified snapshot. 439d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 440d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param snapshot The snapshot associated with the new layer 441d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param left The left coordinate of the layer 442d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param top The top coordinate of the layer 443d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param right The right coordinate of the layer 444d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param bottom The bottom coordinate of the layer 445d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param alpha The translucency of the layer 446d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode of the layer 447d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param flags The layer save flags 448eb99356a0548684a501766e6a524529ab93304c8Romain Guy * @param previousFbo The name of the current framebuffer 449d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 450d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @return True if the layer was successfully created, false otherwise 451d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 452d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase bool createLayer(float left, float top, float right, float bottom, 453eb99356a0548684a501766e6a524529ab93304c8Romain Guy int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo); 454d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 455d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 4565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Creates a new layer stored in the specified snapshot as an FBO. 4575b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 4585b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to store as an FBO 4595b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param snapshot The snapshot associated with the new layer 4605b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param bounds The bounds of the layer 4615b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param previousFbo The name of the current framebuffer 4625b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 463d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip, GLuint previousFbo); 4645b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 4655b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 4665b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a region. 4675b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 4685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 4695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 4705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 4715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRegion(Layer* layer, const Rect& rect); 4725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 4735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 4745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a simple rectangle. 4755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 4765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 4775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 4785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param swap If true, the source and destination are swapped 4795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 4805b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false); 4815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 48254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 48354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Clears all the regions corresponding to the current list of layers. 48454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method MUST be invoked before any drawing operation. 48554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 48654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void clearLayerRegions(); 48754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 48854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 489f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. The coordinates 490f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * are transformed with the supplied matrix. 491f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 492f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 493f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom, const mat4 transform); 494f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 495f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 496f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. 497f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 498f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 499f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom); 500f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 501f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 5025cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a colored rectangle with the specified color. The specified coordinates 503735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * are transformed by the current snapshot's transform matrix unless specified 504735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * otherwise. 5055cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 5065cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 5075cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 5085cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 5095cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 5105cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param color The rectangle's ARGB color, defined as a packed 32 bits word 511026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param mode The Skia xfermode to use 5123d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy * @param ignoreTransform True if the current transform should be ignored 5135cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 514026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void drawColorRect(float left, float top, float right, float bottom, 5151c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy int color, SkXfermode::Mode mode, bool ignoreTransform = false); 5165cbbce535744b89df5ecea95de21ee3733298260Romain Guy 51754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 518735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * Draws a series of colored rectangles with the specified color. The specified 519735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * coordinates are transformed by the current snapshot's transform matrix unless 520735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * specified otherwise. 521735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * 522735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param rects A list of rectangles, 4 floats (left, top, right, bottom) 523735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * per rectangle 524735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param color The rectangles' ARGB color, defined as a packed 32 bits word 525735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param mode The Skia xfermode to use 526735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param ignoreTransform True if the current transform should be ignored 527735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy */ 528735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy status_t drawColorRects(const float* rects, int count, int color, 529735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy SkXfermode::Mode mode, bool ignoreTransform = false); 530735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy 531735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy /** 53254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the shape represented by the specified path texture. 53354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method invokes drawPathTexture() but takes into account 53454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * the extra left/top offset and the texture offset to correctly 53554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * position the final shape. 53654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 53754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The left coordinate of the shape to render 53854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The top coordinate of the shape to render 53954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture reprsenting the shape 54054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the shape with 54154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 542486590963e2207d68eebd6944fec70d50d41116aChet Haase status_t drawShape(float left, float top, const PathTexture* texture, SkPaint* paint); 54354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 54454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 54554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey 54654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * different compositing rules. 54754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 54854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to draw with 54954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The x coordinate of the bitmap 55054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The y coordinate of the bitmap 55154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to render with 55254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 553a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint); 554a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy 55554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 556710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * Renders the convex hull defined by the specified path as a strip of polygons. 55754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 558710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * @param path The hull of the path to draw 559cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik * @param paint The paint to render with 56054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 561cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik void drawConvexPath(const SkPath& path, SkPaint* paint); 562858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase 5635cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 5645cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 5655cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 5665cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 5675cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 5685cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 5695cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 5705cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 5715cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param texture The texture name to map onto the rectangle 5725cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 573d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode 574c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy * @param blend True if the texture contains an alpha channel 5755cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 576bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy void drawTextureRect(float left, float top, float right, float bottom, GLuint texture, 577a979474f15b454c8e2963f239a3770e200bb227cRomain Guy float alpha, SkXfermode::Mode mode, bool blend); 578c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 579026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy /** 58082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 58182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * are transformed by the current snapshot's transform matrix. 58282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 58382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 58482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 58582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 58682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 58782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture to use 58882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param paint The paint containing the alpha, blending mode, etc. 58982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 590a979474f15b454c8e2963f239a3770e200bb227cRomain Guy void drawTextureRect(float left, float top, float right, float bottom, 5918164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy Texture* texture, SkPaint* paint); 59282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 59382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy /** 59403750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * Draws a textured mesh with the specified texture. If the indices are omitted, 59503750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * the mesh is drawn as a simple quad. The mesh pointers become offsets when a 59603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * VBO is bound. 59782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 59882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 59982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 60082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 60182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 60282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture name to map onto the rectangle 60382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param alpha An additional translucency parameter, between 0.0f and 1.0f 60482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param mode The blending mode 60582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param blend True if the texture contains an alpha channel 60682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param vertices The vertices that define the mesh 60782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texCoords The texture coordinates of each vertex 60882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param elementsCount The number of elements in the mesh, required by indices 609f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param swapSrcDst Whether or not the src and dst blending operations should be swapped 610f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param ignoreTransform True if the current transform should be ignored 61103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * @param vbo The VBO used to draw the mesh 6125b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param ignoreScale True if the model view matrix should not be scaled 6135b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param dirty True if calling this method should dirty the current layer 614f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 615f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, 616a979474f15b454c8e2963f239a3770e200bb227cRomain Guy float alpha, SkXfermode::Mode mode, bool blend, 6176820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 6185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 6195b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy bool ignoreScale = false, bool dirty = true); 620f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 621886b275e529e44a59c54b933453d9bc902973178Romain Guy void drawAlpha8TextureMesh(float left, float top, float right, float bottom, 622886b275e529e44a59c54b933453d9bc902973178Romain Guy GLuint texture, bool hasColor, int color, int alpha, SkXfermode::Mode mode, 623886b275e529e44a59c54b933453d9bc902973178Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 624886b275e529e44a59c54b933453d9bc902973178Romain Guy bool ignoreTransform, bool dirty = true); 625886b275e529e44a59c54b933453d9bc902973178Romain Guy 626f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 6270a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * Draws text underline and strike-through if needed. 6280a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * 6290a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param text The text to decor 6300a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param bytesCount The number of bytes in the text 6310a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param length The length in pixels of the text, can be <= 0.0f to force a measurement 6320a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param x The x coordinate where the text will be drawn 6330a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param y The y coordinate where the text will be drawn 6340a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param paint The paint to draw the text with 6350a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy */ 6360a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy void drawTextDecorations(const char* text, int bytesCount, float length, 6370a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy float x, float y, SkPaint* paint); 6381e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 639416a847633680d94efb926837efdc18726d54918Raph Levien /** 640416a847633680d94efb926837efdc18726d54918Raph Levien * Draws shadow layer on text (with optional positions). 641416a847633680d94efb926837efdc18726d54918Raph Levien * 642416a847633680d94efb926837efdc18726d54918Raph Levien * @param paint The paint to draw the shadow with 643416a847633680d94efb926837efdc18726d54918Raph Levien * @param text The text to draw 644416a847633680d94efb926837efdc18726d54918Raph Levien * @param bytesCount The number of bytes in the text 645416a847633680d94efb926837efdc18726d54918Raph Levien * @param count The number of glyphs in the text 646416a847633680d94efb926837efdc18726d54918Raph Levien * @param positions The x, y positions of individual glyphs (or NULL) 647416a847633680d94efb926837efdc18726d54918Raph Levien * @param fontRenderer The font renderer object 648416a847633680d94efb926837efdc18726d54918Raph Levien * @param alpha The alpha value for drawing the shadow 649416a847633680d94efb926837efdc18726d54918Raph Levien * @param mode The xfermode for drawing the shadow 650416a847633680d94efb926837efdc18726d54918Raph Levien * @param x The x coordinate where the shadow will be drawn 651416a847633680d94efb926837efdc18726d54918Raph Levien * @param y The y coordinate where the shadow will be drawn 652416a847633680d94efb926837efdc18726d54918Raph Levien */ 653416a847633680d94efb926837efdc18726d54918Raph Levien void drawTextShadow(SkPaint* paint, const char* text, int bytesCount, int count, 654416a847633680d94efb926837efdc18726d54918Raph Levien const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode, 655416a847633680d94efb926837efdc18726d54918Raph Levien float x, float y); 656416a847633680d94efb926837efdc18726d54918Raph Levien 65754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 65854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws a path texture. Path textures are alpha8 bitmaps that need special 65954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * compositing to apply colors/filters/etc. 66054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 66154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to render 66254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param x The x coordinate where the texture will be drawn 66354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param y The y coordinate where the texture will be drawn 66454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the texture with 66554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 666416a847633680d94efb926837efdc18726d54918Raph Levien void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint); 66701d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy 6681e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy /** 669ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Resets the texture coordinates stored in mMeshVertices. Setting the values 670026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * back to default is achieved by calling: 671026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 6728ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 673026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 674026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u1 The left coordinate of the texture 675026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v1 The bottom coordinate of the texture 676026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u2 The right coordinate of the texture 677026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v2 The top coordinate of the texture 678026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 679026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 680026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 6818ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy /** 682746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Binds the specified texture. The texture unit must have been selected 683746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * prior to calling this method. 684a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy */ 685746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void bindTexture(GLuint texture) { 686746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy glBindTexture(GL_TEXTURE_2D, texture); 687746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 688746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 689746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 690aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Binds the specified EGLImage texture. The texture unit must have been selected 691aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * prior to calling this method. 692aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 693aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy inline void bindExternalTexture(GLuint texture) { 694aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture); 695aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy } 696aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 697aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 69882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Enable or disable blending as necessary. This function sets the appropriate 69982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * blend function based on the specified xfermode. 70082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 701f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description, 702f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy bool swapSrcDst = false); 703a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy 704f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy /** 705d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Use the specified program with the current GL context. If the program is already 706d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * in use, it will not be bound again. If it is not in use, the current program is 707d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * marked unused and the specified program becomes used and becomes the new 708d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * current program. 7096926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy * 710d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param program The program to use 711d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 712d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @return true If the specified program was already in use, false otherwise. 713260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy */ 714889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy inline bool useProgram(Program* program); 715260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy 716746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 717746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Invoked before any drawing operation. This sets required state. 718746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 71954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void setupDraw(bool clear = true); 72017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 72170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy /** 72270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy * Various methods to setup OpenGL rendering. 72370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy */ 72470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawWithTexture(bool isAlpha8 = false); 725aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawWithExternalTexture(); 72615bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy void setupDrawNoTexture(); 727710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik void setupDrawAA(); 728710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik void setupDrawVertexShape(); 729ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy void setupDrawPoint(float pointSize); 7308d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy void setupDrawColor(int color, int alpha); 73170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColor(float r, float g, float b, float a); 73286568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawAlpha8Color(int color, int alpha); 7334121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGamma(const SkPaint* paint); 73470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawShader(); 73570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColorFilter(); 73670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode, 73770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool swapSrcDst = false); 73870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode, 73970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool swapSrcDst = false); 74070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawProgram(); 74170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawDirtyRegionsDisabled(); 7428a5cc92a150bae38ec43732d941b38bb381fe153Chet Haase void setupDrawModelViewIdentity(bool offset = false); 74370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawModelView(float left, float top, float right, float bottom, 74470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool ignoreTransform = false, bool ignoreModelView = false); 74570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawModelViewTranslate(float left, float top, float right, float bottom, 74670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool ignoreTransform = false); 747ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy void setupDrawPointUniforms(); 74870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColorUniforms(); 74986568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawPureColorUniforms(); 7508d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy void setupDrawShaderIdentityUniforms(); 75170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawShaderUniforms(bool ignoreTransform = false); 75270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColorFilterUniforms(); 75370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawSimpleMesh(); 75470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawTexture(GLuint texture); 755aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawExternalTexture(GLuint texture); 7568f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransform(); 7578f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransformUniforms(mat4& transform); 7584121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGammaUniforms(); 7598d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0); 76015bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords); 7615b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase void setupDrawVertices(GLvoid* vertices); 76299585adeb4167ca357a72eb866f34c1af944f4b9Chet Haase void setupDrawAALine(GLvoid* vertices, GLvoid* distanceCoords, GLvoid* lengthCoords, 7637b63142d2f4bc32beacedcc761453b8aea1f3a86Romain Guy float strokeWidth, int& widthSlot, int& lengthSlot); 7647b63142d2f4bc32beacedcc761453b8aea1f3a86Romain Guy void finishDrawAALine(const int widthSlot, const int lengthSlot); 76570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void finishDrawTexture(); 766f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy void accountForClear(SkXfermode::Mode mode); 767746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 76811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy bool updateLayer(Layer* layer, bool inFrame); 76911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy void updateLayers(); 77011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 77117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 77217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Renders the specified region as a series of rectangles. This method 77317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * is used for debugging only. 77417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 7753a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy void drawRegionRects(const Region& region); 7763a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy 7777c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void debugOverdraw(bool enable, bool clear); 7787c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void renderOverdraw(); 7797c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy 780746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 781746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Should be invoked every time the glScissor is modified. 782746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 783746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void dirtyClip() { 784746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy mDirtyClip = true; 785746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 786746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 787bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Dimensions of the drawing surface 788bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int mWidth, mHeight; 789bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 79085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy // Matrix used for ortho projection in shaders 791260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy mat4 mOrthoMatrix; 792bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 793c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy // Model-view matrix used to position/size objects 794c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy mat4 mModelView; 795c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 796bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Number of saved states 797bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy int mSaveCount; 798f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy // Base state 799ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy sp<Snapshot> mFirstSnapshot; 800bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // Current state 801bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy sp<Snapshot> mSnapshot; 8022b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // State used to define the clipping region 8032b7028eabac80cec170572bc0e945a1d4224e595Romain Guy sp<Snapshot> mTilingSnapshot; 8049d5316e3f56d138504565ff311145ac01621dff4Romain Guy 8059d5316e3f56d138504565ff311145ac01621dff4Romain Guy // Shaders 80606f96e2652e4855b6520ad9dd70583677605b79aRomain Guy SkiaShader* mShader; 807026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 808db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy // Color filters 809db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy SkiaColorFilter* mColorFilter; 810db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy 811026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy // Used to draw textured quads 812ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy TextureVertex mMeshVertices[4]; 813ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 8141e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy // Drop shadow 8151e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy bool mHasShadow; 8161e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy float mShadowRadius; 8171e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy float mShadowDx; 8181e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy float mShadowDy; 8191e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy int mShadowColor; 8201e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 8215ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy // Draw filters 8225ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy bool mHasDrawFilter; 8235ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy int mPaintFilterClearBits; 8245ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy int mPaintFilterSetBits; 8255ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy SkPaint mFilteredPaint; 8265ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 82782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Various caches 828fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy Caches& mCaches; 8298694230ff25fa0a60e480d424843e56b718f0516Romain Guy 8308f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy // List of rectangles to clear after saveLayer() is invoked 83154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy Vector<Rect*> mLayers; 8328f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy // List of functors to invoke after a frame is drawn 833ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy SortedVector<Functor*> mFunctors; 83411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy // List of layers to update at the beginning of a frame 83511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy Vector<Layer*> mLayerUpdates; 83654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 83799bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy // Indentity matrix 83899bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy const mat4 mIdentity; 83999bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy 840746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy // Indicates whether the clip must be restored 841746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy bool mDirtyClip; 842746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 84370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // The following fields are used to setup drawing 84470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Used to describe the shaders to generate 84570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy ProgramDescription mDescription; 84670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Color description 84770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mColorSet; 84870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy float mColorA, mColorR, mColorG, mColorB; 84970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Indicates that the shader should get a color 85070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mSetShaderColor; 85170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Current texture unit 85270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy GLuint mTextureUnit; 85370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Track dirty regions, true by default 85470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mTrackDirtyRegions; 8552b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // Indicate whether we are drawing an opaque frame 8562b7028eabac80cec170572bc0e945a1d4224e595Romain Guy bool mOpaqueFrame; 85770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy 85887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in 85987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // Properties.h 86087e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy bool mScissorOptimizationDisabled; 86187e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 86254c1a64d5441a964890b44280e4457e11f4f924aRomain Guy // No-ops start/endTiling when set 86354c1a64d5441a964890b44280e4457e11f4f924aRomain Guy bool mSuppressTiling; 86454c1a64d5441a964890b44280e4457e11f4f924aRomain Guy 865b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy friend class DisplayListRenderer; 866b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy 867bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer 868e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 8699d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer 870e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android 871e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 8725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H 873