Caches.cpp revision 627c6fd91377ead85f74a365438e25610ef1e2ee
1dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase/*
2dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * Copyright (C) 2010 The Android Open Source Project
3dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase *
4dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * Licensed under the Apache License, Version 2.0 (the "License");
5dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * you may not use this file except in compliance with the License.
6dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * You may obtain a copy of the License at
7dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase *
8dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase *      http://www.apache.org/licenses/LICENSE-2.0
9dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase *
10dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * Unless required by applicable law or agreed to in writing, software
11dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * distributed under the License is distributed on an "AS IS" BASIS,
12dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * See the License for the specific language governing permissions and
14dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase * limitations under the License.
15dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase */
16dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
17dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase#define LOG_TAG "OpenGLRenderer"
18dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
19c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include <utils/Log.h>
209c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase#include <utils/String8.h>
21c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy
22dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase#include "Caches.h"
23bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy#include "DisplayListRenderer.h"
24e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy#include "Properties.h"
2509b7c91de73b59aa3f679b3ae3ba299f82ec9f8aRomain Guy#include "LayerRenderer.h"
26dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
27dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haasenamespace android {
28dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
29dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase#ifdef USE_OPENGL_RENDERER
30dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haaseusing namespace uirenderer;
31dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet HaaseANDROID_SINGLETON_STATIC_INSTANCE(Caches);
32dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase#endif
33dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
34dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haasenamespace uirenderer {
35dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
36dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase///////////////////////////////////////////////////////////////////////////////
37bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy// Macros
38bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy///////////////////////////////////////////////////////////////////////////////
39bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy
40bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy#if DEBUG_CACHE_FLUSH
415baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
42bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy#else
43bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy    #define FLUSH_LOGD(...)
44bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy#endif
45bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy
46bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy///////////////////////////////////////////////////////////////////////////////
47dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase// Constructors/destructor
48dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase///////////////////////////////////////////////////////////////////////////////
49dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
508aa195d7081b889f3a7b1f426cbd8556377aae5eRomain GuyCaches::Caches(): Singleton<Caches>(),
518aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mExtensions(Extensions::getInstance()), mInitialized(false) {
528ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    init();
53b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy    initFont();
54dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    initConstraints();
554ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy    initProperties();
56f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy    initStaticProperties();
570f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    initExtensions();
58e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy
59e190aa69756aecfaffabdd4c6d32cb6b3220d842Romain Guy    mDebugLevel = readDebugLevel();
605baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    ALOGD("Enabling debug mode %d", mDebugLevel);
61dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase}
62dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
633b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guybool Caches::init() {
643b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    if (mInitialized) return false;
658ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
668ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    glGenBuffers(1, &meshBuffer);
678ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    glBindBuffer(GL_ARRAY_BUFFER, meshBuffer);
688ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);
698ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
708ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    mCurrentBuffer = meshBuffer;
7115bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    mCurrentIndicesBuffer = 0;
72f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    mCurrentPositionPointer = this;
73cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik    mCurrentPositionStride = 0;
74f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    mCurrentTexCoordsPointer = this;
75cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    mCurrentPixelBuffer = 0;
76f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy
7715bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    mTexCoordsArrayEnabled = false;
7815bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy
79b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy    glDisable(GL_SCISSOR_TEST);
80586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    scissorEnabled = false;
818f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy    mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
828f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy
83a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy    glActiveTexture(gTextureUnits[0]);
84a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy    mTextureUnit = 0;
85a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy
868ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    mRegionMesh = NULL;
873b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    mMeshIndices = 0;
888ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
898ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    blend = false;
908ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    lastSrcMode = GL_ZERO;
918ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    lastDstMode = GL_ZERO;
928ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    currentProgram = NULL;
938ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
9454c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    mFunctorsCount = 0;
9554c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
96c2a972131f1870042eb63847d4b24fbe718d8e3fRomain Guy    debugLayersUpdates = false;
97c2a972131f1870042eb63847d4b24fbe718d8e3fRomain Guy    debugOverdraw = false;
983ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy    debugStencilClip = kStencilHide;
99c2a972131f1870042eb63847d4b24fbe718d8e3fRomain Guy
1003b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    patchCache.init(*this);
1013b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
1028ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    mInitialized = true;
1033b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
1048aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    resetBoundTextures();
1058aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy
1063b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    return true;
1078ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy}
1088ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
109b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guyvoid Caches::initFont() {
110b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy    fontRenderer = GammaFontRenderer::createRenderer();
111b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy}
112b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy
113dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guyvoid Caches::initExtensions() {
1143bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    if (mExtensions.hasDebugMarker()) {
115dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        eventMark = glInsertEventMarkerEXT;
1160f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
117ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        startMark = glPushGroupMarkerEXT;
118ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        endMark = glPopGroupMarkerEXT;
119dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    } else {
120dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        eventMark = eventMarkNull;
121dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        startMark = startMarkNull;
122dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        endMark = endMarkNull;
123dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    }
124dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy
1250f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    if (mExtensions.hasDebugLabel() && (drawDeferDisabled || drawReorderDisabled)) {
126dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        setLabel = glLabelObjectEXT;
127dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        getLabel = glGetObjectLabelEXT;
128dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    } else {
129dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        setLabel = setLabelNull;
130dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        getLabel = getLabelNull;
131dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    }
132dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy}
133dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy
134dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guyvoid Caches::initConstraints() {
135dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    GLint maxTextureUnits;
136dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
137dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
138dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy        ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
139dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    }
140dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy
141dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
142dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy}
143dfa1046ecab165eb0daf5caa8475e993350f4a2bRomain Guy
144f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guyvoid Caches::initStaticProperties() {
145f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy    gpuPixelBuffersEnabled = false;
146f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy
147f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy    // OpenGL ES 3.0+ specific features
1487f4307668b10467ee39d41c7ea29cf1ff238a835Romain Guy    if (mExtensions.hasPixelBufferObjects()) {
149f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy        char property[PROPERTY_VALUE_MAX];
150f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy        if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) {
151f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy            gpuPixelBuffersEnabled = !strcmp(property, "true");
152f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy        }
153f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy    }
154f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy}
155f9f0016b1ff816eb2c7561eed482c056189005f8Romain Guy
1565bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guybool Caches::initProperties() {
1575bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guy    bool prevDebugLayersUpdates = debugLayersUpdates;
1585bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guy    bool prevDebugOverdraw = debugOverdraw;
1593ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy    StencilClipDebug prevDebugStencilClip = debugStencilClip;
1605bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guy
1614ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy    char property[PROPERTY_VALUE_MAX];
1624ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy    if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, NULL) > 0) {
1634ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy        INIT_LOGD("  Layers updates debug enabled: %s", property);
1644ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy        debugLayersUpdates = !strcmp(property, "true");
1654ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy    } else {
1664ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy        debugLayersUpdates = false;
1674ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy    }
1687c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
169627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy    debugOverdraw = false;
1707c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    if (property_get(PROPERTY_DEBUG_OVERDRAW, property, NULL) > 0) {
1717c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy        INIT_LOGD("  Overdraw debug enabled: %s", property);
172627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy        if (!strcmp(property, "show")) {
173627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy            debugOverdraw = true;
174627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy            mOverdrawDebugColorSet = kColorSet_Default;
175627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy        } else if (!strcmp(property, "show_deuteranomaly")) {
176627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy            debugOverdraw = true;
177627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy            mOverdrawDebugColorSet = kColorSet_Deuteranomaly;
178627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy        }
1797c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    }
1805bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guy
1813ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy    // See Properties.h for valid values
1823ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy    if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, NULL) > 0) {
1833ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy        INIT_LOGD("  Stencil clip debug enabled: %s", property);
1843ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy        if (!strcmp(property, "hide")) {
1853ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy            debugStencilClip = kStencilHide;
1863ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy        } else if (!strcmp(property, "highlight")) {
1873ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy            debugStencilClip = kStencilShowHighlight;
1883ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy        } else if (!strcmp(property, "region")) {
1893ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy            debugStencilClip = kStencilShowRegion;
1903ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy        }
1913ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy    } else {
1923ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy        debugStencilClip = kStencilHide;
1933ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy    }
1943ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy
1950f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    if (property_get(PROPERTY_DISABLE_DRAW_DEFER, property, "false")) {
1960f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        drawDeferDisabled = !strcasecmp(property, "true");
1970f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        INIT_LOGD("  Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
1980f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    } else {
1990f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        INIT_LOGD("  Draw defer enabled");
2000f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
2010f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
2020f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    if (property_get(PROPERTY_DISABLE_DRAW_REORDER, property, "false")) {
2030f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        drawReorderDisabled = !strcasecmp(property, "true");
2040f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        INIT_LOGD("  Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
2050f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    } else {
2060f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        INIT_LOGD("  Draw reorder enabled");
2070f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
2080f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
2095bb3c730f5ebd2a0db1b02a8981c6fdbea6c1a2eRomain Guy    return (prevDebugLayersUpdates != debugLayersUpdates) ||
2103ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy            (prevDebugOverdraw != debugOverdraw) ||
2113ff0bfdd144bba3b023eda8c49b25fb0d0de8653Romain Guy            (prevDebugStencilClip != debugStencilClip);
2124ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy}
2134ff0cf4b83605bff630c4e6f1fabe4f72a3f93a1Romain Guy
2148ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guyvoid Caches::terminate() {
2158ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    if (!mInitialized) return;
2168ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
2178ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    glDeleteBuffers(1, &meshBuffer);
2188ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    mCurrentBuffer = 0;
2198ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
2203b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    glDeleteBuffers(1, &mMeshIndices);
2215b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    delete[] mRegionMesh;
2223b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    mMeshIndices = 0;
2238ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    mRegionMesh = NULL;
2248ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
2258ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    fboCache.clear();
2268ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
2278ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    programCache.clear();
2288ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    currentProgram = NULL;
2298ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy
2303b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    assetAtlas.terminate();
2313b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
2323b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    patchCache.clear();
2333b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
23446bfc4811094e5b1e3196246e457d4c6b58332ecRomain Guy    clearGarbage();
23546bfc4811094e5b1e3196246e457d4c6b58332ecRomain Guy
2368ff6b9ebeeb24a6161ec6098e6bfdf8790ee5695Romain Guy    mInitialized = false;
2375b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy}
2385b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2395b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy///////////////////////////////////////////////////////////////////////////////
240c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy// Debug
241c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy///////////////////////////////////////////////////////////////////////////////
242c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy
243627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guyuint32_t Caches::getOverdrawColor(uint32_t amount) const {
244627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy    static uint32_t sOverdrawColors[2][4] = {
245627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy            { 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000 },
246627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy            { 0x2f0000ff, 0x4fffff00, 0x5fff8ad8, 0x7fff0000 }
247627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy    };
248627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy    if (amount < 1) amount = 1;
249627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy    if (amount > 4) amount = 4;
250627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy    return sOverdrawColors[mOverdrawDebugColorSet][amount - 1];
251627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy}
252627c6fd91377ead85f74a365438e25610ef1e2eeRomain Guy
253c15008e72ec00ca20a271c3006dac649fd07533bRomain Guyvoid Caches::dumpMemoryUsage() {
2549c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    String8 stringLog;
2559c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    dumpMemoryUsage(stringLog);
2565baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    ALOGD("%s", stringLog.string());
2579c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase}
2589c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase
2599c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haasevoid Caches::dumpMemoryUsage(String8 &log) {
2609c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("Current memory usage / total memory usage (bytes):\n");
2619c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  TextureCache         %8d / %8d\n",
2629c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase            textureCache.getSize(), textureCache.getMaxSize());
2639c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  LayerCache           %8d / %8d\n",
2649c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase            layerCache.getSize(), layerCache.getMaxSize());
2658d4aeb7111afac0c3c7e56d4ad5d92f9cfce2ffdRomain Guy    log.appendFormat("  RenderBufferCache    %8d / %8d\n",
2668d4aeb7111afac0c3c7e56d4ad5d92f9cfce2ffdRomain Guy            renderBufferCache.getSize(), renderBufferCache.getMaxSize());
2679c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  GradientCache        %8d / %8d\n",
2689c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase            gradientCache.getSize(), gradientCache.getMaxSize());
2699c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  PathCache            %8d / %8d\n",
2709c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase            pathCache.getSize(), pathCache.getMaxSize());
2719c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  TextDropShadowCache  %8d / %8d\n", dropShadowCache.getSize(),
272c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy            dropShadowCache.getMaxSize());
2733b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    log.appendFormat("  PatchCache           %8d / %8d\n",
2743b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            patchCache.getSize(), patchCache.getMaxSize());
275b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy    for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
2761e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        const uint32_t sizeA8 = fontRenderer->getFontRendererSize(i, GL_ALPHA);
2771e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        const uint32_t sizeRGBA = fontRenderer->getFontRendererSize(i, GL_RGBA);
2781e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        log.appendFormat("  FontRenderer %d A8    %8d / %8d\n", i, sizeA8, sizeA8);
2791e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        log.appendFormat("  FontRenderer %d RGBA  %8d / %8d\n", i, sizeRGBA, sizeRGBA);
2801e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        log.appendFormat("  FontRenderer %d total %8d / %8d\n", i, sizeA8 + sizeRGBA,
2811e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease                sizeA8 + sizeRGBA);
282c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    }
283d2ba50ab861ec0950bda18dd0f463b687e66249fRomain Guy    log.appendFormat("Other:\n");
2849c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  FboCache             %8d / %8d\n",
2859c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase            fboCache.getSize(), fboCache.getMaxSize());
286c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy
287c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    uint32_t total = 0;
288c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    total += textureCache.getSize();
289c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    total += layerCache.getSize();
2908d4aeb7111afac0c3c7e56d4ad5d92f9cfce2ffdRomain Guy    total += renderBufferCache.getSize();
291c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    total += gradientCache.getSize();
292c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    total += pathCache.getSize();
293c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    total += dropShadowCache.getSize();
2943b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    total += patchCache.getSize();
295b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy    for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
2961e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        total += fontRenderer->getFontRendererSize(i, GL_ALPHA);
2971e546815bbb736c50679a8aefc25f48561026fc5Victoria Lease        total += fontRenderer->getFontRendererSize(i, GL_RGBA);
298c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy    }
299c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy
3009c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("Total memory usage:\n");
3019c1e23baf5bfbebd1aebbd6d9a18c225325567ceChet Haase    log.appendFormat("  %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
302c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy}
303c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy
304c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy///////////////////////////////////////////////////////////////////////////////
305fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy// Memory management
306fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy///////////////////////////////////////////////////////////////////////////////
307fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy
308fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guyvoid Caches::clearGarbage() {
309fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy    textureCache.clearGarbage();
310fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy    pathCache.clearGarbage();
311e3b0a0117a2ab4118f868a731b238fe8f2430276Romain Guy    patchCache.clearGarbage();
31257066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy
31317ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    Vector<DisplayList*> displayLists;
31417ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    Vector<Layer*> layers;
31517ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian
31617ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    { // scope for the lock
31717ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        Mutex::Autolock _l(mGarbageLock);
31817ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        displayLists = mDisplayListGarbage;
31917ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        layers = mLayerGarbage;
32017ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        mDisplayListGarbage.clear();
32117ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        mLayerGarbage.clear();
32217ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    }
32357066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy
32417ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    size_t count = displayLists.size();
32557066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy    for (size_t i = 0; i < count; i++) {
32617ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        DisplayList* displayList = displayLists.itemAt(i);
32717ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        delete displayList;
32857066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy    }
329bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy
33017ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    count = layers.size();
331bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy    for (size_t i = 0; i < count; i++) {
33217ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        Layer* layer = layers.itemAt(i);
33317ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian        delete layer;
334bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy    }
33517ef62cc1f9d092669af0fed465a9a77e0dc1a4fMathias Agopian    layers.clear();
33657066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy}
33757066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy
338ada830f639591b99c3e40de22b07296c7932a33fRomain Guyvoid Caches::deleteLayerDeferred(Layer* layer) {
33957066eb64c9a190d1afc87bb060bbb2d31e5b86cRomain Guy    Mutex::Autolock _l(mGarbageLock);
340ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    mLayerGarbage.push(layer);
341fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy}
342fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy
343bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guyvoid Caches::deleteDisplayListDeferred(DisplayList* displayList) {
344bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy    Mutex::Autolock _l(mGarbageLock);
345bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy    mDisplayListGarbage.push(displayList);
346bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy}
347bb0acdf9e1d862a7cf0e2533321fc1105c29b5e3Romain Guy
348bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guyvoid Caches::flush(FlushMode mode) {
349bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy    FLUSH_LOGD("Flushing caches (mode %d)", mode);
350bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy
351b0a41ed3dcc34a2b4026f6cc8336796f3523aa21Romain Guy    // We must stop tasks before clearing caches
352b0a41ed3dcc34a2b4026f6cc8336796f3523aa21Romain Guy    if (mode > kFlushMode_Layers) {
353b0a41ed3dcc34a2b4026f6cc8336796f3523aa21Romain Guy        tasks.stop();
354b0a41ed3dcc34a2b4026f6cc8336796f3523aa21Romain Guy    }
355b0a41ed3dcc34a2b4026f6cc8336796f3523aa21Romain Guy
356bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy    switch (mode) {
357bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy        case kFlushMode_Full:
358bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            textureCache.clear();
359bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            patchCache.clear();
360bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            dropShadowCache.clear();
361bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            gradientCache.clear();
362b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy            fontRenderer->clear();
363b746371de7f21ae36a14953d9b253df06838efb1Romain Guy            fboCache.clear();
364211efea7376371ee755edd2ad03e83ef6eea464eRomain Guy            dither.clear();
365bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            // fall through
366bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy        case kFlushMode_Moderate:
367b1d0a4ed21168fefcb82232c8f22cb95d60acb85Romain Guy            fontRenderer->flush();
368eca0ca2424afc1e98912405906edfc32f7733e16Romain Guy            textureCache.flush();
369bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            pathCache.clear();
3706d7475d666baefaa3ba9f0dcee25238739454241Romain Guy            // fall through
3716d7475d666baefaa3ba9f0dcee25238739454241Romain Guy        case kFlushMode_Layers:
3726d7475d666baefaa3ba9f0dcee25238739454241Romain Guy            layerCache.clear();
3738d4aeb7111afac0c3c7e56d4ad5d92f9cfce2ffdRomain Guy            renderBufferCache.clear();
374bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy            break;
375bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy    }
3766a2d17f71342f981c9df1dc5beff33e30eb3ae2bChet Haase
3776a2d17f71342f981c9df1dc5beff33e30eb3ae2bChet Haase    clearGarbage();
378bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy}
379bdf7609867a3f886455c51dba91623a86cceb6e2Romain Guy
380fe48f65922d4a3cc4aefe058cee5acec51504a20Romain Guy///////////////////////////////////////////////////////////////////////////////
3815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy// VBO
3825b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy///////////////////////////////////////////////////////////////////////////////
3835b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
384f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guybool Caches::bindMeshBuffer() {
385f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    return bindMeshBuffer(meshBuffer);
386dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase}
387dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
388f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guybool Caches::bindMeshBuffer(const GLuint buffer) {
3899bca4793a33d2714b306d69ceb870925a588fe71Romain Guy    if (mCurrentBuffer != buffer) {
390dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase        glBindBuffer(GL_ARRAY_BUFFER, buffer);
3919bca4793a33d2714b306d69ceb870925a588fe71Romain Guy        mCurrentBuffer = buffer;
392f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy        return true;
393dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase    }
394f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    return false;
395dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase}
396dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
397f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guybool Caches::unbindMeshBuffer() {
3989bca4793a33d2714b306d69ceb870925a588fe71Romain Guy    if (mCurrentBuffer) {
399dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase        glBindBuffer(GL_ARRAY_BUFFER, 0);
4009bca4793a33d2714b306d69ceb870925a588fe71Romain Guy        mCurrentBuffer = 0;
401f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy        return true;
402f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    }
403f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    return false;
404f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy}
405f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy
40615bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guybool Caches::bindIndicesBuffer(const GLuint buffer) {
40715bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    if (mCurrentIndicesBuffer != buffer) {
40815bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
40915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        mCurrentIndicesBuffer = buffer;
41015bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        return true;
41115bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    }
41215bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    return false;
41315bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy}
41415bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy
4153b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guybool Caches::bindIndicesBuffer() {
4163b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    if (!mMeshIndices) {
41731e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy        uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6];
41831e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy        for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
4193b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            uint16_t quad = i * 4;
4203b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            int index = i * 6;
4213b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            regionIndices[index    ] = quad;       // top-left
4223b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            regionIndices[index + 1] = quad + 1;   // top-right
4233b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            regionIndices[index + 2] = quad + 2;   // bottom-left
4243b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            regionIndices[index + 3] = quad + 2;   // bottom-left
4253b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            regionIndices[index + 4] = quad + 1;   // top-right
4263b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            regionIndices[index + 5] = quad + 3;   // bottom-right
4273b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        }
4283b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
4293b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        glGenBuffers(1, &mMeshIndices);
4303b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        bool force = bindIndicesBuffer(mMeshIndices);
43131e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy        glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t),
4323b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy                regionIndices, GL_STATIC_DRAW);
4333b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
4343b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        delete[] regionIndices;
4353b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        return force;
4363b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    }
4373b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
4383b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    return bindIndicesBuffer(mMeshIndices);
4393b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy}
4403b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
44115bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guybool Caches::unbindIndicesBuffer() {
44215bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    if (mCurrentIndicesBuffer) {
44315bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
44415bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        mCurrentIndicesBuffer = 0;
44515bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        return true;
44615bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    }
44715bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    return false;
44815bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy}
44915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy
45085ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
451cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy// PBO
452cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy///////////////////////////////////////////////////////////////////////////////
453cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy
454cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guybool Caches::bindPixelBuffer(const GLuint buffer) {
455cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    if (mCurrentPixelBuffer != buffer) {
456cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
457cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy        mCurrentPixelBuffer = buffer;
458cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy        return true;
459cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    }
460cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    return false;
461cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy}
462cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy
463cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guybool Caches::unbindPixelBuffer() {
464cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    if (mCurrentPixelBuffer) {
465cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
466cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy        mCurrentPixelBuffer = 0;
467cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy        return true;
468cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    }
469cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy    return false;
470cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy}
471cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy
472cf51a4199835e9604aa4c8b3854306f8fbabbf33Romain Guy///////////////////////////////////////////////////////////////////////////////
47385ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy// Meshes and textures
47485ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
47585ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy
476cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craikvoid Caches::bindPositionVertexPointer(bool force, GLvoid* vertices, GLsizei stride) {
477cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik    if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) {
478cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik        GLuint slot = currentProgram->position;
479f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
480f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy        mCurrentPositionPointer = vertices;
481cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik        mCurrentPositionStride = stride;
482dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase    }
483dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase}
484dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase
485ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guyvoid Caches::bindTexCoordsVertexPointer(bool force, GLvoid* vertices, GLsizei stride) {
486ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) {
487cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik        GLuint slot = currentProgram->texCoords;
488ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
489f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy        mCurrentTexCoordsPointer = vertices;
490ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy        mCurrentTexCoordsStride = stride;
491f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    }
492f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy}
493f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy
494f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guyvoid Caches::resetVertexPointers() {
495f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    mCurrentPositionPointer = this;
496f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    mCurrentTexCoordsPointer = this;
497f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy}
498f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy
499f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guyvoid Caches::resetTexCoordsVertexPointer() {
500f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy    mCurrentTexCoordsPointer = this;
501f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy}
502f3a910b423db7ad79cf61518bdd9278c048ad0d8Romain Guy
50315bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guyvoid Caches::enableTexCoordsVertexArray() {
50415bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    if (!mTexCoordsArrayEnabled) {
50515bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        glEnableVertexAttribArray(Program::kBindingTexCoords);
506ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy        mCurrentTexCoordsPointer = this;
50715bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        mTexCoordsArrayEnabled = true;
50815bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    }
50915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy}
51015bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy
511ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guyvoid Caches::disableTexCoordsVertexArray() {
51215bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    if (mTexCoordsArrayEnabled) {
51315bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        glDisableVertexAttribArray(Program::kBindingTexCoords);
51415bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy        mTexCoordsArrayEnabled = false;
51515bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    }
51615bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy}
51715bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy
518a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guyvoid Caches::activeTexture(GLuint textureUnit) {
519a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy    if (mTextureUnit != textureUnit) {
520a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy        glActiveTexture(gTextureUnits[textureUnit]);
521a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy        mTextureUnit = textureUnit;
522a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy    }
523a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy}
524a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy
5259ab2d1847552aa4169b4325aae1b1368d6947a9fChris Craikvoid Caches::resetActiveTexture() {
5269ab2d1847552aa4169b4325aae1b1368d6947a9fChris Craik    mTextureUnit = -1;
5279ab2d1847552aa4169b4325aae1b1368d6947a9fChris Craik}
5289ab2d1847552aa4169b4325aae1b1368d6947a9fChris Craik
5298aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guyvoid Caches::bindTexture(GLuint texture) {
5308aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    if (mBoundTextures[mTextureUnit] != texture) {
5318aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        glBindTexture(GL_TEXTURE_2D, texture);
5328aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mBoundTextures[mTextureUnit] = texture;
5338aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    }
5348aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy}
5358aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy
5368aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guyvoid Caches::bindTexture(GLenum target, GLuint texture) {
5378aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    if (mBoundTextures[mTextureUnit] != texture) {
5388aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        glBindTexture(target, texture);
5398aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mBoundTextures[mTextureUnit] = texture;
5408aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    }
5418aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy}
5428aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy
543be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guyvoid Caches::deleteTexture(GLuint texture) {
544be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // When glDeleteTextures() is called on a currently bound texture,
545be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // OpenGL ES specifies that the texture is then considered unbound
546be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // Consider the following series of calls:
547be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    //
548be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // glGenTextures -> creates texture name 2
549be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // glBindTexture(2)
550be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // glDeleteTextures(2) -> 2 is now unbound
551be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // glGenTextures -> can return 2 again
552be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    //
553be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // If we don't call glBindTexture(2) after the second glGenTextures
554be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // call, any texture operation will be performed on the default
555be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    // texture (name=0)
556be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy
557be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    for (int i = 0; i < REQUIRED_TEXTURE_UNITS_COUNT; i++) {
558be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy        if (mBoundTextures[i] == texture) {
559be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy            mBoundTextures[i] = 0;
560be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy        }
561be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    }
562be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    glDeleteTextures(1, &texture);
563be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy}
564be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy
5658aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guyvoid Caches::resetBoundTextures() {
5668aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    memset(mBoundTextures, 0, REQUIRED_TEXTURE_UNITS_COUNT * sizeof(GLuint));
5678aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy}
5688aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy
56985ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
57085ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy// Scissor
57185ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
57285ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy
5738a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guybool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
574586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    if (scissorEnabled && (x != mScissorX || y != mScissorY ||
575586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy            width != mScissorWidth || height != mScissorHeight)) {
576586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy
577aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        if (x < 0) {
578aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase            width += x;
579aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase            x = 0;
580aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        }
581aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        if (y < 0) {
582aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase            height += y;
583aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase            y = 0;
584aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        }
585aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        if (width < 0) {
586aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase            width = 0;
587aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        }
588aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        if (height < 0) {
589aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase            height = 0;
590aa42c9af6ea2158a685ebf9b338e6d2355712268Chet Haase        }
5918f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        glScissor(x, y, width, height);
5928f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy
5938f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        mScissorX = x;
5948f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        mScissorY = y;
5958f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        mScissorWidth = width;
5968f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        mScissorHeight = height;
5978a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy
5988a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy        return true;
5998f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy    }
6008a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy    return false;
6018f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy}
6028f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy
6038a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guybool Caches::enableScissor() {
604586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    if (!scissorEnabled) {
605586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        glEnable(GL_SCISSOR_TEST);
606586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        scissorEnabled = true;
60750ae66a554126fadee2054e0d01a9e57150cedb5Romain Guy        resetScissor();
6088a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy        return true;
609586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    }
6108a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy    return false;
611586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy}
612586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy
6138a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guybool Caches::disableScissor() {
614586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    if (scissorEnabled) {
615586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        glDisable(GL_SCISSOR_TEST);
616586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        scissorEnabled = false;
6178a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy        return true;
618586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    }
6198a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy    return false;
620586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy}
621586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy
622586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guyvoid Caches::setScissorEnabled(bool enabled) {
623586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    if (scissorEnabled != enabled) {
624586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        if (enabled) glEnable(GL_SCISSOR_TEST);
625586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        else glDisable(GL_SCISSOR_TEST);
626586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy        scissorEnabled = enabled;
627586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy    }
628586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy}
629586cae3ac69c0c667fbf8a954edbd399f620a717Romain Guy
63082bc7a772747fcf8a6fe7097f70bf2981429ffe9Romain Guyvoid Caches::resetScissor() {
63182bc7a772747fcf8a6fe7097f70bf2981429ffe9Romain Guy    mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
63282bc7a772747fcf8a6fe7097f70bf2981429ffe9Romain Guy}
63382bc7a772747fcf8a6fe7097f70bf2981429ffe9Romain Guy
63485ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
63585ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy// Tiling
63685ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
63785ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy
638f735c8e5cb59d6e1d1aa152fed7a6480a08d1c2aRomain Guyvoid Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard) {
6393bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    if (mExtensions.hasTiledRendering() && !debugOverdraw) {
640f735c8e5cb59d6e1d1aa152fed7a6480a08d1c2aRomain Guy        glStartTilingQCOM(x, y, width, height, (discard ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
64185ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy    }
64285ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy}
64385ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy
64485ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guyvoid Caches::endTiling() {
6453bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    if (mExtensions.hasTiledRendering() && !debugOverdraw) {
6462b7028eabac80cec170572bc0e945a1d4224e595Romain Guy        glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
64785ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy    }
64885ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy}
64985ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy
65054c1a64d5441a964890b44280e4457e11f4f924aRomain Guybool Caches::hasRegisteredFunctors() {
65154c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    return mFunctorsCount > 0;
65254c1a64d5441a964890b44280e4457e11f4f924aRomain Guy}
65354c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
65454c1a64d5441a964890b44280e4457e11f4f924aRomain Guyvoid Caches::registerFunctors(uint32_t functorCount) {
65554c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    mFunctorsCount += functorCount;
65654c1a64d5441a964890b44280e4457e11f4f924aRomain Guy}
65754c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
65854c1a64d5441a964890b44280e4457e11f4f924aRomain Guyvoid Caches::unregisterFunctors(uint32_t functorCount) {
65954c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    if (functorCount > mFunctorsCount) {
66054c1a64d5441a964890b44280e4457e11f4f924aRomain Guy        mFunctorsCount = 0;
66154c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    } else {
66254c1a64d5441a964890b44280e4457e11f4f924aRomain Guy        mFunctorsCount -= functorCount;
66354c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    }
66454c1a64d5441a964890b44280e4457e11f4f924aRomain Guy}
66554c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
66685ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
66785ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy// Regions
66885ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy///////////////////////////////////////////////////////////////////////////////
66985ef80d8902afe8d26cb75fa7837fd9e6d019620Romain Guy
6705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain GuyTextureVertex* Caches::getRegionMesh() {
6715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
6725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    if (!mRegionMesh) {
67331e08e953fe7bdb1b1cbc247156cb6a19917a2f1Romain Guy        mRegionMesh = new TextureVertex[gMaxNumberOfQuads * 4];
6745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    }
6755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
6765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    return mRegionMesh;
6775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy}
6785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
679dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase}; // namespace uirenderer
680dd78ccacff83f0714ad90be98b58ad85f5d08c66Chet Haase}; // namespace android
681