OpenGLRenderer.h revision e18264b079481a244b30e3f71012c53bbd861f92
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> 29d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy#include <SkShader.h> 3085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h> 31e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 32daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h> 33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h> 34ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h> 358694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h> 36bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 377953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h> 387953745dd565167113f8cbfc461bc0521d32d870Romain Guy 393b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include <androidfw/ResourceTypes.h> 403b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 41c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h" 4251769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h" 43f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h" 445cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h" 45bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h" 46b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Renderer.h" 4714e513058ed4168c94e015638d16f5f87fd8063aChris Craik#include "StatefulBaseRenderer.h" 48b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Snapshot.h" 493b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include "UvMapper.h" 50b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Vertex.h" 51fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h" 52bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 53e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android { 549d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer { 55e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 56b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DeferredDisplayState; 57e18264b079481a244b30e3f71012c53bbd861f92John Reckclass RenderNode; 58b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass TextSetupFunctor; 59b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass VertexBuffer; 60b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass SkiaShader; 61b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik 62c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers { 639b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy DrawModifiers() { 649b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy reset(); 659b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy } 669b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy 679b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy void reset() { 689b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy memset(this, 0, sizeof(DrawModifiers)); 699b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy } 709b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy 71c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik SkiaShader* mShader; 7216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik float mOverrideLayerAlpha; 73c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 74c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik // Drop shadow 75c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik bool mHasShadow; 76c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik float mShadowRadius; 77c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik float mShadowDx; 78c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik float mShadowDy; 79c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik int mShadowColor; 80c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 81c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik // Draw filters 82c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik bool mHasDrawFilter; 83c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik int mPaintFilterClearBits; 84c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik int mPaintFilterSetBits; 85c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik}; 86c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 87ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags { 88ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik kStateDeferFlag_Draw = 0x1, 89ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik kStateDeferFlag_Clip = 0x2 90ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik}; 91ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik 9228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags { 93a02c4ed885d97e516f844ddb0a96083f1b45b4cbChris Craik kClipSide_None = 0x0, 9428ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Left = 0x1, 9528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Top = 0x2, 9628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Right = 0x4, 9728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik kClipSide_Bottom = 0x8, 98d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik kClipSide_Full = 0xF, 99d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik kClipSide_ConservativeFull = 0x1F 10028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik}; 10128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik 1024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik/** 1034063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Defines additional transformation that should be applied by the model view matrix, beyond that of 1044063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * the currentTransform() 1054063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craikenum ModelViewMode { 1074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 1084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used when the model view should simply translate geometry passed to the shader. The resulting 1094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * matrix will be a simple translation. 1104063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1114063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik kModelViewMode_Translate = 0, 1124063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 1134063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 1144063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used when the model view should translate and scale geometry. The resulting matrix will be a 1154063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect. 1164063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 1174063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik kModelViewMode_TranslateAndScale = 1, 1184063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik}; 1194063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 12063d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghuienum VertexBufferMode { 12163d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghui kVertexBufferMode_Standard = 0, 12263d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghui kVertexBufferMode_Shadow = 1 12363d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghui}; 12463d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghui 125f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 126f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer 127f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy/////////////////////////////////////////////////////////////////////////////// 1285cbbce535744b89df5ecea95de21ee3733298260Romain Guy/** 12914e513058ed4168c94e015638d16f5f87fd8063aChris Craik * OpenGL Renderer implementation. 1305cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 13114e513058ed4168c94e015638d16f5f87fd8063aChris Craikclass OpenGLRenderer : public StatefulBaseRenderer { 132e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic: 1337953745dd565167113f8cbfc461bc0521d32d870Romain Guy ANDROID_API OpenGLRenderer(); 134e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy virtual ~OpenGLRenderer(); 135e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 13687e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy ANDROID_API void initProperties(); 13787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 138b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy virtual void setViewport(int width, int height); 1397c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque); 14017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy virtual void finish(); 141c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy virtual void interrupt(); 142c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy virtual void resume(); 143c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy 14478dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy ANDROID_API void setCountOverdrawEnabled(bool enabled) { 14578dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy mCountOverdraw = enabled; 14678dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy } 14778dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy 14878dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy ANDROID_API float getOverdraw() { 14978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy return mCountOverdraw ? mOverdraw : 0.0f; 15078dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy } 15178dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy 1528f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy ANDROID_API status_t invokeFunctors(Rect& dirty); 153ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy ANDROID_API void detachFunctor(Functor* functor); 154ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy ANDROID_API void attachFunctor(Functor* functor); 1558f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty); 15608ae317c21ec3086b5017672bba87420cc38a407Romain Guy 15711cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy ANDROID_API void pushLayerUpdate(Layer* layer); 158e93482f5eac3df581d57e64c2a771a96aa868585Romain Guy ANDROID_API void cancelLayerUpdate(Layer* layer); 15911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy ANDROID_API void clearLayerUpdates(); 160405436021da156fbe3c5d4de48bdefa564cf7fc0Romain Guy ANDROID_API void flushLayerUpdates(); 16111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 162d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger ANDROID_API virtual int saveLayer(float left, float top, float right, float bottom, 163d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger const SkPaint* paint, int flags); 164bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 165d90144db52c7297879b950cbbc85137ed123ab5bChris Craik int saveLayerDeferred(float left, float top, float right, float bottom, 166d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger const SkPaint* paint, int flags); 167d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 168e18264b079481a244b30e3f71012c53bbd861f92John Reck virtual status_t drawDisplayList(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1); 169a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik virtual status_t drawLayer(Layer* layer, float x, float y); 170d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawBitmap(const SkBitmap* bitmap, float left, float top, 171d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 172d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik status_t drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount, 173d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint); 174d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawBitmap(const SkBitmap* bitmap, const SkMatrix* matrix, 175d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 176d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop, 177e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy float srcRight, float srcBottom, float dstLeft, float dstTop, 178d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float dstRight, float dstBottom, const SkPaint* paint); 179d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawBitmapData(const SkBitmap* bitmap, float left, float top, 180d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 181d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight, 182d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* vertices, const int* colors, const SkPaint* paint); 183d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry, 184d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint); 185d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, 186d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float left, float top, float right, float bottom, const SkPaint* paint); 187d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik status_t drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry, 188d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float left, float top, float right, float bottom, const SkPaint* paint); 189486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawColor(int color, SkXfermode::Mode mode); 190d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawRect(float left, float top, float right, float bottom, 191d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 192486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawRoundRect(float left, float top, float right, float bottom, 193d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float rx, float ry, const SkPaint* paint); 194d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawCircle(float x, float y, float radius, const SkPaint* paint); 195d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawOval(float left, float top, float right, float bottom, 196d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint); 197486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawArc(float left, float top, float right, float bottom, 198d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint); 199d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawPath(const SkPath* path, const SkPaint* paint); 200d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawLines(const float* points, int count, const SkPaint* paint); 201d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawPoints(const float* points, int count, const SkPaint* paint); 202d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path, 203d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik float hOffset, float vOffset, const SkPaint* paint); 204486590963e2207d68eebd6944fec70d50d41116aChet Haase virtual status_t drawPosText(const char* text, int bytesCount, int count, 205d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* positions, const SkPaint* paint); 206c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y, 207d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds, 208527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik DrawOpMode drawOpMode = kDrawOpMode_Immediate); 209d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik virtual status_t drawRects(const float* rects, int count, const SkPaint* paint); 21085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy 211b79a3e301a8d89b9e1b1f6f3d7fd6aa56610a6f0Chris Craik status_t drawShadow(const mat4& casterTransformXY, const mat4& casterTransformZ, 212b79a3e301a8d89b9e1b1f6f3d7fd6aa56610a6f0Chris Craik float casterAlpha, const SkPath* casterOutline); 213f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik 2144aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void resetShader(); 2154aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void setupShader(SkiaShader* shader); 216d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 2174aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void resetShadow(); 2184aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy virtual void setupShadow(float radius, float dx, float dy, int color); 2191e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 2205ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy virtual void resetPaintFilter(); 2215ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy virtual void setupPaintFilter(int clearBits, int setBits); 2225ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 22316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer) 22416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; } 22516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik 226d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* filterPaint(const SkPaint* paint); 2275ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 2285e49b307eb99269db2db257760508b8efd7bb97dChris Craik /** 2295e49b307eb99269db2db257760508b8efd7bb97dChris Craik * Store the current display state (most importantly, the current clip and transform), and 2305e49b307eb99269db2db257760508b8efd7bb97dChris Craik * additionally map the state's bounds from local to window coordinates. 2315e49b307eb99269db2db257760508b8efd7bb97dChris Craik * 2325e49b307eb99269db2db257760508b8efd7bb97dChris Craik * Returns true if quick-rejected 2335e49b307eb99269db2db257760508b8efd7bb97dChris Craik */ 234ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags); 235527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false); 23628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik void setupMergedMultiDraw(const Rect* clipRect); 237c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik 238d90144db52c7297879b950cbbc85137ed123ab5bChris Craik const DrawModifiers& getDrawModifiers() { return mDrawModifiers; } 239d90144db52c7297879b950cbbc85137ed123ab5bChris Craik void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; } 240d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 241672433d90fab7383cd28beac9d4485b566a90940Romain Guy ANDROID_API bool isCurrentTransformSimple() { 242d6b65f67717025b1162f86f04e2caa5723566cacChris Craik return currentTransform()->isSimple(); 243672433d90fab7383cd28beac9d4485b566a90940Romain Guy } 244672433d90fab7383cd28beac9d4485b566a90940Romain Guy 2450f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy Caches& getCaches() { 2460f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy return mCaches; 2470f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy } 2480f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy 249ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik // simple rect clip 250ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik bool isCurrentClipSimple() { 251ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik return mSnapshot->clipRegion->isEmpty(); 252ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik } 253ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik 254d6b65f67717025b1162f86f04e2caa5723566cacChris Craik int getViewportWidth() { return currentSnapshot()->viewport.getWidth(); } 255d6b65f67717025b1162f86f04e2caa5723566cacChris Craik int getViewportHeight() { return currentSnapshot()->viewport.getHeight(); } 2560e87f00f8cb79635aa70b9a2dfa02bf19dc7473dChris Craik 25717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 258a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik * Scales the alpha on the current snapshot. This alpha value will be modulated 25917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * with other alpha values when drawing primitives. 26017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 261a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik void scaleAlpha(float alpha) { 262a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik mSnapshot->alpha *= alpha; 26317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy } 26417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 26517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 2660f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy * Inserts a named event marker in the stream of GL commands. 2670f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy */ 2680f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy void eventMark(const char* name) const; 2690f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy 2700f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy /** 27117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Inserts a named group marker in the stream of GL commands. This marker 27217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * can be used by tools to group commands into logical groups. A call to 27317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * this method must always be followed later on by a call to endMark(). 27417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 27513631f3da855f200a151e7837ed9f6b079622b58Romain Guy void startMark(const char* name) const; 27617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 27717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 27817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Closes the last group marker opened by startMark(). 27917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 28013631f3da855f200a151e7837ed9f6b079622b58Romain Guy void endMark() const; 28113631f3da855f200a151e7837ed9f6b079622b58Romain Guy 282d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase /** 283d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Gets the alpha and xfermode out of a paint object. If the paint is null 284d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * alpha will be 255 and the xfermode will be SRC_OVER. This method does 28516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * not multiply the paint's alpha by the current snapshot's alpha, and does 28616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * not replace the alpha with the overrideLayerAlpha 287d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * 288d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param paint The paint to extract values from 289d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param alpha Where to store the resulting alpha 290d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * @param mode Where to store the resulting xfermode 291d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase */ 292d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) { 293527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik *mode = getXfermodeDirect(paint); 294527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik *alpha = getAlphaDirect(paint); 295527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 296527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 297d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) { 298527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (!paint) return SkXfermode::kSrcOver_Mode; 299527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik return getXfermode(paint->getXfermode()); 300527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 301527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 302c1c5f0870282b56dafe5a4d756e4b9e6884655a7Chris Craik static inline int getAlphaDirect(const SkPaint* paint) { 303527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (!paint) return 255; 304527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik return paint->getAlpha(); 305d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase } 306d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase 307624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy /** 308624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy * Return the best transform to use to rasterize text given a full 309624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy * transform matrix. 310624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy */ 311624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy mat4 findBestFontTransform(const mat4& transform) const; 312624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy 313527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR 314527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) { 315527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik mCaches.setScissorEnabled(false); 316527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 317527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik // should only be called outside of other draw ops, so stencil can only be in test state 318527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik bool stencilWasEnabled = mCaches.stencil.isTestEnabled(); 319527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik mCaches.stencil.disable(); 320527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 321527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true); 322527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 323527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik if (stencilWasEnabled) mCaches.stencil.enableTest(); 324527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik } 325527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif 326527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik 327e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected: 328e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy /** 32935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Computes the projection matrix, initialize the first snapshot 33035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * and stores the dimensions of the render target. 33135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 33235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy void initViewport(int width, int height); 33335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 33435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 33596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Perform the setup specific to a frame. This method does not 33696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * issue any OpenGL commands. 33796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 33896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void setupFrameState(float left, float top, float right, float bottom, bool opaque); 33996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 34096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 34196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * Indicates the start of rendering. This method will setup the 34296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy * initial OpenGL state (viewport, clearing the buffer, etc.) 34396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy */ 34496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy status_t startFrame(); 34596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy 34696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy /** 3477c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy * Clears the underlying surface if needed. 3487c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy */ 3497c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy virtual status_t clear(float left, float top, float right, float bottom, bool opaque); 3507c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy 3517c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy /** 35235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy * Call this method after updating a layer during a drawing pass. 35335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy */ 35435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy void resumeAfterLayer(); 35535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy 35635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy /** 3578ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * This method is called whenever a stencil buffer is required. Subclasses 3588ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * should override this method and call attachStencilBufferToLayer() on the 3598ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * appropriate layer(s). 3608ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 3618ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy virtual void ensureStencilBuffer(); 3628ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 3638ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 3648ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Obtains a stencil render buffer (allocating it if necessary) and 3658ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * attaches it to the specified layer. 3668ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 3678ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void attachStencilBufferToLayer(Layer* layer); 3688ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 369f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik bool quickRejectSetupScissor(float left, float top, float right, float bottom, 370d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik const SkPaint* paint = NULL); 371d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) { 372f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik return quickRejectSetupScissor(bounds.left, bounds.top, 373f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik bounds.right, bounds.bottom, paint); 374f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik } 375f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik 3768ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 377e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * Compose the layer defined in the current snapshot with the layer 378e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * defined by the previous snapshot. 379e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 380e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 381e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * 382e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param curent The current snapshot containing the layer to compose 383e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy * @param previous The previous snapshot to compose the current layer with 384e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy */ 38514e513058ed4168c94e015638d16f5f87fd8063aChris Craik virtual void composeLayer(const Snapshot& current, const Snapshot& previous); 386694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy 387ada830f639591b99c3e40de22b07296c7932a33fRomain Guy /** 388f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Marks the specified region as dirty at the specified bounds. 389ada830f639591b99c3e40de22b07296c7932a33fRomain Guy */ 390f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayerUnchecked(Rect& bounds, Region* region); 391ada830f639591b99c3e40de22b07296c7932a33fRomain Guy 39242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 39342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the region of the current layer. 39442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 395624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual Region* getRegion() const { 396f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return mSnapshot->region; 397f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 398f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 39942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 40042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Indicates whether rendering is currently targeted at a layer. 40142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 402624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual bool hasLayer() const { 403f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region; 404f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 4051bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy 40642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy /** 40742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy * Returns the name of the FBO this renderer is rendering into. 40842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy */ 40914e513058ed4168c94e015638d16f5f87fd8063aChris Craik virtual GLuint getTargetFbo() const { 41042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy return 0; 41142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy } 41242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy 41377a811610f99e21da7f88dafef60d09f345d0506Romain Guy /** 41477a811610f99e21da7f88dafef60d09f345d0506Romain Guy * Renders the specified layer as a textured quad. 41577a811610f99e21da7f88dafef60d09f345d0506Romain Guy * 41677a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param layer The layer to render 41777a811610f99e21da7f88dafef60d09f345d0506Romain Guy * @param rect The bounds of the layer 41877a811610f99e21da7f88dafef60d09f345d0506Romain Guy */ 41977a811610f99e21da7f88dafef60d09f345d0506Romain Guy void drawTextureLayer(Layer* layer, const Rect& rect); 42077a811610f99e21da7f88dafef60d09f345d0506Romain Guy 421be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 422be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * Gets the alpha and xfermode out of a paint object. If the paint is null 42316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both 42416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * snapshot alpha, and overrideLayerAlpha 425be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * 426be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param paint The paint to extract values from 427be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param alpha Where to store the resulting alpha 428be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy * @param mode Where to store the resulting xfermode 429be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 430d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const; 43116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik 43216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik /** 43316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha 43416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * 43516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik * @param layer The layer from which the alpha is extracted 43616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik */ 43776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger inline float getLayerAlpha(const Layer* layer) const; 438be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 439be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy /** 44076d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * Safely retrieves the ColorFilter from the given Paint. If the paint is 44176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * null then null is returned. 442be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy */ 44376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger static inline SkColorFilter* getColorFilter(const SkPaint* paint) { 44476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger return paint ? paint->getColorFilter() : NULL; 445be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy } 446be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy 44711cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy /** 44811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy * Set to true to suppress error checks at the end of a frame. 44911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy */ 450624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy virtual bool suppressErrorChecks() const { 45111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy return false; 45211cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy } 45311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 45408ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate: 4555cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 456dcfc836b457a87881da409e1acf251515f121446Romain Guy * Discards the content of the framebuffer if supported by the driver. 457dcfc836b457a87881da409e1acf251515f121446Romain Guy * This method should be called at the beginning of a frame to optimize 458dcfc836b457a87881da409e1acf251515f121446Romain Guy * rendering on some tiler architectures. 459dcfc836b457a87881da409e1acf251515f121446Romain Guy */ 460dcfc836b457a87881da409e1acf251515f121446Romain Guy void discardFramebuffer(float left, float top, float right, float bottom); 461dcfc836b457a87881da409e1acf251515f121446Romain Guy 462dcfc836b457a87881da409e1acf251515f121446Romain Guy /** 463ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * Ensures the state of the renderer is the same as the state of 464ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy * the GL context. 465ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy */ 466ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy void syncState(); 467ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy 468ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy /** 4692b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 470d6b65f67717025b1162f86f04e2caa5723566cacChris Craik * This method will use the current layer space clip rect. 4712b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * This method needs to be invoked every time getTargetFbo() is 4722b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * bound again. 4732b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 474d6b65f67717025b1162f86f04e2caa5723566cacChris Craik void startTilingCurrentClip(bool opaque = false); 4752b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 4762b7028eabac80cec170572bc0e945a1d4224e595Romain Guy /** 477c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * Tells the GPU what part of the screen is about to be redrawn. 478c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * This method needs to be invoked every time getTargetFbo() is 479c3fedafc5f50100219449125a000e3138f6fb987Romain Guy * bound again. 480c3fedafc5f50100219449125a000e3138f6fb987Romain Guy */ 481c3fedafc5f50100219449125a000e3138f6fb987Romain Guy void startTiling(const Rect& clip, int windowHeight, bool opaque = false); 482c3fedafc5f50100219449125a000e3138f6fb987Romain Guy 483c3fedafc5f50100219449125a000e3138f6fb987Romain Guy /** 4842b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * Tells the GPU that we are done drawing the frame or that we 4852b7028eabac80cec170572bc0e945a1d4224e595Romain Guy * are switching to another render target. 4862b7028eabac80cec170572bc0e945a1d4224e595Romain Guy */ 4872b7028eabac80cec170572bc0e945a1d4224e595Romain Guy void endTiling(); 4882b7028eabac80cec170572bc0e945a1d4224e595Romain Guy 48914e513058ed4168c94e015638d16f5f87fd8063aChris Craik void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored); 490bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 4915cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 4925cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Sets the clipping rectangle using glScissor. The clip is defined by 4935cbbce535744b89df5ecea95de21ee3733298260Romain Guy * the current snapshot's clipRect member. 4945cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 495bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy void setScissorFromClip(); 496bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 4975cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 4988ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Sets the clipping region using the stencil buffer. The clip region 4998ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * is defined by the current snapshot's clipRegion member. 5008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 5018ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void setStencilFromClip(); 5028ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 5038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 504408eb12631376cbdc96803e918decf6ea804d346Chris Craik * Given the local bounds of the layer, calculates ... 505d90144db52c7297879b950cbbc85137ed123ab5bChris Craik */ 506d90144db52c7297879b950cbbc85137ed123ab5bChris Craik void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer); 507d90144db52c7297879b950cbbc85137ed123ab5bChris Craik 508d90144db52c7297879b950cbbc85137ed123ab5bChris Craik /** 509408eb12631376cbdc96803e918decf6ea804d346Chris Craik * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible 510408eb12631376cbdc96803e918decf6ea804d346Chris Craik */ 511408eb12631376cbdc96803e918decf6ea804d346Chris Craik void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip, 512408eb12631376cbdc96803e918decf6ea804d346Chris Craik bool fboLayer, int alpha); 513408eb12631376cbdc96803e918decf6ea804d346Chris Craik 514408eb12631376cbdc96803e918decf6ea804d346Chris Craik /** 515d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * Creates a new layer stored in the specified snapshot. 516d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 517d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param snapshot The snapshot associated with the new layer 518d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param left The left coordinate of the layer 519d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param top The top coordinate of the layer 520d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param right The right coordinate of the layer 521d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param bottom The bottom coordinate of the layer 522d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param alpha The translucency of the layer 523d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param mode The blending mode of the layer 524d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @param flags The layer save flags 525d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * 526d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy * @return True if the layer was successfully created, false otherwise 527d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy */ 528d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase bool createLayer(float left, float top, float right, float bottom, 529d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger const SkPaint* paint, int flags); 530d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy 531d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy /** 5325b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Creates a new layer stored in the specified snapshot as an FBO. 5335b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5345b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to store as an FBO 5355b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param snapshot The snapshot associated with the new layer 5365b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param bounds The bounds of the layer 5375b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 538e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip); 5395b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 5405b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 5415b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a region. 5425b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5435b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 5445b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 5455b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 5465b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRegion(Layer* layer, const Rect& rect); 5475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 5485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 5495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Compose the specified layer as a simple rectangle. 5505b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * 5515b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param layer The layer to compose 5525b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param rect The layer's bounds 5535b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param swap If true, the source and destination are swapped 5545b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 5555b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false); 5565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 55754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 55854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Clears all the regions corresponding to the current list of layers. 55954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method MUST be invoked before any drawing operation. 56054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 56154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void clearLayerRegions(); 56254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 56354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 564f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. The coordinates 565f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * are transformed with the supplied matrix. 566f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 567f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 568f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom, const mat4 transform); 569f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 570f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 571f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * Mark the layer as dirty at the specified coordinates. 572f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 573f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy void dirtyLayer(const float left, const float top, 574f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy const float right, const float bottom); 575f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 576f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 5775cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a colored rectangle with the specified color. The specified coordinates 578735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * are transformed by the current snapshot's transform matrix unless specified 579735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * otherwise. 5805cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 5815cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 5825cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 5835cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 5845cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 58576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the color, blending mode, etc. 5863d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy * @param ignoreTransform True if the current transform should be ignored 5875cbbce535744b89df5ecea95de21ee3733298260Romain Guy */ 588026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void drawColorRect(float left, float top, float right, float bottom, 58976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool ignoreTransform = false); 5905cbbce535744b89df5ecea95de21ee3733298260Romain Guy 59154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 592735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * Draws a series of colored rectangles with the specified color. The specified 593735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * coordinates are transformed by the current snapshot's transform matrix unless 594735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * specified otherwise. 595735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * 596735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param rects A list of rectangles, 4 floats (left, top, right, bottom) 597735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * per rectangle 59876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the color, blending mode, etc. 599735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy * @param ignoreTransform True if the current transform should be ignored 6008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * @param dirty True if calling this method should dirty the current layer 6013bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy * @param clip True if the rects should be clipped, false otherwise 602735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy */ 60376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger status_t drawColorRects(const float* rects, int count, const SkPaint* paint, 60476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger bool ignoreTransform = false, bool dirty = true, bool clip = true); 605735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy 606735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy /** 60754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the shape represented by the specified path texture. 60854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * This method invokes drawPathTexture() but takes into account 60954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * the extra left/top offset and the texture offset to correctly 61054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * position the final shape. 61154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 61254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The left coordinate of the shape to render 61354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The top coordinate of the shape to render 61454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture reprsenting the shape 61554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the shape with 61654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 617d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik status_t drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint); 61854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 61954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 62054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey 62154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * different compositing rules. 62254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 62354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to draw with 62454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param left The x coordinate of the bitmap 62554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param top The y coordinate of the bitmap 62654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to render with 62754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 628d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawAlphaBitmap(Texture* texture, float left, float top, const SkPaint* paint); 629a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy 63054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 63165cd612face362d054a85d0f7e5881c59cd523beChris Craik * Renders a strip of polygons with the specified paint, used for tessellated geometry. 63265cd612face362d054a85d0f7e5881c59cd523beChris Craik * 63365cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param vertexBuffer The VertexBuffer to be drawn 63465cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param paint The paint to render with 63565cd612face362d054a85d0f7e5881c59cd523beChris Craik * @param useOffset Offset the vertexBuffer (used in drawing non-AA lines) 63665cd612face362d054a85d0f7e5881c59cd523beChris Craik */ 63763d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghui status_t drawVertexBuffer(VertexBufferMode mode, const VertexBuffer& vertexBuffer, 63863d41abb40b3ce40d8b9bccb1cf186e8158a3687ztenghui const SkPaint* paint, bool useOffset = false); 63965cd612face362d054a85d0f7e5881c59cd523beChris Craik 64065cd612face362d054a85d0f7e5881c59cd523beChris Craik /** 641710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * Renders the convex hull defined by the specified path as a strip of polygons. 64254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 643710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik * @param path The hull of the path to draw 644cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik * @param paint The paint to render with 64554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 646d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik status_t drawConvexPath(const SkPath& path, const SkPaint* paint); 647858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase 6485cbbce535744b89df5ecea95de21ee3733298260Romain Guy /** 6495cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Draws a textured rectangle with the specified texture. The specified coordinates 6505cbbce535744b89df5ecea95de21ee3733298260Romain Guy * are transformed by the current snapshot's transform matrix. 6515cbbce535744b89df5ecea95de21ee3733298260Romain Guy * 6525cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param left The left coordinate of the rectangle 6535cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param top The top coordinate of the rectangle 6545cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param right The right coordinate of the rectangle 6555cbbce535744b89df5ecea95de21ee3733298260Romain Guy * @param bottom The bottom coordinate of the rectangle 65682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture to use 65782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param paint The paint containing the alpha, blending mode, etc. 65882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 659a979474f15b454c8e2963f239a3770e200bb227cRomain Guy void drawTextureRect(float left, float top, float right, float bottom, 660d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik Texture* texture, const SkPaint* paint); 66182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 66282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy /** 66303750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * Draws a textured mesh with the specified texture. If the indices are omitted, 66403750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * the mesh is drawn as a simple quad. The mesh pointers become offsets when a 66503750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * VBO is bound. 66682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * 66782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param left The left coordinate of the rectangle 66882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param top The top coordinate of the rectangle 66982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param right The right coordinate of the rectangle 67082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param bottom The bottom coordinate of the rectangle 67182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texture The texture name to map onto the rectangle 67276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger * @param paint The paint containing the alpha, blending mode, colorFilter, etc. 67382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param blend True if the texture contains an alpha channel 67482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param vertices The vertices that define the mesh 67582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param texCoords The texture coordinates of each vertex 67682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * @param elementsCount The number of elements in the mesh, required by indices 677f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param swapSrcDst Whether or not the src and dst blending operations should be swapped 678f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy * @param ignoreTransform True if the current transform should be ignored 67903750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy * @param vbo The VBO used to draw the mesh 6804063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param modelViewMode Defines whether the model view matrix should be scaled 6815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * @param dirty True if calling this method should dirty the current layer 682f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 683f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, 68476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool blend, 6856820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 6865b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 6874063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true); 688f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 6893b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture, 69076d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const SkPaint* paint, bool blend, 6913b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 6923b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0, 6934063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true); 6943b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 695886b275e529e44a59c54b933453d9bc902973178Romain Guy void drawAlpha8TextureMesh(float left, float top, float right, float bottom, 69676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger GLuint texture, const SkPaint* paint, 697886b275e529e44a59c54b933453d9bc902973178Romain Guy GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, 6984063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik bool ignoreTransform, ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, 6994063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik bool dirty = true); 700886b275e529e44a59c54b933453d9bc902973178Romain Guy 701f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy /** 702448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * Draws the specified list of vertices as quads using indexed GL_TRIANGLES. 703448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * If the number of vertices to draw exceeds the number of indices we have 704448455fe783b0a711340322dca272b8cc0ebe473Romain Guy * pre-allocated, this method will generate several glDrawElements() calls. 705448455fe783b0a711340322dca272b8cc0ebe473Romain Guy */ 7064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik void issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount); 707448455fe783b0a711340322dca272b8cc0ebe473Romain Guy 708448455fe783b0a711340322dca272b8cc0ebe473Romain Guy /** 7090a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * Draws text underline and strike-through if needed. 7100a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * 7110a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param text The text to decor 7120a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param bytesCount The number of bytes in the text 71341541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik * @param totalAdvance The total advance in pixels, defines underline/strikethrough length 7140a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param x The x coordinate where the text will be drawn 7150a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param y The y coordinate where the text will be drawn 7160a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy * @param paint The paint to draw the text with 7170a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy */ 718d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint); 7191e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy 720416a847633680d94efb926837efdc18726d54918Raph Levien /** 721416a847633680d94efb926837efdc18726d54918Raph Levien * Draws shadow layer on text (with optional positions). 722416a847633680d94efb926837efdc18726d54918Raph Levien * 723416a847633680d94efb926837efdc18726d54918Raph Levien * @param paint The paint to draw the shadow with 724416a847633680d94efb926837efdc18726d54918Raph Levien * @param text The text to draw 725416a847633680d94efb926837efdc18726d54918Raph Levien * @param bytesCount The number of bytes in the text 726416a847633680d94efb926837efdc18726d54918Raph Levien * @param count The number of glyphs in the text 727416a847633680d94efb926837efdc18726d54918Raph Levien * @param positions The x, y positions of individual glyphs (or NULL) 728416a847633680d94efb926837efdc18726d54918Raph Levien * @param fontRenderer The font renderer object 729416a847633680d94efb926837efdc18726d54918Raph Levien * @param alpha The alpha value for drawing the shadow 730416a847633680d94efb926837efdc18726d54918Raph Levien * @param x The x coordinate where the shadow will be drawn 731416a847633680d94efb926837efdc18726d54918Raph Levien * @param y The y coordinate where the shadow will be drawn 732416a847633680d94efb926837efdc18726d54918Raph Levien */ 733d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count, 73476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger const float* positions, FontRenderer& fontRenderer, int alpha, 735416a847633680d94efb926837efdc18726d54918Raph Levien float x, float y); 736416a847633680d94efb926837efdc18726d54918Raph Levien 73754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy /** 73854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * Draws a path texture. Path textures are alpha8 bitmaps that need special 73954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * compositing to apply colors/filters/etc. 74054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * 74154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param texture The texture to render 74254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param x The x coordinate where the texture will be drawn 74354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param y The y coordinate where the texture will be drawn 74454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy * @param paint The paint to draw the texture with 74554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy */ 746d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint); 74701d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy 7481e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy /** 749ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Resets the texture coordinates stored in mMeshVertices. Setting the values 750026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * back to default is achieved by calling: 751026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 7528ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 753026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * 754026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u1 The left coordinate of the texture 755026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v1 The bottom coordinate of the texture 756026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param u2 The right coordinate of the texture 757026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * @param v2 The top coordinate of the texture 758026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */ 759026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 760026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 7618ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy /** 762768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy * Returns true if the specified paint will draw invisible text. 763768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy */ 764768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy bool canSkipText(const SkPaint* paint) const; 765768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy 766768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy /** 767746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Binds the specified texture. The texture unit must have been selected 768746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * prior to calling this method. 769a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy */ 770746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void bindTexture(GLuint texture) { 7718aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy mCaches.bindTexture(texture); 772746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 773746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 774746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 775aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Binds the specified EGLImage texture. The texture unit must have been selected 776aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * prior to calling this method. 777aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 778aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy inline void bindExternalTexture(GLuint texture) { 7798aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture); 780aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy } 781aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 782aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 78382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * Enable or disable blending as necessary. This function sets the appropriate 78482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy * blend function based on the specified xfermode. 78582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy */ 786f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description, 787f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy bool swapSrcDst = false); 788a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy 789f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy /** 790d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * Use the specified program with the current GL context. If the program is already 791d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * in use, it will not be bound again. If it is not in use, the current program is 792d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * marked unused and the specified program becomes used and becomes the new 793d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * current program. 7946926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy * 795d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @param program The program to use 796d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * 797d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy * @return true If the specified program was already in use, false otherwise. 798260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy */ 799889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy inline bool useProgram(Program* program); 800260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy 801746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 802746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Invoked before any drawing operation. This sets required state. 803746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 80454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy void setupDraw(bool clear = true); 80517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy 80670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy /** 80770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy * Various methods to setup OpenGL rendering. 80870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy */ 80970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawWithTexture(bool isAlpha8 = false); 810ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy void setupDrawWithTextureAndColor(bool isAlpha8 = false); 811aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawWithExternalTexture(); 81215bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy void setupDrawNoTexture(); 813710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik void setupDrawAA(); 8148d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy void setupDrawColor(int color, int alpha); 81570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColor(float r, float g, float b, float a); 81686568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawAlpha8Color(int color, int alpha); 8174121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGamma(const SkPaint* paint); 81870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawShader(); 81976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawColorFilter(const SkColorFilter* filter); 82076d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawBlending(const Layer* layer, bool swapSrcDst = false); 82176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawBlending(const SkPaint* paint, bool blend = true, bool swapSrcDst = false); 82270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawProgram(); 82370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawDirtyRegionsDisabled(); 8244063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik 8254063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 8264063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Setup the current program matrices based upon the nature of the geometry. 8274063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8284063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param mode If kModelViewMode_Translate, the geometry must be translated by the left and top 8294063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * parameters. If kModelViewMode_TranslateAndScale, the geometry that exists in the (0,0, 1,1) 8304063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * space must be scaled up and translated to fill the quad provided in (l,t,r,b). These 8314063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * transformations are stored in the modelView matrix and uploaded to the shader. 8324063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8334063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate 834564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik * geometry pixel positioning. See Vertex::GeometryFudgeFactor(). 8354063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 8364063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space, 8374063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil, 8384063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * or when simple translation has been extracted) 8394063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 8404063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik void setupDrawModelView(ModelViewMode mode, bool offset, 8414063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik float left, float top, float right, float bottom, bool ignoreTransform = false); 84270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawColorUniforms(); 84386568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy void setupDrawPureColorUniforms(); 84470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawShaderUniforms(bool ignoreTransform = false); 84576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void setupDrawColorFilterUniforms(const SkColorFilter* paint); 84670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawSimpleMesh(); 84770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy void setupDrawTexture(GLuint texture); 848aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy void setupDrawExternalTexture(GLuint texture); 8498f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransform(); 8508f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy void setupDrawTextureTransformUniforms(mat4& transform); 8514121063313ac0d6f69f6253cac821d0c1c122086Romain Guy void setupDrawTextGammaUniforms(); 852564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0); 853564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors); 854564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0); 855448455fe783b0a711340322dca272b8cc0ebe473Romain Guy void setupDrawIndexedVertices(GLvoid* vertices); 856f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy void accountForClear(SkXfermode::Mode mode); 857746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 85811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy bool updateLayer(Layer* layer, bool inFrame); 85911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy void updateLayers(); 86096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy void flushLayers(); 86111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy 862e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#if DEBUG_LAYERS_AS_REGIONS 86317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy /** 86417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * Renders the specified region as a series of rectangles. This method 86517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy * is used for debugging only. 86617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy */ 867e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik void drawRegionRectsDebug(const Region& region); 868e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#endif 8693a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy 8708ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 8718ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Renders the specified region as a series of rectangles. The region 8728ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * must be in screen-space coordinates. 8738ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 87476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false); 8758ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 8768ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy /** 8778ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS 8788ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy * is turned on. 8798ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy */ 8808ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy void debugClip(); 8818ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy 8827c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void debugOverdraw(bool enable, bool clear); 8837c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy void renderOverdraw(); 88478dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy void countOverdraw(); 8857c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy 886746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy /** 887746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy * Should be invoked every time the glScissor is modified. 888746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy */ 889746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy inline void dirtyClip() { 890746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy mDirtyClip = true; 891746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy } 892746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy 8933b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy inline const UvMapper& getMapper(const Texture* texture) { 8943b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper; 8953b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy } 8963b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 8973b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy /** 8983b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * Returns a texture object for the specified bitmap. The texture can 8993b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * come from the texture cache or an atlas. If this method returns 9003b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy * NULL, the texture could not be found and/or allocated. 9013b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy */ 902d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik Texture* getTexture(const SkBitmap* bitmap); 9033b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 904f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik // Matrix used for view/projection in shaders 905f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik mat4 mViewProjMatrix; 906bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 9074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik /** 9084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Model-view matrix used to position/size objects 9094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9104063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Stores operation-local modifications to the draw matrix that aren't incorporated into the 9114063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * currentTransform(). 9124063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9134063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * If generated with kModelViewMode_Translate, the mModelView will reflect an x/y offset, 9144063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale, 9154063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * mModelView will reflect a translation and scale, e.g. the translation and scale required to 9164063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height of a 9174063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * bitmap. 9184063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * 9194063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Used as input to SkiaShader transformation. 9204063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */ 921c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy mat4 mModelView; 922c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy 9232b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // State used to define the clipping region 9245f803623559aab395a29d575c37c4e39c23a4b4eChris Craik Rect mTilingClip; 92596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy // Is the target render surface opaque 92696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy bool mOpaque; 92796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy // Is a frame currently being rendered 92896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy bool mFrameStarted; 9299d5316e3f56d138504565ff311145ac01621dff4Romain Guy 930026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy // Used to draw textured quads 931ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy TextureVertex mMeshVertices[4]; 932ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 9333b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy // Default UV mapper 9343b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy const UvMapper mUvMapper; 9353b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy 936c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik // shader, filters, and shadow 937c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik DrawModifiers mDrawModifiers; 9385ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy SkPaint mFilteredPaint; 9395ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy 94082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy // Various caches 941fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy Caches& mCaches; 9423bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy Extensions& mExtensions; 9438694230ff25fa0a60e480d424843e56b718f0516Romain Guy 9448f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy // List of rectangles to clear after saveLayer() is invoked 94554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy Vector<Rect*> mLayers; 9468f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy // List of functors to invoke after a frame is drawn 947ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy SortedVector<Functor*> mFunctors; 94811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy // List of layers to update at the beginning of a frame 94911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy Vector<Layer*> mLayerUpdates; 95054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy 95170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // The following fields are used to setup drawing 95270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Used to describe the shaders to generate 95370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy ProgramDescription mDescription; 95470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Color description 95570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mColorSet; 95670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy float mColorA, mColorR, mColorG, mColorB; 95770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Indicates that the shader should get a color 95870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mSetShaderColor; 95970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Current texture unit 96070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy GLuint mTextureUnit; 96170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy // Track dirty regions, true by default 96270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy bool mTrackDirtyRegions; 9632b7028eabac80cec170572bc0e945a1d4224e595Romain Guy // Indicate whether we are drawing an opaque frame 9642b7028eabac80cec170572bc0e945a1d4224e595Romain Guy bool mOpaqueFrame; 96570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy 96687e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in 96787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy // Properties.h 96887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy bool mScissorOptimizationDisabled; 96987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy 97054c1a64d5441a964890b44280e4457e11f4f924aRomain Guy // No-ops start/endTiling when set 97154c1a64d5441a964890b44280e4457e11f4f924aRomain Guy bool mSuppressTiling; 97254c1a64d5441a964890b44280e4457e11f4f924aRomain Guy 97378dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy // If true, this renderer will setup drawing to emulate 97478dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy // an increment stencil buffer in the color buffer 97578dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy bool mCountOverdraw; 97678dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy float mOverdraw; 97778dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy 978b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy friend class DisplayListRenderer; 97996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy friend class Layer; 980257ae3502cfad43df681b1783528d645bdabc63fRomain Guy friend class TextSetupFunctor; 98103c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy friend class DrawBitmapOp; 98203c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy friend class DrawPatchOp; 983b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy 984bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer 985e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 9869d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer 987e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android 988e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 9895b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H 990