OpenGLRenderer.h revision 107843de4507b3511006cb9c77b8d0364374385a
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> 2476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger#include <SkCanvas.h> 2576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger#include <SkColorFilter.h> 26f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h> 27ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h> 28079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h> 2985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h> 30e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 31c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger#include <utils/Blur.h> 32daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h> 33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h> 34ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h> 358694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h> 36bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 377953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h> 387953745dd565167113f8cbfc461bc0521d32d870Romain Guy 393b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include <androidfw/ResourceTypes.h> 403b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 41c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h" 4251769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h" 43f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h" 445cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h" 45bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h" 46b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Snapshot.h" 47d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III#include "StatefulBaseRenderer.h" 483b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include "UvMapper.h" 49b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Vertex.h" 50fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h" 51bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 52d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins IIIclass SkShader; 53d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III 54e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android { 559d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer { 56e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 57b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DeferredDisplayState; 583b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState; 59e18264b079481a244b30e3f71012c53bbd861f92John Reckclass RenderNode; 60b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass TextSetupFunctor; 61b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass VertexBuffer; 62b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik 63c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers { 649b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy DrawModifiers() { 659b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy reset(); 669b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy } 679b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy 689b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy void reset() { 699b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy memset(this, 0, sizeof(DrawModifiers)); 709b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy } 719b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy 7216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik float mOverrideLayerAlpha; 73c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik}; 74c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 75ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags { 76ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik kStateDeferFlag_Draw = 0x1, 77ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik kStateDeferFlag_Clip = 0x2 78ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik}; 79ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik 8028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags { 81a02c4ed885d97e516f844ddb0a96083f1b45b4cbChris Craik kClipSide_None = 0x0, 8228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Left = 0x1, 8328ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Top = 0x2, 8428ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Right = 0x4, 8528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Bottom = 0x8, 86d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik kClipSide_Full = 0xF, 87d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik kClipSide_ConservativeFull = 0x1F 8828ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik}; 8928ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik 90bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craikenum VertexBufferDisplayFlags { 91bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik kVertexBuffer_Offset = 0x1, 9291a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik kVertexBuffer_ShadowInterp = 0x2, 93bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik}; 94bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik 954063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik/** 964063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Defines additional transformation that should be applied by the model view matrix, beyond that of 974063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * the currentTransform() 984063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 994063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craikenum ModelViewMode { 1004063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 1014063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used when the model view should simply translate geometry passed to the shader. The resulting 1024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * matrix will be a simple translation. 1034063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1044063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik kModelViewMode_Translate = 0, 1054063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 1064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 1074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used when the model view should translate and scale geometry. The resulting matrix will be a 1084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect. 1094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1104063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik kModelViewMode_TranslateAndScale = 1, 1114063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik}; 1124063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 113f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 114f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer 115f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 1165cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 11714e513058ed4168c94e015638d16f5f87fd8063aChris Craik * OpenGL Renderer implementation. 1185cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 11914e513058ed4168c94e015638d16f5f87fd8063aChris Craikclass OpenGLRenderer : public StatefulBaseRenderer { 120e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic: 1213b20251a355c88193c439f928a84ae69483fb488John Reck OpenGLRenderer(RenderState& renderState); 122e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual ~OpenGLRenderer(); 123e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 1243b20251a355c88193c439f928a84ae69483fb488John Reck void initProperties(); 125058fc640017c90120c599d378a4cbc55668b05b7Chris Craik void initLight(const Vector3& lightCenter, float lightRadius, 126058fc640017c90120c599d378a4cbc55668b05b7Chris Craik uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); 12787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 128797b95b26bbb7557678af78b9a2a61830158920fChris Craik virtual void onViewportInitialized(); 129107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); 130107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual bool finish(); 131c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy 132107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void callDrawGLFunction(Functor* functor, Rect& dirty); 13308ae317c21ec3086b5017672bba87420cc38a407Romain Guy 1343b20251a355c88193c439f928a84ae69483fb488John Reck void pushLayerUpdate(Layer* layer); 1353b20251a355c88193c439f928a84ae69483fb488John Reck void cancelLayerUpdate(Layer* layer); 1363b20251a355c88193c439f928a84ae69483fb488John Reck void flushLayerUpdates(); 137443a714fa7c0dd07fee3527cc5bc3d3ca1fb7d44John Reck void markLayersAsBuildLayers(); 13811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 1393b20251a355c88193c439f928a84ae69483fb488John Reck virtual int saveLayer(float left, float top, float right, float bottom, 1403f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPaint* paint, int flags) { 1413f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik return saveLayer(left, top, right, bottom, paint, flags, NULL); 1423f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik } 1433f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 1443f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if 1453f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // created, which will in turn clip to that mask when drawn back/restored. 1463f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik int saveLayer(float left, float top, float right, float bottom, 1473f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPaint* paint, int flags, const SkPath* convexMask); 148bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 149d90144db52c7297879b950cbbc85137ed123ab5bChris Craik int saveLayerDeferred(float left, float top, float right, float bottom, 150d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger const SkPaint* paint, int flags); 151d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 152107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1); 153107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawLayer(Layer* layer, float x, float y); 154107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint); 155107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount, 156d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint); 157107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop, 158e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy float srcRight, float srcBottom, float dstLeft, float dstTop, 159d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float dstRight, float dstBottom, const SkPaint* paint); 160107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint); 161107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight, 162d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* vertices, const int* colors, const SkPaint* paint); 163107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry, 164d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint); 165107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, 166d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float left, float top, float right, float bottom, const SkPaint* paint); 167107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry, 168d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float left, float top, float right, float bottom, const SkPaint* paint); 169107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawColor(int color, SkXfermode::Mode mode); 170107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRect(float left, float top, float right, float bottom, 171d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 172107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRoundRect(float left, float top, float right, float bottom, 173d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float rx, float ry, const SkPaint* paint); 174107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawCircle(float x, float y, float radius, const SkPaint* paint); 175107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawOval(float left, float top, float right, float bottom, 176d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 177107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawArc(float left, float top, float right, float bottom, 178d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint); 179107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPath(const SkPath* path, const SkPaint* paint); 180107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawLines(const float* points, int count, const SkPaint* paint); 181107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPoints(const float* points, int count, const SkPaint* paint); 182107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path, 183d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float hOffset, float vOffset, const SkPaint* paint); 184107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPosText(const char* text, int bytesCount, int count, 185d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* positions, const SkPaint* paint); 186107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawText(const char* text, int bytesCount, int count, float x, float y, 187d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds, 188527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik DrawOpMode drawOpMode = kDrawOpMode_Immediate); 189107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRects(const float* rects, int count, const SkPaint* paint); 19085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 191107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawShadow(float casterAlpha, 19205f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik const VertexBuffer* ambientShadowVertexBuffer, const VertexBuffer* spotShadowVertexBuffer); 193f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik 19409c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger virtual void setDrawFilter(SkDrawFilter* filter); 1955ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 19616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer) 19716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; } 19816ecda5317c40fc3da284952d9b3add34d6763aeChris Craik 1995e49b307eb99269db2db257760508b8efd7bb97dChris Craik /** 2005e49b307eb99269db2db257760508b8efd7bb97dChris Craik * Store the current display state (most importantly, the current clip and transform), and 2015e49b307eb99269db2db257760508b8efd7bb97dChris Craik * additionally map the state's bounds from local to window coordinates. 2025e49b307eb99269db2db257760508b8efd7bb97dChris Craik * 2035e49b307eb99269db2db257760508b8efd7bb97dChris Craik * Returns true if quick-rejected 2045e49b307eb99269db2db257760508b8efd7bb97dChris Craik */ 205ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags); 206527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false); 20728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik void setupMergedMultiDraw(const Rect* clipRect); 208c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 209d90144db52c7297879b950cbbc85137ed123ab5bChris Craik const DrawModifiers& getDrawModifiers() { return mDrawModifiers; } 210d90144db52c7297879b950cbbc85137ed123ab5bChris Craik void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; } 211d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 2123b20251a355c88193c439f928a84ae69483fb488John Reck bool isCurrentTransformSimple() { 213d6b65f67717025b1162f86f04e2caa5723566cacChris Craik return currentTransform()->isSimple(); 214672433d90fab7383cd28beac9d4485b566a90940Romain Guy } 215672433d90fab7383cd28beac9d4485b566a90940Romain Guy 2160f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy Caches& getCaches() { 2170f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy return mCaches; 2180f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy } 2190f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy 220ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik // simple rect clip 221ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik bool isCurrentClipSimple() { 222ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik return mSnapshot->clipRegion->isEmpty(); 223ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik } 224ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik 225a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik int getViewportWidth() { return currentSnapshot()->getViewportWidth(); } 226a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik int getViewportHeight() { return currentSnapshot()->getViewportHeight(); } 2270e87f00f8cb79635aa70b9a2dfa02bf19dc7473dChris Craik 22817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 229a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik * Scales the alpha on the current snapshot. This alpha value will be modulated 23017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * with other alpha values when drawing primitives. 23117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 232a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik void scaleAlpha(float alpha) { 233a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik mSnapshot->alpha *= alpha; 23417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy } 23517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 23617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 2370f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy * Inserts a named event marker in the stream of GL commands. 2380f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy */ 2390f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy void eventMark(const char* name) const; 2400f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy 2410f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy /** 24262d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik * Inserts a formatted event marker in the stream of GL commands. 24362d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik */ 24462d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik void eventMarkDEBUG(const char *fmt, ...) const; 24562d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik 24662d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik /** 24717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Inserts a named group marker in the stream of GL commands. This marker 24817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * can be used by tools to group commands into logical groups. A call to 24917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * this method must always be followed later on by a call to endMark(). 25017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 25113631f3da855f200a151e7837ed9f6b079622b58Romain Guy void startMark(const char* name) const; 25217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 25317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 25417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Closes the last group marker opened by startMark(). 25517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 25613631f3da855f200a151e7837ed9f6b079622b58Romain Guy void endMark() const; 25713631f3da855f200a151e7837ed9f6b079622b58Romain Guy 258d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase /** 259d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Gets the alpha and xfermode out of a paint object. If the paint is null 260d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * alpha will be 255 and the xfermode will be SRC_OVER. This method does 26116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * not multiply the paint's alpha by the current snapshot's alpha, and does 26216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * not replace the alpha with the overrideLayerAlpha 263d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * 264d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param paint The paint to extract values from 265d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param alpha Where to store the resulting alpha 266d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param mode Where to store the resulting xfermode 267d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase */ 268d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) { 269527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik *mode = getXfermodeDirect(paint); 270527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik *alpha = getAlphaDirect(paint); 271527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 272527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 273d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) { 274527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (!paint) return SkXfermode::kSrcOver_Mode; 275527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik return getXfermode(paint->getXfermode()); 276527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 277527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 278c1c5f0870282b56dafe5a4d756e4b9e6884655a7Chris Craik static inline int getAlphaDirect(const SkPaint* paint) { 279527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (!paint) return 255; 280527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik return paint->getAlpha(); 281d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } 282d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase 283c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger struct TextShadow { 284c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger SkScalar radius; 285c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger float dx; 286c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger float dy; 287c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger SkColor color; 288c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger }; 289c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger 290c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger static inline bool getTextShadow(const SkPaint* paint, TextShadow* textShadow) { 291c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger SkDrawLooper::BlurShadowRec blur; 292c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger if (paint && paint->getLooper() && paint->getLooper()->asABlurShadow(&blur)) { 293c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger if (textShadow) { 294c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->radius = Blur::convertSigmaToRadius(blur.fSigma); 295c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->dx = blur.fOffset.fX; 296c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->dy = blur.fOffset.fY; 297c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->color = blur.fColor; 298c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 299c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger return true; 300c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 301c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger return false; 302c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 303c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger 304c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger static inline bool hasTextShadow(const SkPaint* paint) { 305c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger return getTextShadow(paint, NULL); 306c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 307c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger 308624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy /** 30959744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * Build the best transform to use to rasterize text given a full 31059744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * transform matrix, and whether filteration is needed. 31159744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * 31259744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * Returns whether filtration is needed 313624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy */ 31459744b79ec302000802cd56d30a1bf70f0183c80Chris Craik bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const; 315624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy 316527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR 317527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) { 318527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik mCaches.setScissorEnabled(false); 319527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 320527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik // should only be called outside of other draw ops, so stencil can only be in test state 321527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik bool stencilWasEnabled = mCaches.stencil.isTestEnabled(); 322527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik mCaches.stencil.disable(); 323527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 324527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true); 325527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 326527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (stencilWasEnabled) mCaches.stencil.enableTest(); 327107843de4507b3511006cb9c77b8d0364374385aTom Hudson mDirty = true; 328527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 329527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif 330527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 33169e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik const Vector3& getLightCenter() const { return currentSnapshot()->getRelativeLightCenter(); } 33205f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik float getLightRadius() const { return mLightRadius; } 33369e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; } 33469e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; } 33505f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik 336e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected: 337e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy /** 33896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Perform the setup specific to a frame. This method does not 33996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * issue any OpenGL commands. 34096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 34196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void setupFrameState(float left, float top, float right, float bottom, bool opaque); 34296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 34396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 34496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Indicates the start of rendering. This method will setup the 34596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * initial OpenGL state (viewport, clearing the buffer, etc.) 34696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 347107843de4507b3511006cb9c77b8d0364374385aTom Hudson void startFrame(); 34896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 34996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 3507c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy * Clears the underlying surface if needed. 3517c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy */ 352107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void clear(float left, float top, float right, float bottom, bool opaque); 3537c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 3547c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy /** 35535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Call this method after updating a layer during a drawing pass. 35635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 35735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy void resumeAfterLayer(); 35835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 35935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 3608ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * This method is called whenever a stencil buffer is required. Subclasses 3618ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * should override this method and call attachStencilBufferToLayer() on the 3628ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * appropriate layer(s). 3638ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 3648ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy virtual void ensureStencilBuffer(); 3658ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 3668ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 3678ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Obtains a stencil render buffer (allocating it if necessary) and 3688ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * attaches it to the specified layer. 3698ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 3708ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void attachStencilBufferToLayer(Layer* layer); 3718ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 372f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik bool quickRejectSetupScissor(float left, float top, float right, float bottom, 373d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint = NULL); 374d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) { 375f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik return quickRejectSetupScissor(bounds.left, bounds.top, 376f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik bounds.right, bounds.bottom, paint); 377f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik } 378f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik 3798ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 380e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * Compose the layer defined in the current snapshot with the layer 381e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * defined by the previous snapshot. 382e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 383e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 384e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 385e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param curent The current snapshot containing the layer to compose 386e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param previous The previous snapshot to compose the current layer with 387e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy */ 38814e513058ed4168c94e015638d16f5f87fd8063aChris Craik virtual void composeLayer(const Snapshot& current, const Snapshot& previous); 389694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 390ada830f639591b99c3e40de22b07296c7932a33fRomain Guy /** 391f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Marks the specified region as dirty at the specified bounds. 392ada830f639591b99c3e40de22b07296c7932a33fRomain Guy */ 393f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayerUnchecked(Rect& bounds, Region* region); 394ada830f639591b99c3e40de22b07296c7932a33fRomain Guy 39542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 39642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the region of the current layer. 39742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 398624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual Region* getRegion() const { 399f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return mSnapshot->region; 400f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 401f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 40242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 40342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Indicates whether rendering is currently targeted at a layer. 40442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 405624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual bool hasLayer() const { 406f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region; 407f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 4081bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy 40942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 41042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the name of the FBO this renderer is rendering into. 41142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 41214e513058ed4168c94e015638d16f5f87fd8063aChris Craik virtual GLuint getTargetFbo() const { 41342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy return 0; 41442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy } 41542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy 41677a811610f99e21da7f88dafef60d09f345d0506Romain Guy /** 41777a811610f99e21da7f88dafef60d09f345d0506Romain Guy * Renders the specified layer as a textured quad. 41877a811610f99e21da7f88dafef60d09f345d0506Romain Guy * 41977a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param layer The layer to render 42077a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param rect The bounds of the layer 42177a811610f99e21da7f88dafef60d09f345d0506Romain Guy */ 42277a811610f99e21da7f88dafef60d09f345d0506Romain Guy void drawTextureLayer(Layer* layer, const Rect& rect); 42377a811610f99e21da7f88dafef60d09f345d0506Romain Guy 424be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 425be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * Gets the alpha and xfermode out of a paint object. If the paint is null 42616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both 42716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * snapshot alpha, and overrideLayerAlpha 428be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * 429be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param paint The paint to extract values from 430be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param alpha Where to store the resulting alpha 431be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param mode Where to store the resulting xfermode 432be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 433d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const; 43416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik 43516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik /** 43616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha 43716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * 43816ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * @param layer The layer from which the alpha is extracted 43916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik */ 44076d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger inline float getLayerAlpha(const Layer* layer) const; 441be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 442be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 44376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * Safely retrieves the ColorFilter from the given Paint. If the paint is 44476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * null then null is returned. 445be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 44676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger static inline SkColorFilter* getColorFilter(const SkPaint* paint) { 44776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger return paint ? paint->getColorFilter() : NULL; 448be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy } 449be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 45011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy /** 451d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * Safely retrieves the Shader from the given Paint. If the paint is 452d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * null then null is returned. 453d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III */ 454d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III static inline const SkShader* getShader(const SkPaint* paint) { 455d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III return paint ? paint->getShader() : NULL; 456d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III } 457d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III 458d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III /** 45911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy * Set to true to suppress error checks at the end of a frame. 46011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy */ 461624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual bool suppressErrorChecks() const { 46211cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy return false; 46311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy } 46411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 4653b20251a355c88193c439f928a84ae69483fb488John Reck inline RenderState& renderState() { return mRenderState; } 4663b20251a355c88193c439f928a84ae69483fb488John Reck 46708ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate: 4685cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 469dcfc836b457a87881da409e1acf251515f121446Romain Guy * Discards the content of the framebuffer if supported by the driver. 470dcfc836b457a87881da409e1acf251515f121446Romain Guy * This method should be called at the beginning of a frame to optimize 471dcfc836b457a87881da409e1acf251515f121446Romain Guy * rendering on some tiler architectures. 472dcfc836b457a87881da409e1acf251515f121446Romain Guy */ 473dcfc836b457a87881da409e1acf251515f121446Romain Guy void discardFramebuffer(float left, float top, float right, float bottom); 474dcfc836b457a87881da409e1acf251515f121446Romain Guy 475dcfc836b457a87881da409e1acf251515f121446Romain Guy /** 476ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * Ensures the state of the renderer is the same as the state of 477ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * the GL context. 478ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy */ 479ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy void syncState(); 480ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy 481ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy /** 4822b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 483d6b65f67717025b1162f86f04e2caa5723566cacChris Craik * This method will use the current layer space clip rect. 4842b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * This method needs to be invoked every time getTargetFbo() is 4852b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * bound again. 4862b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 48733f5a59ac3e304970920dda824958870f85f76efhenry.uh_chen void startTilingCurrentClip(bool opaque = false, bool expand = false); 4882b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 4892b7028eabac80cec170572bc0e945a1d4224e595Romain Guy /** 490c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 491c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * This method needs to be invoked every time getTargetFbo() is 492c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * bound again. 493c3fedafc5f50100219449125a000e3138f6fb987Romain Guy */ 49433f5a59ac3e304970920dda824958870f85f76efhenry.uh_chen void startTiling(const Rect& clip, int windowHeight, bool opaque = false, bool expand = false); 495c3fedafc5f50100219449125a000e3138f6fb987Romain Guy 496c3fedafc5f50100219449125a000e3138f6fb987Romain Guy /** 4972b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU that we are done drawing the frame or that we 4982b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * are switching to another render target. 4992b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 5002b7028eabac80cec170572bc0e945a1d4224e595Romain Guy void endTiling(); 5012b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 50214e513058ed4168c94e015638d16f5f87fd8063aChris Craik void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored); 503bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 5045cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 5055cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Sets the clipping rectangle using glScissor. The clip is defined by 5065cbbce535744b89df5ecea95de21ee3733298260Romain Guy * the current snapshot's clipRect member. 5075cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 508bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void setScissorFromClip(); 509bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 5105cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 5118ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Sets the clipping region using the stencil buffer. The clip region 5128ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * is defined by the current snapshot's clipRegion member. 5138ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 5148ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void setStencilFromClip(); 5158ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 5168ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 517408eb12631376cbdc96803e918decf6ea804d346Chris Craik * Given the local bounds of the layer, calculates ... 518d90144db52c7297879b950cbbc85137ed123ab5bChris Craik */ 519d90144db52c7297879b950cbbc85137ed123ab5bChris Craik void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer); 520d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 521d90144db52c7297879b950cbbc85137ed123ab5bChris Craik /** 522408eb12631376cbdc96803e918decf6ea804d346Chris Craik * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible 523408eb12631376cbdc96803e918decf6ea804d346Chris Craik */ 524408eb12631376cbdc96803e918decf6ea804d346Chris Craik void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip, 525408eb12631376cbdc96803e918decf6ea804d346Chris Craik bool fboLayer, int alpha); 526408eb12631376cbdc96803e918decf6ea804d346Chris Craik 527408eb12631376cbdc96803e918decf6ea804d346Chris Craik /** 528d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Creates a new layer stored in the specified snapshot. 529d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 530d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param snapshot The snapshot associated with the new layer 531d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param left The left coordinate of the layer 532d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param top The top coordinate of the layer 533d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param right The right coordinate of the layer 534d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param bottom The bottom coordinate of the layer 535d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param alpha The translucency of the layer 536d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode of the layer 537d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param flags The layer save flags 5383f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik * @param mask A mask to use when drawing the layer back, may be empty 539d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 540d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @return True if the layer was successfully created, false otherwise 541d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 542d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase bool createLayer(float left, float top, float right, float bottom, 5433f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPaint* paint, int flags, const SkPath* convexMask); 544d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 545d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 5465b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Creates a new layer stored in the specified snapshot as an FBO. 5475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to store as an FBO 5495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param snapshot The snapshot associated with the new layer 5505b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param bounds The bounds of the layer 5515b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 552e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip); 5535b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 5545b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 5555b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a region. 5565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5575b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 5585b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 5595b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 5605b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRegion(Layer* layer, const Rect& rect); 5615b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 5625b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 5635b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a simple rectangle. 5645b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5655b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 5665b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 5675b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param swap If true, the source and destination are swapped 5685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 5695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false); 5705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 57154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 57254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Clears all the regions corresponding to the current list of layers. 57354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method MUST be invoked before any drawing operation. 57454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 57554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void clearLayerRegions(); 57654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 57754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 578f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. The coordinates 579f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * are transformed with the supplied matrix. 580f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 581f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 582f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom, const mat4 transform); 583f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 584f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 585f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. 586f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 587f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 588f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom); 589f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 590f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 5915cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a colored rectangle with the specified color. The specified coordinates 592735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * are transformed by the current snapshot's transform matrix unless specified 593735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * otherwise. 5945cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 5955cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 5965cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 5975cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 5985cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 59976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the color, blending mode, etc. 6003d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy * @param ignoreTransform True if the current transform should be ignored 6015cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 602026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void drawColorRect(float left, float top, float right, float bottom, 60376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool ignoreTransform = false); 6045cbbce535744b89df5ecea95de21ee3733298260Romain Guy 60554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 606735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * Draws a series of colored rectangles with the specified color. The specified 607735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * coordinates are transformed by the current snapshot's transform matrix unless 608735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * specified otherwise. 609735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * 610735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param rects A list of rectangles, 4 floats (left, top, right, bottom) 611735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * per rectangle 61276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the color, blending mode, etc. 613735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param ignoreTransform True if the current transform should be ignored 6148ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * @param dirty True if calling this method should dirty the current layer 6153bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy * @param clip True if the rects should be clipped, false otherwise 616735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy */ 617107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawColorRects(const float* rects, int count, const SkPaint* paint, 61876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger bool ignoreTransform = false, bool dirty = true, bool clip = true); 619735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy 620735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy /** 62154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the shape represented by the specified path texture. 62254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method invokes drawPathTexture() but takes into account 62354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * the extra left/top offset and the texture offset to correctly 62454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * position the final shape. 62554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 62654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The left coordinate of the shape to render 62754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The top coordinate of the shape to render 62854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture reprsenting the shape 62954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the shape with 63054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 631107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint); 63254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 63354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 63454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey 63554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * different compositing rules. 63654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 63754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to draw with 63854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The x coordinate of the bitmap 63954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The y coordinate of the bitmap 64054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to render with 64154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 642d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawAlphaBitmap(Texture* texture, float left, float top, const SkPaint* paint); 643a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy 64454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 64565cd612face362d054a85d0f7e5881c59cd523beChris Craik * Renders a strip of polygons with the specified paint, used for tessellated geometry. 64665cd612face362d054a85d0f7e5881c59cd523beChris Craik * 64765cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param vertexBuffer The VertexBuffer to be drawn 64865cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param paint The paint to render with 649bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik * @param flags flags with which to draw 65065cd612face362d054a85d0f7e5881c59cd523beChris Craik */ 651107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer, 652bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik const SkPaint* paint, int flags = 0); 65365cd612face362d054a85d0f7e5881c59cd523beChris Craik 65465cd612face362d054a85d0f7e5881c59cd523beChris Craik /** 65505f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik * Convenience for translating method 65605f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik */ 657107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawVertexBuffer(const VertexBuffer& vertexBuffer, 658bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik const SkPaint* paint, int flags = 0) { 659107843de4507b3511006cb9c77b8d0364374385aTom Hudson drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags); 66005f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik } 66105f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik 66205f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik /** 663710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * Renders the convex hull defined by the specified path as a strip of polygons. 66454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 665710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * @param path The hull of the path to draw 666cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik * @param paint The paint to render with 66754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 668107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawConvexPath(const SkPath& path, const SkPaint* paint); 669858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase 6705cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 6715cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 6725cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 6735cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 6745cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 6755cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 6765cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 6775cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 67882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture to use 67982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param paint The paint containing the alpha, blending mode, etc. 68082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 681a979474f15b454c8e2963f239a3770e200bb227cRomain Guy void drawTextureRect(float left, float top, float right, float bottom, 682d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik Texture* texture, const SkPaint* paint); 68382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 68482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy /** 68503750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * Draws a textured mesh with the specified texture. If the indices are omitted, 68603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * the mesh is drawn as a simple quad. The mesh pointers become offsets when a 68703750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * VBO is bound. 68882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 68982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 69082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 69182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 69282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 69382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture name to map onto the rectangle 69476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the alpha, blending mode, colorFilter, etc. 69582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param blend True if the texture contains an alpha channel 69682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param vertices The vertices that define the mesh 69782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texCoords The texture coordinates of each vertex 69882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param elementsCount The number of elements in the mesh, required by indices 699f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param swapSrcDst Whether or not the src and dst blending operations should be swapped 700f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param ignoreTransform True if the current transform should be ignored 70103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * @param vbo The VBO used to draw the mesh 7024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param modelViewMode Defines whether the model view matrix should be scaled 7035b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param dirty True if calling this method should dirty the current layer 704f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 705f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, 70676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool blend, 7076820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 7085b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 7094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true); 710f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 7113b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture, 71276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool blend, 7133b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 7143b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 7154063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true); 7163b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 717886b275e529e44a59c54b933453d9bc902973178Romain Guy void drawAlpha8TextureMesh(float left, float top, float right, float bottom, 71876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger GLuint texture, const SkPaint* paint, 719886b275e529e44a59c54b933453d9bc902973178Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 7204063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik bool ignoreTransform, ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, 7214063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik bool dirty = true); 722886b275e529e44a59c54b933453d9bc902973178Romain Guy 723f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 724448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * Draws the specified list of vertices as quads using indexed GL_TRIANGLES. 725448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * If the number of vertices to draw exceeds the number of indices we have 726448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * pre-allocated, this method will generate several glDrawElements() calls. 727448455fe783b0a711340322dca272b8cc0ebe473Romain Guy */ 7284063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik void issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount); 729448455fe783b0a711340322dca272b8cc0ebe473Romain Guy 730448455fe783b0a711340322dca272b8cc0ebe473Romain Guy /** 7310a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * Draws text underline and strike-through if needed. 7320a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * 7330a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param text The text to decor 7340a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param bytesCount The number of bytes in the text 73541541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik * @param totalAdvance The total advance in pixels, defines underline/strikethrough length 7360a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param x The x coordinate where the text will be drawn 7370a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param y The y coordinate where the text will be drawn 7380a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param paint The paint to draw the text with 7390a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy */ 740d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint); 7411e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 742416a847633680d94efb926837efdc18726d54918Raph Levien /** 743416a847633680d94efb926837efdc18726d54918Raph Levien * Draws shadow layer on text (with optional positions). 744416a847633680d94efb926837efdc18726d54918Raph Levien * 745416a847633680d94efb926837efdc18726d54918Raph Levien * @param paint The paint to draw the shadow with 746416a847633680d94efb926837efdc18726d54918Raph Levien * @param text The text to draw 747416a847633680d94efb926837efdc18726d54918Raph Levien * @param bytesCount The number of bytes in the text 748416a847633680d94efb926837efdc18726d54918Raph Levien * @param count The number of glyphs in the text 749416a847633680d94efb926837efdc18726d54918Raph Levien * @param positions The x, y positions of individual glyphs (or NULL) 750416a847633680d94efb926837efdc18726d54918Raph Levien * @param fontRenderer The font renderer object 751416a847633680d94efb926837efdc18726d54918Raph Levien * @param alpha The alpha value for drawing the shadow 752416a847633680d94efb926837efdc18726d54918Raph Levien * @param x The x coordinate where the shadow will be drawn 753416a847633680d94efb926837efdc18726d54918Raph Levien * @param y The y coordinate where the shadow will be drawn 754416a847633680d94efb926837efdc18726d54918Raph Levien */ 755d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count, 75676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const float* positions, FontRenderer& fontRenderer, int alpha, 757416a847633680d94efb926837efdc18726d54918Raph Levien float x, float y); 758416a847633680d94efb926837efdc18726d54918Raph Levien 75954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 76054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws a path texture. Path textures are alpha8 bitmaps that need special 76154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * compositing to apply colors/filters/etc. 76254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 76354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to render 76454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param x The x coordinate where the texture will be drawn 76554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param y The y coordinate where the texture will be drawn 76654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the texture with 76754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 768d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint); 76901d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy 7701e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy /** 771ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Resets the texture coordinates stored in mMeshVertices. Setting the values 772026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * back to default is achieved by calling: 773026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 7748ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 775026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 776026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u1 The left coordinate of the texture 777026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v1 The bottom coordinate of the texture 778026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u2 The right coordinate of the texture 779026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v2 The top coordinate of the texture 780026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 781026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 782026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 7838ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy /** 784768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy * Returns true if the specified paint will draw invisible text. 785768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy */ 786768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy bool canSkipText(const SkPaint* paint) const; 787768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy 788768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy /** 789746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Binds the specified texture. The texture unit must have been selected 790746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * prior to calling this method. 791a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy */ 792746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void bindTexture(GLuint texture) { 7938aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy mCaches.bindTexture(texture); 794746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 795746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 796746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 797aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Binds the specified EGLImage texture. The texture unit must have been selected 798aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * prior to calling this method. 799aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 800aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy inline void bindExternalTexture(GLuint texture) { 8018aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture); 802aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy } 803aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 804aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 80582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Enable or disable blending as necessary. This function sets the appropriate 80682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * blend function based on the specified xfermode. 80782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 808f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description, 809f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy bool swapSrcDst = false); 810a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy 811f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy /** 812d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Use the specified program with the current GL context. If the program is already 813d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * in use, it will not be bound again. If it is not in use, the current program is 814d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * marked unused and the specified program becomes used and becomes the new 815d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * current program. 8166926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy * 817d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param program The program to use 818d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 819d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @return true If the specified program was already in use, false otherwise. 820260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy */ 821889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy inline bool useProgram(Program* program); 822260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy 823746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 824746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Invoked before any drawing operation. This sets required state. 825746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 82654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void setupDraw(bool clear = true); 82717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 82870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy /** 82970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy * Various methods to setup OpenGL rendering. 83070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy */ 83170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawWithTexture(bool isAlpha8 = false); 832ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy void setupDrawWithTextureAndColor(bool isAlpha8 = false); 833aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawWithExternalTexture(); 83415bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy void setupDrawNoTexture(); 83591a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik void setupDrawVertexAlpha(bool useShadowAlphaInterp); 8368d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy void setupDrawColor(int color, int alpha); 83770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColor(float r, float g, float b, float a); 83886568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawAlpha8Color(int color, int alpha); 8394121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGamma(const SkPaint* paint); 840d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III void setupDrawShader(const SkShader* shader); 84176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawColorFilter(const SkColorFilter* filter); 84276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawBlending(const Layer* layer, bool swapSrcDst = false); 84376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawBlending(const SkPaint* paint, bool blend = true, bool swapSrcDst = false); 84470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawProgram(); 84570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawDirtyRegionsDisabled(); 8464063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 8474063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 8484063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Setup the current program matrices based upon the nature of the geometry. 8494063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8504063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param mode If kModelViewMode_Translate, the geometry must be translated by the left and top 8514063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * parameters. If kModelViewMode_TranslateAndScale, the geometry that exists in the (0,0, 1,1) 8524063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * space must be scaled up and translated to fill the quad provided in (l,t,r,b). These 8534063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * transformations are stored in the modelView matrix and uploaded to the shader. 8544063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8554063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate 856564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik * geometry pixel positioning. See Vertex::GeometryFudgeFactor(). 8574063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8584063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space, 8594063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil, 8604063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * or when simple translation has been extracted) 8614063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 8624063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik void setupDrawModelView(ModelViewMode mode, bool offset, 8634063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik float left, float top, float right, float bottom, bool ignoreTransform = false); 864d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III void setupDrawColorUniforms(bool hasShader); 86586568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawPureColorUniforms(); 866d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III 867d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III /** 868d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * Setup uniforms for the current shader. 869d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * 870d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * @param shader SkShader on the current paint. 871d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * 872d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * @param ignoreTransform Set to true to ignore the transform in shader. 873d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III */ 874d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III void setupDrawShaderUniforms(const SkShader* shader, bool ignoreTransform = false); 87576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawColorFilterUniforms(const SkColorFilter* paint); 87670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawSimpleMesh(); 87770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawTexture(GLuint texture); 878aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawExternalTexture(GLuint texture); 8798f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransform(); 8808f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransformUniforms(mat4& transform); 8814121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGammaUniforms(); 882564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0); 883564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors); 884564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0); 885448455fe783b0a711340322dca272b8cc0ebe473Romain Guy void setupDrawIndexedVertices(GLvoid* vertices); 886f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy void accountForClear(SkXfermode::Mode mode); 887746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 88811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy bool updateLayer(Layer* layer, bool inFrame); 88911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy void updateLayers(); 89096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void flushLayers(); 89111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 892e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#if DEBUG_LAYERS_AS_REGIONS 89317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 89417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Renders the specified region as a series of rectangles. This method 89517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * is used for debugging only. 89617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 897e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik void drawRegionRectsDebug(const Region& region); 898e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#endif 8993a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy 9008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 9018ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Renders the specified region as a series of rectangles. The region 9028ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * must be in screen-space coordinates. 9038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 90476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false); 9058ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 9068ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 9078ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS 9088ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * is turned on. 9098ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 9108ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void debugClip(); 9118ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 9127c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void debugOverdraw(bool enable, bool clear); 9137c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void renderOverdraw(); 91478dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy void countOverdraw(); 9157c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy 916746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 917746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Should be invoked every time the glScissor is modified. 918746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 919746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void dirtyClip() { 920746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy mDirtyClip = true; 921746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 922746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 9233b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy inline const UvMapper& getMapper(const Texture* texture) { 9243b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper; 9253b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy } 9263b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 9273b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy /** 9283b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * Returns a texture object for the specified bitmap. The texture can 9293b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * come from the texture cache or an atlas. If this method returns 9303b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * NULL, the texture could not be found and/or allocated. 9313b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy */ 932d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik Texture* getTexture(const SkBitmap* bitmap); 9333b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 934107843de4507b3511006cb9c77b8d0364374385aTom Hudson bool reportAndClearDirty() { bool ret = mDirty; mDirty = false; return ret; } 935107843de4507b3511006cb9c77b8d0364374385aTom Hudson 9364063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 9374063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Model-view matrix used to position/size objects 9384063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9394063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Stores operation-local modifications to the draw matrix that aren't incorporated into the 9404063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * currentTransform(). 9414063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 942e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * If generated with kModelViewMode_Translate, mModelViewMatrix will reflect an x/y offset, 9434063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale, 944e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * mModelViewMatrix will reflect a translation and scale, e.g. the translation and scale 945e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * required to make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height 946e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * of a bitmap. 9474063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9484063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used as input to SkiaShader transformation. 9494063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 950e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik mat4 mModelViewMatrix; 951c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 9522b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // State used to define the clipping region 9535f803623559aab395a29d575c37c4e39c23a4b4eChris Craik Rect mTilingClip; 95496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy // Is the target render surface opaque 95596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy bool mOpaque; 95696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy // Is a frame currently being rendered 95796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy bool mFrameStarted; 9589d5316e3f56d138504565ff311145ac01621dff4Romain Guy 959026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy // Used to draw textured quads 960ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy TextureVertex mMeshVertices[4]; 961ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 9623b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy // Default UV mapper 9633b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy const UvMapper mUvMapper; 9643b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 965c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik // shader, filters, and shadow 966c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik DrawModifiers mDrawModifiers; 9675ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy SkPaint mFilteredPaint; 9685ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 96982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Various caches 970fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy Caches& mCaches; 9713bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy Extensions& mExtensions; 9723b20251a355c88193c439f928a84ae69483fb488John Reck RenderState& mRenderState; 9738694230ff25fa0a60e480d424843e56b718f0516Romain Guy 9748f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy // List of rectangles to clear after saveLayer() is invoked 97554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy Vector<Rect*> mLayers; 97611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy // List of layers to update at the beginning of a frame 9770e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck Vector< sp<Layer> > mLayerUpdates; 97854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 97970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // The following fields are used to setup drawing 98070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Used to describe the shaders to generate 98170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy ProgramDescription mDescription; 98270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Color description 98370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mColorSet; 98470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy float mColorA, mColorR, mColorG, mColorB; 98570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Indicates that the shader should get a color 98670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mSetShaderColor; 98770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Current texture unit 98870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy GLuint mTextureUnit; 98970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Track dirty regions, true by default 99070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mTrackDirtyRegions; 9912b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // Indicate whether we are drawing an opaque frame 9922b7028eabac80cec170572bc0e945a1d4224e595Romain Guy bool mOpaqueFrame; 99370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy 99487e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in 99587e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // Properties.h 99687e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy bool mScissorOptimizationDisabled; 99787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 99854c1a64d5441a964890b44280e4457e11f4f924aRomain Guy // No-ops start/endTiling when set 99954c1a64d5441a964890b44280e4457e11f4f924aRomain Guy bool mSuppressTiling; 1000284b24358410cb0200e525a5ba36994090c83f20Chris Craik bool mFirstFrameAfterResize; 100154c1a64d5441a964890b44280e4457e11f4f924aRomain Guy 1002deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik bool mSkipOutlineClip; 1003deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik 1004107843de4507b3511006cb9c77b8d0364374385aTom Hudson // True if anything has been drawn since the last call to 1005107843de4507b3511006cb9c77b8d0364374385aTom Hudson // reportAndClearDirty() 1006107843de4507b3511006cb9c77b8d0364374385aTom Hudson bool mDirty; 1007107843de4507b3511006cb9c77b8d0364374385aTom Hudson 1008058fc640017c90120c599d378a4cbc55668b05b7Chris Craik // Lighting + shadows 1009058fc640017c90120c599d378a4cbc55668b05b7Chris Craik Vector3 mLightCenter; 1010058fc640017c90120c599d378a4cbc55668b05b7Chris Craik float mLightRadius; 1011058fc640017c90120c599d378a4cbc55668b05b7Chris Craik uint8_t mAmbientShadowAlpha; 1012058fc640017c90120c599d378a4cbc55668b05b7Chris Craik uint8_t mSpotShadowAlpha; 1013058fc640017c90120c599d378a4cbc55668b05b7Chris Craik 101496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy friend class Layer; 1015257ae3502cfad43df681b1783528d645bdabc63fRomain Guy friend class TextSetupFunctor; 101603c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy friend class DrawBitmapOp; 101703c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy friend class DrawPatchOp; 1018b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy 1019bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer 1020e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 10219d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer 1022e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android 1023e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 10245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H 1025