OpenGLRenderer.h revision 984162fb7e4010b6e2908352dbff17ed47eecf06
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 41984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson#include "CanvasState.h" 42c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h" 4351769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h" 44f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h" 455cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h" 46bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h" 47984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson#include "Renderer.h" 48b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Snapshot.h" 493b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include "UvMapper.h" 50b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Vertex.h" 51fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h" 52bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 53d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins IIIclass SkShader; 54d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III 55e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android { 569d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer { 57e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 58b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DeferredDisplayState; 593b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState; 60e18264b079481a244b30e3f71012c53bbd861f92John Reckclass RenderNode; 61b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass TextSetupFunctor; 62b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass VertexBuffer; 63b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik 64c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers { 659b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy DrawModifiers() { 669b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy reset(); 679b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy } 689b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy 699b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy void reset() { 709b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy memset(this, 0, sizeof(DrawModifiers)); 719b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy } 729b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy 7316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik float mOverrideLayerAlpha; 74c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik}; 75c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 76ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags { 77ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik kStateDeferFlag_Draw = 0x1, 78ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik kStateDeferFlag_Clip = 0x2 79ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik}; 80ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik 8128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags { 82a02c4ed885d97e516f844ddb0a96083f1b45b4cbChris Craik kClipSide_None = 0x0, 8328ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Left = 0x1, 8428ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Top = 0x2, 8528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Right = 0x4, 8628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Bottom = 0x8, 87d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik kClipSide_Full = 0xF, 88d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik kClipSide_ConservativeFull = 0x1F 8928ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik}; 9028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik 91bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craikenum VertexBufferDisplayFlags { 92bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik kVertexBuffer_Offset = 0x1, 9391a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik kVertexBuffer_ShadowInterp = 0x2, 94bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik}; 95bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik 964063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik/** 974063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Defines additional transformation that should be applied by the model view matrix, beyond that of 984063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * the currentTransform() 994063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1004063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craikenum ModelViewMode { 1014063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 1024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used when the model view should simply translate geometry passed to the shader. The resulting 1034063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * matrix will be a simple translation. 1044063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1054063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik kModelViewMode_Translate = 0, 1064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 1074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 1084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used when the model view should translate and scale geometry. The resulting matrix will be a 1094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect. 1104063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1114063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik kModelViewMode_TranslateAndScale = 1, 1124063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik}; 1134063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 114f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 115f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer 116f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 1175cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 11814e513058ed4168c94e015638d16f5f87fd8063aChris Craik * OpenGL Renderer implementation. 1195cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 120984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudsonclass OpenGLRenderer : public Renderer, public CanvasStateClient { 121e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic: 1223b20251a355c88193c439f928a84ae69483fb488John Reck OpenGLRenderer(RenderState& renderState); 123e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual ~OpenGLRenderer(); 124e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 1253b20251a355c88193c439f928a84ae69483fb488John Reck void initProperties(); 126058fc640017c90120c599d378a4cbc55668b05b7Chris Craik void initLight(const Vector3& lightCenter, float lightRadius, 127058fc640017c90120c599d378a4cbc55668b05b7Chris Craik uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); 12887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 129107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); 130984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void prepare(bool opaque) { 131984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson prepareDirty(0.0f, 0.0f, mState.getWidth(), mState.getHeight(), opaque); 132984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson } 133107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual bool finish(); 134c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy 135107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void callDrawGLFunction(Functor* functor, Rect& dirty); 13608ae317c21ec3086b5017672bba87420cc38a407Romain Guy 1373b20251a355c88193c439f928a84ae69483fb488John Reck void pushLayerUpdate(Layer* layer); 1383b20251a355c88193c439f928a84ae69483fb488John Reck void cancelLayerUpdate(Layer* layer); 1393b20251a355c88193c439f928a84ae69483fb488John Reck void flushLayerUpdates(); 140443a714fa7c0dd07fee3527cc5bc3d3ca1fb7d44John Reck void markLayersAsBuildLayers(); 14111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 1423b20251a355c88193c439f928a84ae69483fb488John Reck virtual int saveLayer(float left, float top, float right, float bottom, 1433f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPaint* paint, int flags) { 1443f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik return saveLayer(left, top, right, bottom, paint, flags, NULL); 1453f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik } 1463f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik 1473f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if 1483f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik // created, which will in turn clip to that mask when drawn back/restored. 1493f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik int saveLayer(float left, float top, float right, float bottom, 1503f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPaint* paint, int flags, const SkPath* convexMask); 151bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 152d90144db52c7297879b950cbbc85137ed123ab5bChris Craik int saveLayerDeferred(float left, float top, float right, float bottom, 153d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger const SkPaint* paint, int flags); 154d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 155107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1); 156107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawLayer(Layer* layer, float x, float y); 157107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint); 158107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount, 159d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint); 160107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop, 161e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy float srcRight, float srcBottom, float dstLeft, float dstTop, 162d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float dstRight, float dstBottom, const SkPaint* paint); 163107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint); 164107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight, 165d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* vertices, const int* colors, const SkPaint* paint); 166107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry, 167d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint); 168107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, 169d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float left, float top, float right, float bottom, const SkPaint* paint); 170107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry, 171d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float left, float top, float right, float bottom, const SkPaint* paint); 172107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawColor(int color, SkXfermode::Mode mode); 173107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRect(float left, float top, float right, float bottom, 174d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 175107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRoundRect(float left, float top, float right, float bottom, 176d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float rx, float ry, const SkPaint* paint); 177107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawCircle(float x, float y, float radius, const SkPaint* paint); 178107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawOval(float left, float top, float right, float bottom, 179d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 180107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawArc(float left, float top, float right, float bottom, 181d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint); 182107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPath(const SkPath* path, const SkPaint* paint); 183107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawLines(const float* points, int count, const SkPaint* paint); 184107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPoints(const float* points, int count, const SkPaint* paint); 185107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path, 186d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float hOffset, float vOffset, const SkPaint* paint); 187107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawPosText(const char* text, int bytesCount, int count, 188d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* positions, const SkPaint* paint); 189107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawText(const char* text, int bytesCount, int count, float x, float y, 190d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds, 191527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik DrawOpMode drawOpMode = kDrawOpMode_Immediate); 192107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void drawRects(const float* rects, int count, const SkPaint* paint); 19385bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 194107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawShadow(float casterAlpha, 19505f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik const VertexBuffer* ambientShadowVertexBuffer, const VertexBuffer* spotShadowVertexBuffer); 196f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik 19709c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger virtual void setDrawFilter(SkDrawFilter* filter); 1985ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 19916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer) 20016ecda5317c40fc3da284952d9b3add34d6763aeChris Craik void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; } 20116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik 2025e49b307eb99269db2db257760508b8efd7bb97dChris Craik /** 2035e49b307eb99269db2db257760508b8efd7bb97dChris Craik * Store the current display state (most importantly, the current clip and transform), and 2045e49b307eb99269db2db257760508b8efd7bb97dChris Craik * additionally map the state's bounds from local to window coordinates. 2055e49b307eb99269db2db257760508b8efd7bb97dChris Craik * 2065e49b307eb99269db2db257760508b8efd7bb97dChris Craik * Returns true if quick-rejected 2075e49b307eb99269db2db257760508b8efd7bb97dChris Craik */ 208ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags); 209527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false); 21028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik void setupMergedMultiDraw(const Rect* clipRect); 211c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 212d90144db52c7297879b950cbbc85137ed123ab5bChris Craik const DrawModifiers& getDrawModifiers() { return mDrawModifiers; } 213d90144db52c7297879b950cbbc85137ed123ab5bChris Craik void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; } 214d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 2153b20251a355c88193c439f928a84ae69483fb488John Reck bool isCurrentTransformSimple() { 216d6b65f67717025b1162f86f04e2caa5723566cacChris Craik return currentTransform()->isSimple(); 217672433d90fab7383cd28beac9d4485b566a90940Romain Guy } 218672433d90fab7383cd28beac9d4485b566a90940Romain Guy 2190f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy Caches& getCaches() { 2200f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy return mCaches; 2210f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy } 2220f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy 223ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik // simple rect clip 224984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson bool isCurrentClipSimple() { return mState.isCurrentClipSimple(); } 225ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik 226984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson int getViewportWidth() { return mState.getViewportWidth(); } 227984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson int getViewportHeight() { return mState.getViewportHeight(); } 2280e87f00f8cb79635aa70b9a2dfa02bf19dc7473dChris Craik 22917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 230a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik * Scales the alpha on the current snapshot. This alpha value will be modulated 23117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * with other alpha values when drawing primitives. 23217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 233984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson void scaleAlpha(float alpha) { mState.scaleAlpha(alpha); } 23417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 23517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 2360f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy * Inserts a named event marker in the stream of GL commands. 2370f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy */ 2380f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy void eventMark(const char* name) const; 2390f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy 2400f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy /** 24162d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik * Inserts a formatted event marker in the stream of GL commands. 24262d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik */ 24362d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik void eventMarkDEBUG(const char *fmt, ...) const; 24462d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik 24562d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik /** 24617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Inserts a named group marker in the stream of GL commands. This marker 24717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * can be used by tools to group commands into logical groups. A call to 24817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * this method must always be followed later on by a call to endMark(). 24917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 25013631f3da855f200a151e7837ed9f6b079622b58Romain Guy void startMark(const char* name) const; 25117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 25217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 25317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Closes the last group marker opened by startMark(). 25417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 25513631f3da855f200a151e7837ed9f6b079622b58Romain Guy void endMark() const; 25613631f3da855f200a151e7837ed9f6b079622b58Romain Guy 257d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase /** 258d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Gets the alpha and xfermode out of a paint object. If the paint is null 259d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * alpha will be 255 and the xfermode will be SRC_OVER. This method does 26016ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * not multiply the paint's alpha by the current snapshot's alpha, and does 26116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * not replace the alpha with the overrideLayerAlpha 262d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * 263d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param paint The paint to extract values from 264d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param alpha Where to store the resulting alpha 265d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param mode Where to store the resulting xfermode 266d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase */ 267d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) { 268527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik *mode = getXfermodeDirect(paint); 269527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik *alpha = getAlphaDirect(paint); 270527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 271527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 272d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) { 273527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (!paint) return SkXfermode::kSrcOver_Mode; 274527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik return getXfermode(paint->getXfermode()); 275527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 276527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 277c1c5f0870282b56dafe5a4d756e4b9e6884655a7Chris Craik static inline int getAlphaDirect(const SkPaint* paint) { 278527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (!paint) return 255; 279527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik return paint->getAlpha(); 280d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } 281d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase 282c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger struct TextShadow { 283c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger SkScalar radius; 284c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger float dx; 285c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger float dy; 286c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger SkColor color; 287c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger }; 288c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger 289c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger static inline bool getTextShadow(const SkPaint* paint, TextShadow* textShadow) { 290c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger SkDrawLooper::BlurShadowRec blur; 291c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger if (paint && paint->getLooper() && paint->getLooper()->asABlurShadow(&blur)) { 292c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger if (textShadow) { 293c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->radius = Blur::convertSigmaToRadius(blur.fSigma); 294c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->dx = blur.fOffset.fX; 295c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->dy = blur.fOffset.fY; 296c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger textShadow->color = blur.fColor; 297c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 298c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger return true; 299c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 300c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger return false; 301c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 302c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger 303c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger static inline bool hasTextShadow(const SkPaint* paint) { 304c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger return getTextShadow(paint, NULL); 305c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger } 306c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger 307624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy /** 30859744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * Build the best transform to use to rasterize text given a full 30959744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * transform matrix, and whether filteration is needed. 31059744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * 31159744b79ec302000802cd56d30a1bf70f0183c80Chris Craik * Returns whether filtration is needed 312624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy */ 31359744b79ec302000802cd56d30a1bf70f0183c80Chris Craik bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const; 314624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy 315527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR 316527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) { 317527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik mCaches.setScissorEnabled(false); 318527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 319527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik // should only be called outside of other draw ops, so stencil can only be in test state 320527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik bool stencilWasEnabled = mCaches.stencil.isTestEnabled(); 321527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik mCaches.stencil.disable(); 322527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 323527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true); 324527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 325527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (stencilWasEnabled) mCaches.stencil.enableTest(); 326107843de4507b3511006cb9c77b8d0364374385aTom Hudson mDirty = true; 327527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 328527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif 329527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 330984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson const Vector3& getLightCenter() const { return mState.currentLightCenter(); } 33105f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik float getLightRadius() const { return mLightRadius; } 33269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; } 33369e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; } 33405f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik 335984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson /////////////////////////////////////////////////////////////////// 336984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson /// State manipulation 337984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 338984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void setViewport(int width, int height) { mState.setViewport(width, height); } 339984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 340984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual int getSaveCount() const; 341984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual int save(int flags); 342984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void restore(); 343984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void restoreToCount(int saveCount); 344984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 345984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void getMatrix(SkMatrix* outMatrix) const { mState.getMatrix(outMatrix); } 346984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void setMatrix(const SkMatrix& matrix) { mState.setMatrix(matrix); } 347984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void concatMatrix(const SkMatrix& matrix) { mState.concatMatrix(matrix); } 348984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 349984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void translate(float dx, float dy, float dz = 0.0f); 350984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void rotate(float degrees); 351984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void scale(float sx, float sy); 352984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void skew(float sx, float sy); 353984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 354984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson void setMatrix(const Matrix4& matrix); // internal only convenience method 355984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson void concatMatrix(const Matrix4& matrix); // internal only convenience method 356984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 357984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual const Rect& getLocalClipBounds() const { return mState.getLocalClipBounds(); } 358984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); } 359984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual bool quickRejectConservative(float left, float top, float right, float bottom) const { 360984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson return mState.quickRejectConservative(left, top, right, bottom); 361984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson } 362984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 363984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); 364984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual bool clipPath(const SkPath* path, SkRegion::Op op); 365984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual bool clipRegion(const SkRegion* region, SkRegion::Op op); 366984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 367984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson /** 368984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson * Does not support different clipping Ops (that is, every call to setClippingOutline is 369984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson * effectively using SkRegion::kReplaceOp) 370984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson * 371984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson * The clipping outline is independent from the regular clip. 372984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson */ 373984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson void setClippingOutline(LinearAllocator& allocator, const Outline* outline); 374984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson void setClippingRoundRect(LinearAllocator& allocator, 375984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson const Rect& rect, float radius, bool highPriority = true); 376984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 377984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson inline bool hasRectToRectTransform() const { return mState.hasRectToRectTransform(); } 378984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson inline const mat4* currentTransform() const { return mState.currentTransform(); } 379984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 380984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson /////////////////////////////////////////////////////////////////// 381984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson /// CanvasStateClient interface 382984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 383984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void onViewportInitialized(); 384984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored); 385984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson virtual GLuint onGetTargetFbo() const { return 0; } 386984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 387e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected: 388e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy /** 38996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Perform the setup specific to a frame. This method does not 39096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * issue any OpenGL commands. 39196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 39296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void setupFrameState(float left, float top, float right, float bottom, bool opaque); 39396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 39496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 39596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Indicates the start of rendering. This method will setup the 39696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * initial OpenGL state (viewport, clearing the buffer, etc.) 39796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 398107843de4507b3511006cb9c77b8d0364374385aTom Hudson void startFrame(); 39996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 40096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 4017c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy * Clears the underlying surface if needed. 4027c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy */ 403107843de4507b3511006cb9c77b8d0364374385aTom Hudson virtual void clear(float left, float top, float right, float bottom, bool opaque); 4047c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 4057c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy /** 40635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Call this method after updating a layer during a drawing pass. 40735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 40835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy void resumeAfterLayer(); 40935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 41035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 4118ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * This method is called whenever a stencil buffer is required. Subclasses 4128ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * should override this method and call attachStencilBufferToLayer() on the 4138ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * appropriate layer(s). 4148ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 4158ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy virtual void ensureStencilBuffer(); 4168ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 4178ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 4188ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Obtains a stencil render buffer (allocating it if necessary) and 4198ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * attaches it to the specified layer. 4208ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 4218ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void attachStencilBufferToLayer(Layer* layer); 4228ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 423f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik bool quickRejectSetupScissor(float left, float top, float right, float bottom, 424d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint = NULL); 425d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) { 426f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik return quickRejectSetupScissor(bounds.left, bounds.top, 427f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik bounds.right, bounds.bottom, paint); 428f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik } 429f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik 4308ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 431e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * Compose the layer defined in the current snapshot with the layer 432e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * defined by the previous snapshot. 433e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 434e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 435e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 436e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param curent The current snapshot containing the layer to compose 437e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param previous The previous snapshot to compose the current layer with 438e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy */ 43914e513058ed4168c94e015638d16f5f87fd8063aChris Craik virtual void composeLayer(const Snapshot& current, const Snapshot& previous); 440694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 441ada830f639591b99c3e40de22b07296c7932a33fRomain Guy /** 442f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Marks the specified region as dirty at the specified bounds. 443ada830f639591b99c3e40de22b07296c7932a33fRomain Guy */ 444f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayerUnchecked(Rect& bounds, Region* region); 445ada830f639591b99c3e40de22b07296c7932a33fRomain Guy 44642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 44742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the region of the current layer. 44842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 449624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual Region* getRegion() const { 450984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson return mState.currentRegion(); 451f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 452f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 45342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 45442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Indicates whether rendering is currently targeted at a layer. 45542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 456624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual bool hasLayer() const { 457984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson return (mState.currentFlags() & Snapshot::kFlagFboTarget) && mState.currentRegion(); 458f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 4591bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy 46042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy 46177a811610f99e21da7f88dafef60d09f345d0506Romain Guy /** 46277a811610f99e21da7f88dafef60d09f345d0506Romain Guy * Renders the specified layer as a textured quad. 46377a811610f99e21da7f88dafef60d09f345d0506Romain Guy * 46477a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param layer The layer to render 46577a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param rect The bounds of the layer 46677a811610f99e21da7f88dafef60d09f345d0506Romain Guy */ 46777a811610f99e21da7f88dafef60d09f345d0506Romain Guy void drawTextureLayer(Layer* layer, const Rect& rect); 46877a811610f99e21da7f88dafef60d09f345d0506Romain Guy 469be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 470be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * Gets the alpha and xfermode out of a paint object. If the paint is null 47116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both 47216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * snapshot alpha, and overrideLayerAlpha 473be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * 474be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param paint The paint to extract values from 475be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param alpha Where to store the resulting alpha 476be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param mode Where to store the resulting xfermode 477be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 478d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const; 47916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik 48016ecda5317c40fc3da284952d9b3add34d6763aeChris Craik /** 48116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha 48216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * 48316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * @param layer The layer from which the alpha is extracted 48416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik */ 48576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger inline float getLayerAlpha(const Layer* layer) const; 486be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 487be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 48876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * Safely retrieves the ColorFilter from the given Paint. If the paint is 48976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * null then null is returned. 490be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 49176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger static inline SkColorFilter* getColorFilter(const SkPaint* paint) { 49276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger return paint ? paint->getColorFilter() : NULL; 493be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy } 494be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 49511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy /** 496d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * Safely retrieves the Shader from the given Paint. If the paint is 497d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * null then null is returned. 498d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III */ 499d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III static inline const SkShader* getShader(const SkPaint* paint) { 500d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III return paint ? paint->getShader() : NULL; 501d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III } 502d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III 503d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III /** 50411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy * Set to true to suppress error checks at the end of a frame. 50511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy */ 506624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual bool suppressErrorChecks() const { 50711cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy return false; 50811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy } 50911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 5103b20251a355c88193c439f928a84ae69483fb488John Reck inline RenderState& renderState() { return mRenderState; } 5113b20251a355c88193c439f928a84ae69483fb488John Reck 512984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson CanvasState mState; 513984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson 51408ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate: 5155cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 516dcfc836b457a87881da409e1acf251515f121446Romain Guy * Discards the content of the framebuffer if supported by the driver. 517dcfc836b457a87881da409e1acf251515f121446Romain Guy * This method should be called at the beginning of a frame to optimize 518dcfc836b457a87881da409e1acf251515f121446Romain Guy * rendering on some tiler architectures. 519dcfc836b457a87881da409e1acf251515f121446Romain Guy */ 520dcfc836b457a87881da409e1acf251515f121446Romain Guy void discardFramebuffer(float left, float top, float right, float bottom); 521dcfc836b457a87881da409e1acf251515f121446Romain Guy 522dcfc836b457a87881da409e1acf251515f121446Romain Guy /** 523ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * Ensures the state of the renderer is the same as the state of 524ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * the GL context. 525ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy */ 526ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy void syncState(); 527ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy 528ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy /** 5292b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 530d6b65f67717025b1162f86f04e2caa5723566cacChris Craik * This method will use the current layer space clip rect. 5312b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * This method needs to be invoked every time getTargetFbo() is 5322b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * bound again. 5332b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 53433f5a59ac3e304970920dda824958870f85f76efhenry.uh_chen void startTilingCurrentClip(bool opaque = false, bool expand = false); 5352b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 5362b7028eabac80cec170572bc0e945a1d4224e595Romain Guy /** 537c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 538c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * This method needs to be invoked every time getTargetFbo() is 539c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * bound again. 540c3fedafc5f50100219449125a000e3138f6fb987Romain Guy */ 54133f5a59ac3e304970920dda824958870f85f76efhenry.uh_chen void startTiling(const Rect& clip, int windowHeight, bool opaque = false, bool expand = false); 542c3fedafc5f50100219449125a000e3138f6fb987Romain Guy 543c3fedafc5f50100219449125a000e3138f6fb987Romain Guy /** 5442b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU that we are done drawing the frame or that we 5452b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * are switching to another render target. 5462b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 5472b7028eabac80cec170572bc0e945a1d4224e595Romain Guy void endTiling(); 5482b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 5495cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 5505cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Sets the clipping rectangle using glScissor. The clip is defined by 5515cbbce535744b89df5ecea95de21ee3733298260Romain Guy * the current snapshot's clipRect member. 5525cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 553bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void setScissorFromClip(); 554bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 5555cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 5568ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Sets the clipping region using the stencil buffer. The clip region 5578ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * is defined by the current snapshot's clipRegion member. 5588ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 5598ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void setStencilFromClip(); 5608ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 5618ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 562408eb12631376cbdc96803e918decf6ea804d346Chris Craik * Given the local bounds of the layer, calculates ... 563d90144db52c7297879b950cbbc85137ed123ab5bChris Craik */ 564d90144db52c7297879b950cbbc85137ed123ab5bChris Craik void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer); 565d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 566d90144db52c7297879b950cbbc85137ed123ab5bChris Craik /** 567408eb12631376cbdc96803e918decf6ea804d346Chris Craik * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible 568408eb12631376cbdc96803e918decf6ea804d346Chris Craik */ 569408eb12631376cbdc96803e918decf6ea804d346Chris Craik void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip, 570408eb12631376cbdc96803e918decf6ea804d346Chris Craik bool fboLayer, int alpha); 571408eb12631376cbdc96803e918decf6ea804d346Chris Craik 572408eb12631376cbdc96803e918decf6ea804d346Chris Craik /** 573d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Creates a new layer stored in the specified snapshot. 574d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 575d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param snapshot The snapshot associated with the new layer 576d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param left The left coordinate of the layer 577d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param top The top coordinate of the layer 578d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param right The right coordinate of the layer 579d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param bottom The bottom coordinate of the layer 580d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param alpha The translucency of the layer 581d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode of the layer 582d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param flags The layer save flags 5833f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik * @param mask A mask to use when drawing the layer back, may be empty 584d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 585d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @return True if the layer was successfully created, false otherwise 586d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 587d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase bool createLayer(float left, float top, float right, float bottom, 5883f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik const SkPaint* paint, int flags, const SkPath* convexMask); 589d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 590d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 5915b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Creates a new layer stored in the specified snapshot as an FBO. 5925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5935b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to store as an FBO 5945b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param snapshot The snapshot associated with the new layer 5955b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param bounds The bounds of the layer 5965b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 597e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip); 5985b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 5995b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 6005b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a region. 6015b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 6025b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 6035b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 6045b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 6055b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRegion(Layer* layer, const Rect& rect); 6065b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 6075b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 6085b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a simple rectangle. 6095b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 6105b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 6115b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 6125b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param swap If true, the source and destination are swapped 6135b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 6145b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false); 6155b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 61654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 61754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Clears all the regions corresponding to the current list of layers. 61854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method MUST be invoked before any drawing operation. 61954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 62054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void clearLayerRegions(); 62154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 62254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 623f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. The coordinates 624f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * are transformed with the supplied matrix. 625f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 626f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 627f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom, const mat4 transform); 628f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 629f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 630f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. 631f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 632f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 633f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom); 634f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 635f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 6365cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a colored rectangle with the specified color. The specified coordinates 637735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * are transformed by the current snapshot's transform matrix unless specified 638735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * otherwise. 6395cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 6405cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 6415cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 6425cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 6435cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 64476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the color, blending mode, etc. 6453d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy * @param ignoreTransform True if the current transform should be ignored 6465cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 647026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void drawColorRect(float left, float top, float right, float bottom, 64876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool ignoreTransform = false); 6495cbbce535744b89df5ecea95de21ee3733298260Romain Guy 65054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 651735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * Draws a series of colored rectangles with the specified color. The specified 652735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * coordinates are transformed by the current snapshot's transform matrix unless 653735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * specified otherwise. 654735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * 655735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param rects A list of rectangles, 4 floats (left, top, right, bottom) 656735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * per rectangle 65776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the color, blending mode, etc. 658735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param ignoreTransform True if the current transform should be ignored 6598ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * @param dirty True if calling this method should dirty the current layer 6603bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy * @param clip True if the rects should be clipped, false otherwise 661735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy */ 662107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawColorRects(const float* rects, int count, const SkPaint* paint, 66376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger bool ignoreTransform = false, bool dirty = true, bool clip = true); 664735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy 665735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy /** 66654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the shape represented by the specified path texture. 66754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method invokes drawPathTexture() but takes into account 66854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * the extra left/top offset and the texture offset to correctly 66954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * position the final shape. 67054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 67154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The left coordinate of the shape to render 67254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The top coordinate of the shape to render 67354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture reprsenting the shape 67454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the shape with 67554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 676107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint); 67754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 67854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 67954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey 68054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * different compositing rules. 68154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 68254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to draw with 68354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The x coordinate of the bitmap 68454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The y coordinate of the bitmap 68554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to render with 68654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 687d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawAlphaBitmap(Texture* texture, float left, float top, const SkPaint* paint); 688a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy 68954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 69065cd612face362d054a85d0f7e5881c59cd523beChris Craik * Renders a strip of polygons with the specified paint, used for tessellated geometry. 69165cd612face362d054a85d0f7e5881c59cd523beChris Craik * 69265cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param vertexBuffer The VertexBuffer to be drawn 69365cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param paint The paint to render with 694bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik * @param flags flags with which to draw 69565cd612face362d054a85d0f7e5881c59cd523beChris Craik */ 696107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer, 697bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik const SkPaint* paint, int flags = 0); 69865cd612face362d054a85d0f7e5881c59cd523beChris Craik 69965cd612face362d054a85d0f7e5881c59cd523beChris Craik /** 70005f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik * Convenience for translating method 70105f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik */ 702107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawVertexBuffer(const VertexBuffer& vertexBuffer, 703bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik const SkPaint* paint, int flags = 0) { 704107843de4507b3511006cb9c77b8d0364374385aTom Hudson drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags); 70505f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik } 70605f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik 70705f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik /** 708710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * Renders the convex hull defined by the specified path as a strip of polygons. 70954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 710710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * @param path The hull of the path to draw 711cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik * @param paint The paint to render with 71254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 713107843de4507b3511006cb9c77b8d0364374385aTom Hudson void drawConvexPath(const SkPath& path, const SkPaint* paint); 714858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase 7155cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 7165cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 7175cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 7185cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 7195cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 7205cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 7215cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 7225cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 72382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture to use 72482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param paint The paint containing the alpha, blending mode, etc. 72582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 726a979474f15b454c8e2963f239a3770e200bb227cRomain Guy void drawTextureRect(float left, float top, float right, float bottom, 727d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik Texture* texture, const SkPaint* paint); 72882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 72982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy /** 73003750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * Draws a textured mesh with the specified texture. If the indices are omitted, 73103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * the mesh is drawn as a simple quad. The mesh pointers become offsets when a 73203750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * VBO is bound. 73382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 73482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 73582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 73682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 73782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 73882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture name to map onto the rectangle 73976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the alpha, blending mode, colorFilter, etc. 74082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param blend True if the texture contains an alpha channel 74182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param vertices The vertices that define the mesh 74282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texCoords The texture coordinates of each vertex 74382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param elementsCount The number of elements in the mesh, required by indices 744f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param swapSrcDst Whether or not the src and dst blending operations should be swapped 745f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param ignoreTransform True if the current transform should be ignored 74603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * @param vbo The VBO used to draw the mesh 7474063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param modelViewMode Defines whether the model view matrix should be scaled 7485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param dirty True if calling this method should dirty the current layer 749f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 750f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, 75176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool blend, 7526820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 7535b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 7544063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true); 755f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 7563b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture, 75776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool blend, 7583b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 7593b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 7604063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true); 7613b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 762886b275e529e44a59c54b933453d9bc902973178Romain Guy void drawAlpha8TextureMesh(float left, float top, float right, float bottom, 76376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger GLuint texture, const SkPaint* paint, 764886b275e529e44a59c54b933453d9bc902973178Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 7654063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik bool ignoreTransform, ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, 7664063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik bool dirty = true); 767886b275e529e44a59c54b933453d9bc902973178Romain Guy 768f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 769448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * Draws the specified list of vertices as quads using indexed GL_TRIANGLES. 770448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * If the number of vertices to draw exceeds the number of indices we have 771448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * pre-allocated, this method will generate several glDrawElements() calls. 772448455fe783b0a711340322dca272b8cc0ebe473Romain Guy */ 7734063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik void issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount); 774448455fe783b0a711340322dca272b8cc0ebe473Romain Guy 775448455fe783b0a711340322dca272b8cc0ebe473Romain Guy /** 7760a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * Draws text underline and strike-through if needed. 7770a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * 7780a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param text The text to decor 7790a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param bytesCount The number of bytes in the text 78041541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik * @param totalAdvance The total advance in pixels, defines underline/strikethrough length 7810a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param x The x coordinate where the text will be drawn 7820a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param y The y coordinate where the text will be drawn 7830a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param paint The paint to draw the text with 7840a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy */ 785d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint); 7861e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 787416a847633680d94efb926837efdc18726d54918Raph Levien /** 788416a847633680d94efb926837efdc18726d54918Raph Levien * Draws shadow layer on text (with optional positions). 789416a847633680d94efb926837efdc18726d54918Raph Levien * 790416a847633680d94efb926837efdc18726d54918Raph Levien * @param paint The paint to draw the shadow with 791416a847633680d94efb926837efdc18726d54918Raph Levien * @param text The text to draw 792416a847633680d94efb926837efdc18726d54918Raph Levien * @param bytesCount The number of bytes in the text 793416a847633680d94efb926837efdc18726d54918Raph Levien * @param count The number of glyphs in the text 794416a847633680d94efb926837efdc18726d54918Raph Levien * @param positions The x, y positions of individual glyphs (or NULL) 795416a847633680d94efb926837efdc18726d54918Raph Levien * @param fontRenderer The font renderer object 796416a847633680d94efb926837efdc18726d54918Raph Levien * @param alpha The alpha value for drawing the shadow 797416a847633680d94efb926837efdc18726d54918Raph Levien * @param x The x coordinate where the shadow will be drawn 798416a847633680d94efb926837efdc18726d54918Raph Levien * @param y The y coordinate where the shadow will be drawn 799416a847633680d94efb926837efdc18726d54918Raph Levien */ 800d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count, 80176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const float* positions, FontRenderer& fontRenderer, int alpha, 802416a847633680d94efb926837efdc18726d54918Raph Levien float x, float y); 803416a847633680d94efb926837efdc18726d54918Raph Levien 80454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 80554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws a path texture. Path textures are alpha8 bitmaps that need special 80654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * compositing to apply colors/filters/etc. 80754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 80854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to render 80954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param x The x coordinate where the texture will be drawn 81054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param y The y coordinate where the texture will be drawn 81154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the texture with 81254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 813d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint); 81401d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy 8151e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy /** 816ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Resets the texture coordinates stored in mMeshVertices. Setting the values 817026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * back to default is achieved by calling: 818026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 8198ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 820026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 821026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u1 The left coordinate of the texture 822026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v1 The bottom coordinate of the texture 823026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u2 The right coordinate of the texture 824026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v2 The top coordinate of the texture 825026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 826026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 827026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 8288ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy /** 829768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy * Returns true if the specified paint will draw invisible text. 830768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy */ 831768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy bool canSkipText(const SkPaint* paint) const; 832768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy 833768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy /** 834746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Binds the specified texture. The texture unit must have been selected 835746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * prior to calling this method. 836a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy */ 837746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void bindTexture(GLuint texture) { 8388aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy mCaches.bindTexture(texture); 839746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 840746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 841746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 842aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Binds the specified EGLImage texture. The texture unit must have been selected 843aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * prior to calling this method. 844aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 845aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy inline void bindExternalTexture(GLuint texture) { 8468aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture); 847aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy } 848aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 849aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 85082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Enable or disable blending as necessary. This function sets the appropriate 85182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * blend function based on the specified xfermode. 85282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 853f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description, 854f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy bool swapSrcDst = false); 855a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy 856f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy /** 857d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Use the specified program with the current GL context. If the program is already 858d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * in use, it will not be bound again. If it is not in use, the current program is 859d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * marked unused and the specified program becomes used and becomes the new 860d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * current program. 8616926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy * 862d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param program The program to use 863d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 864d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @return true If the specified program was already in use, false otherwise. 865260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy */ 866889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy inline bool useProgram(Program* program); 867260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy 868746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 869746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Invoked before any drawing operation. This sets required state. 870746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 87154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void setupDraw(bool clear = true); 87217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 87370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy /** 87470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy * Various methods to setup OpenGL rendering. 87570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy */ 87670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawWithTexture(bool isAlpha8 = false); 877ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy void setupDrawWithTextureAndColor(bool isAlpha8 = false); 878aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawWithExternalTexture(); 87915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy void setupDrawNoTexture(); 88091a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik void setupDrawVertexAlpha(bool useShadowAlphaInterp); 8818d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy void setupDrawColor(int color, int alpha); 88270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColor(float r, float g, float b, float a); 88386568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawAlpha8Color(int color, int alpha); 8844121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGamma(const SkPaint* paint); 885d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III void setupDrawShader(const SkShader* shader); 88676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawColorFilter(const SkColorFilter* filter); 88776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawBlending(const Layer* layer, bool swapSrcDst = false); 88876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawBlending(const SkPaint* paint, bool blend = true, bool swapSrcDst = false); 88970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawProgram(); 89070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawDirtyRegionsDisabled(); 8914063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 8924063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 8934063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Setup the current program matrices based upon the nature of the geometry. 8944063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8954063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param mode If kModelViewMode_Translate, the geometry must be translated by the left and top 8964063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * parameters. If kModelViewMode_TranslateAndScale, the geometry that exists in the (0,0, 1,1) 8974063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * space must be scaled up and translated to fill the quad provided in (l,t,r,b). These 8984063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * transformations are stored in the modelView matrix and uploaded to the shader. 8994063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9004063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate 901564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik * geometry pixel positioning. See Vertex::GeometryFudgeFactor(). 9024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9034063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space, 9044063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil, 9054063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * or when simple translation has been extracted) 9064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 9074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik void setupDrawModelView(ModelViewMode mode, bool offset, 9084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik float left, float top, float right, float bottom, bool ignoreTransform = false); 909d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III void setupDrawColorUniforms(bool hasShader); 91086568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawPureColorUniforms(); 911d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III 912d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III /** 913d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * Setup uniforms for the current shader. 914d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * 915d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * @param shader SkShader on the current paint. 916d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * 917d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III * @param ignoreTransform Set to true to ignore the transform in shader. 918d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III */ 919d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III void setupDrawShaderUniforms(const SkShader* shader, bool ignoreTransform = false); 92076d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawColorFilterUniforms(const SkColorFilter* paint); 92170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawSimpleMesh(); 92270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawTexture(GLuint texture); 923aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawExternalTexture(GLuint texture); 9248f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransform(); 9258f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransformUniforms(mat4& transform); 9264121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGammaUniforms(); 927564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0); 928564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors); 929564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0); 930448455fe783b0a711340322dca272b8cc0ebe473Romain Guy void setupDrawIndexedVertices(GLvoid* vertices); 931f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy void accountForClear(SkXfermode::Mode mode); 932746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 93311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy bool updateLayer(Layer* layer, bool inFrame); 93411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy void updateLayers(); 93596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void flushLayers(); 93611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 937e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#if DEBUG_LAYERS_AS_REGIONS 93817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 93917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Renders the specified region as a series of rectangles. This method 94017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * is used for debugging only. 94117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 942e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik void drawRegionRectsDebug(const Region& region); 943e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#endif 9443a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy 9458ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 9468ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Renders the specified region as a series of rectangles. The region 9478ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * must be in screen-space coordinates. 9488ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 94976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false); 9508ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 9518ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 9528ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS 9538ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * is turned on. 9548ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 9558ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void debugClip(); 9568ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 9577c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void debugOverdraw(bool enable, bool clear); 9587c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void renderOverdraw(); 95978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy void countOverdraw(); 9607c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy 961746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 962746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Should be invoked every time the glScissor is modified. 963746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 964984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson inline void dirtyClip() { mState.setDirtyClip(true); } 965746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 9663b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy inline const UvMapper& getMapper(const Texture* texture) { 9673b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper; 9683b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy } 9693b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 9703b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy /** 9713b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * Returns a texture object for the specified bitmap. The texture can 9723b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * come from the texture cache or an atlas. If this method returns 9733b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * NULL, the texture could not be found and/or allocated. 9743b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy */ 975d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik Texture* getTexture(const SkBitmap* bitmap); 9763b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 977107843de4507b3511006cb9c77b8d0364374385aTom Hudson bool reportAndClearDirty() { bool ret = mDirty; mDirty = false; return ret; } 978984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson inline Snapshot* writableSnapshot() { return mState.writableSnapshot(); } 979984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson inline const Snapshot* currentSnapshot() const { return mState.currentSnapshot(); } 980107843de4507b3511006cb9c77b8d0364374385aTom Hudson 9814063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 9824063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Model-view matrix used to position/size objects 9834063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9844063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Stores operation-local modifications to the draw matrix that aren't incorporated into the 9854063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * currentTransform(). 9864063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 987e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * If generated with kModelViewMode_Translate, mModelViewMatrix will reflect an x/y offset, 9884063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale, 989e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * mModelViewMatrix will reflect a translation and scale, e.g. the translation and scale 990e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * required to make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height 991e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik * of a bitmap. 9924063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9934063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used as input to SkiaShader transformation. 9944063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 995e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik mat4 mModelViewMatrix; 996c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 9972b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // State used to define the clipping region 9985f803623559aab395a29d575c37c4e39c23a4b4eChris Craik Rect mTilingClip; 99996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy // Is the target render surface opaque 100096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy bool mOpaque; 100196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy // Is a frame currently being rendered 100296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy bool mFrameStarted; 10039d5316e3f56d138504565ff311145ac01621dff4Romain Guy 1004026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy // Used to draw textured quads 1005ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy TextureVertex mMeshVertices[4]; 1006ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 10073b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy // Default UV mapper 10083b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy const UvMapper mUvMapper; 10093b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 1010c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik // shader, filters, and shadow 1011c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik DrawModifiers mDrawModifiers; 10125ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy SkPaint mFilteredPaint; 10135ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 101482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Various caches 1015fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy Caches& mCaches; 10163bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy Extensions& mExtensions; 10173b20251a355c88193c439f928a84ae69483fb488John Reck RenderState& mRenderState; 10188694230ff25fa0a60e480d424843e56b718f0516Romain Guy 10198f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy // List of rectangles to clear after saveLayer() is invoked 102054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy Vector<Rect*> mLayers; 102111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy // List of layers to update at the beginning of a frame 10220e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck Vector< sp<Layer> > mLayerUpdates; 102354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 102470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // The following fields are used to setup drawing 102570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Used to describe the shaders to generate 102670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy ProgramDescription mDescription; 102770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Color description 102870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mColorSet; 102970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy float mColorA, mColorR, mColorG, mColorB; 103070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Indicates that the shader should get a color 103170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mSetShaderColor; 103270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Current texture unit 103370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy GLuint mTextureUnit; 103470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Track dirty regions, true by default 103570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mTrackDirtyRegions; 10362b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // Indicate whether we are drawing an opaque frame 10372b7028eabac80cec170572bc0e945a1d4224e595Romain Guy bool mOpaqueFrame; 103870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy 103987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in 104087e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // Properties.h 104187e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy bool mScissorOptimizationDisabled; 104287e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 104354c1a64d5441a964890b44280e4457e11f4f924aRomain Guy // No-ops start/endTiling when set 104454c1a64d5441a964890b44280e4457e11f4f924aRomain Guy bool mSuppressTiling; 1045284b24358410cb0200e525a5ba36994090c83f20Chris Craik bool mFirstFrameAfterResize; 104654c1a64d5441a964890b44280e4457e11f4f924aRomain Guy 1047deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik bool mSkipOutlineClip; 1048deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik 1049107843de4507b3511006cb9c77b8d0364374385aTom Hudson // True if anything has been drawn since the last call to 1050107843de4507b3511006cb9c77b8d0364374385aTom Hudson // reportAndClearDirty() 1051107843de4507b3511006cb9c77b8d0364374385aTom Hudson bool mDirty; 1052107843de4507b3511006cb9c77b8d0364374385aTom Hudson 1053058fc640017c90120c599d378a4cbc55668b05b7Chris Craik // Lighting + shadows 1054058fc640017c90120c599d378a4cbc55668b05b7Chris Craik Vector3 mLightCenter; 1055058fc640017c90120c599d378a4cbc55668b05b7Chris Craik float mLightRadius; 1056058fc640017c90120c599d378a4cbc55668b05b7Chris Craik uint8_t mAmbientShadowAlpha; 1057058fc640017c90120c599d378a4cbc55668b05b7Chris Craik uint8_t mSpotShadowAlpha; 1058058fc640017c90120c599d378a4cbc55668b05b7Chris Craik 105996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy friend class Layer; 1060257ae3502cfad43df681b1783528d645bdabc63fRomain Guy friend class TextSetupFunctor; 106103c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy friend class DrawBitmapOp; 106203c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy friend class DrawPatchOp; 1063b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy 1064bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer 1065e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 10669d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer 1067e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android 1068e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 10695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H 1070