13b20251a355c88193c439f928a84ae69483fb488John Reck/*
23b20251a355c88193c439f928a84ae69483fb488John Reck * Copyright (C) 2014 The Android Open Source Project
33b20251a355c88193c439f928a84ae69483fb488John Reck *
43b20251a355c88193c439f928a84ae69483fb488John Reck * Licensed under the Apache License, Version 2.0 (the "License");
53b20251a355c88193c439f928a84ae69483fb488John Reck * you may not use this file except in compliance with the License.
63b20251a355c88193c439f928a84ae69483fb488John Reck * You may obtain a copy of the License at
73b20251a355c88193c439f928a84ae69483fb488John Reck *
83b20251a355c88193c439f928a84ae69483fb488John Reck *      http://www.apache.org/licenses/LICENSE-2.0
93b20251a355c88193c439f928a84ae69483fb488John Reck *
103b20251a355c88193c439f928a84ae69483fb488John Reck * Unless required by applicable law or agreed to in writing, software
113b20251a355c88193c439f928a84ae69483fb488John Reck * distributed under the License is distributed on an "AS IS" BASIS,
123b20251a355c88193c439f928a84ae69483fb488John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133b20251a355c88193c439f928a84ae69483fb488John Reck * See the License for the specific language governing permissions and
143b20251a355c88193c439f928a84ae69483fb488John Reck * limitations under the License.
153b20251a355c88193c439f928a84ae69483fb488John Reck */
163e9999bd866fac71c72e6b484a9836c87c328a08sergeyv#include "DeferredLayerUpdater.h"
178cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel#include "GlLayer.h"
1845ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel#include "VkLayer.h"
1938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck#include <GpuMemoryTracker.h>
2096a5c4c7bab6718524de7253da8309143ab48befChris Craik#include "renderstate/RenderState.h"
213b20251a355c88193c439f928a84ae69483fb488John Reck
22443a714fa7c0dd07fee3527cc5bc3d3ca1fb7d44John Reck#include "renderthread/CanvasContext.h"
230e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck#include "renderthread/EglManager.h"
24117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik#include "utils/GLUtils.h"
25caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
269db58c031f8ffa102a6d585cb585bed3bdb911a9Chris Craik#include <algorithm>
279db58c031f8ffa102a6d585cb585bed3bdb911a9Chris Craik
28caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy#include <ui/ColorSpace.h>
29caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
303b20251a355c88193c439f928a84ae69483fb488John Recknamespace android {
313b20251a355c88193c439f928a84ae69483fb488John Recknamespace uirenderer {
323b20251a355c88193c439f928a84ae69483fb488John Reck
330e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John ReckRenderState::RenderState(renderthread::RenderThread& thread)
340e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck        : mRenderThread(thread)
353b20251a355c88193c439f928a84ae69483fb488John Reck        , mViewportWidth(0)
363b20251a355c88193c439f928a84ae69483fb488John Reck        , mViewportHeight(0)
373b20251a355c88193c439f928a84ae69483fb488John Reck        , mFramebuffer(0) {
380e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    mThreadId = pthread_self();
393b20251a355c88193c439f928a84ae69483fb488John Reck}
403b20251a355c88193c439f928a84ae69483fb488John Reck
413b20251a355c88193c439f928a84ae69483fb488John ReckRenderState::~RenderState() {
4244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
4396a5c4c7bab6718524de7253da8309143ab48befChris Craik            "State object lifecycle not managed correctly");
443b20251a355c88193c439f928a84ae69483fb488John Reck}
453b20251a355c88193c439f928a84ae69483fb488John Reck
463b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::onGLContextCreated() {
4744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
4896a5c4c7bab6718524de7253da8309143ab48befChris Craik            "State object lifecycle not managed correctly");
4945ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    GpuMemoryTracker::onGpuContextCreated();
5038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
5144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    mBlend = new Blend();
5296a5c4c7bab6718524de7253da8309143ab48befChris Craik    mMeshState = new MeshState();
5396a5c4c7bab6718524de7253da8309143ab48befChris Craik    mScissor = new Scissor();
5496a5c4c7bab6718524de7253da8309143ab48befChris Craik    mStencil = new Stencil();
5596a5c4c7bab6718524de7253da8309143ab48befChris Craik
563b20251a355c88193c439f928a84ae69483fb488John Reck    // This is delayed because the first access of Caches makes GL calls
57ff5c8e8097e3eff910632a568195b798798cccccChris Craik    if (!mCaches) {
58ff5c8e8097e3eff910632a568195b798798cccccChris Craik        mCaches = &Caches::createInstance(*this);
59ff5c8e8097e3eff910632a568195b798798cccccChris Craik    }
603b20251a355c88193c439f928a84ae69483fb488John Reck    mCaches->init();
613b20251a355c88193c439f928a84ae69483fb488John Reck}
623b20251a355c88193c439f928a84ae69483fb488John Reck
6357998017ff137f7d4ec33df21b6596141f8c4547John Reckstatic void layerLostGlContext(Layer* layer) {
648cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::OpenGL,
658cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel            "layerLostGlContext on non GL layer");
668cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    static_cast<GlLayer*>(layer)->onGlContextLost();
6757998017ff137f7d4ec33df21b6596141f8c4547John Reck}
6857998017ff137f7d4ec33df21b6596141f8c4547John Reck
691d4774233304c484673e2af2c1de2ab41021c979Chris Craikvoid RenderState::onGLContextDestroyed() {
709fded232a9548a304e0145011df8849fba0dcda7Chris Craik    mLayerPool.clear();
719fded232a9548a304e0145011df8849fba0dcda7Chris Craik
7296a5c4c7bab6718524de7253da8309143ab48befChris Craik    // TODO: reset all cached state in state objects
7357998017ff137f7d4ec33df21b6596141f8c4547John Reck    std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
7496a5c4c7bab6718524de7253da8309143ab48befChris Craik
7544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    mCaches->terminate();
7644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
7744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    delete mBlend;
7844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    mBlend = nullptr;
7996a5c4c7bab6718524de7253da8309143ab48befChris Craik    delete mMeshState;
8096a5c4c7bab6718524de7253da8309143ab48befChris Craik    mMeshState = nullptr;
8196a5c4c7bab6718524de7253da8309143ab48befChris Craik    delete mScissor;
8296a5c4c7bab6718524de7253da8309143ab48befChris Craik    mScissor = nullptr;
8396a5c4c7bab6718524de7253da8309143ab48befChris Craik    delete mStencil;
8496a5c4c7bab6718524de7253da8309143ab48befChris Craik    mStencil = nullptr;
8538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
86c3f131696111a066d9efd9c7c3e37566a2a9fb89sergeyv    destroyLayersInUpdater();
8745ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    GpuMemoryTracker::onGpuContextDestroyed();
8845ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel}
8945ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel
9045ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Danielvoid RenderState::onVkContextCreated() {
9145ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
9245ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel            "State object lifecycle not managed correctly");
9345ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    GpuMemoryTracker::onGpuContextCreated();
9445ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel}
9545ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel
9645ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Danielstatic void layerDestroyedVkContext(Layer* layer) {
9745ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::Vulkan,
9845ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel                        "layerLostVkContext on non Vulkan layer");
9945ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    static_cast<VkLayer*>(layer)->onVkContextDestroyed();
10045ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel}
10145ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel
10245ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Danielvoid RenderState::onVkContextDestroyed() {
10345ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    mLayerPool.clear();
10445ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerDestroyedVkContext);
10545ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    GpuMemoryTracker::onGpuContextDestroyed();
10645ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel}
10745ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel
10845ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg DanielGrContext* RenderState::getGrContext() const {
10945ec62ba72c5017fae7d8baab20bfb0d4c99c627Greg Daniel    return mRenderThread.getGrContext();
1101d4774233304c484673e2af2c1de2ab41021c979Chris Craik}
1111d4774233304c484673e2af2c1de2ab41021c979Chris Craik
1129fded232a9548a304e0145011df8849fba0dcda7Chris Craikvoid RenderState::flush(Caches::FlushMode mode) {
1139fded232a9548a304e0145011df8849fba0dcda7Chris Craik    switch (mode) {
1149fded232a9548a304e0145011df8849fba0dcda7Chris Craik        case Caches::FlushMode::Full:
1159fded232a9548a304e0145011df8849fba0dcda7Chris Craik            // fall through
1169fded232a9548a304e0145011df8849fba0dcda7Chris Craik        case Caches::FlushMode::Moderate:
1179fded232a9548a304e0145011df8849fba0dcda7Chris Craik            // fall through
1189fded232a9548a304e0145011df8849fba0dcda7Chris Craik        case Caches::FlushMode::Layers:
1199fded232a9548a304e0145011df8849fba0dcda7Chris Craik            mLayerPool.clear();
1209fded232a9548a304e0145011df8849fba0dcda7Chris Craik            break;
1219fded232a9548a304e0145011df8849fba0dcda7Chris Craik    }
1229fded232a9548a304e0145011df8849fba0dcda7Chris Craik    mCaches->flush(mode);
1239fded232a9548a304e0145011df8849fba0dcda7Chris Craik}
1249fded232a9548a304e0145011df8849fba0dcda7Chris Craik
1259a814875c4e3a98fea99dae623f22268a9afa38aJohn Reckvoid RenderState::onBitmapDestroyed(uint32_t pixelRefId) {
12636393c3e8da725927357d7a235c18e2f6c1aea98John Reck    if (mCaches && mCaches->textureCache.destroyTexture(pixelRefId)) {
1279a814875c4e3a98fea99dae623f22268a9afa38aJohn Reck        glFlush();
1289a814875c4e3a98fea99dae623f22268a9afa38aJohn Reck        GL_CHECKPOINT(MODERATE);
1299a814875c4e3a98fea99dae623f22268a9afa38aJohn Reck    }
1309a814875c4e3a98fea99dae623f22268a9afa38aJohn Reck}
1319a814875c4e3a98fea99dae623f22268a9afa38aJohn Reck
1323b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::setViewport(GLsizei width, GLsizei height) {
1333b20251a355c88193c439f928a84ae69483fb488John Reck    mViewportWidth = width;
1343b20251a355c88193c439f928a84ae69483fb488John Reck    mViewportHeight = height;
1353b20251a355c88193c439f928a84ae69483fb488John Reck    glViewport(0, 0, mViewportWidth, mViewportHeight);
1363b20251a355c88193c439f928a84ae69483fb488John Reck}
1373b20251a355c88193c439f928a84ae69483fb488John Reck
1383b20251a355c88193c439f928a84ae69483fb488John Reck
1393b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
1403b20251a355c88193c439f928a84ae69483fb488John Reck    *outWidth = mViewportWidth;
1413b20251a355c88193c439f928a84ae69483fb488John Reck    *outHeight = mViewportHeight;
1423b20251a355c88193c439f928a84ae69483fb488John Reck}
1433b20251a355c88193c439f928a84ae69483fb488John Reck
1443b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::bindFramebuffer(GLuint fbo) {
1453b20251a355c88193c439f928a84ae69483fb488John Reck    if (mFramebuffer != fbo) {
1463b20251a355c88193c439f928a84ae69483fb488John Reck        mFramebuffer = fbo;
1473b20251a355c88193c439f928a84ae69483fb488John Reck        glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
1483b20251a355c88193c439f928a84ae69483fb488John Reck    }
1493b20251a355c88193c439f928a84ae69483fb488John Reck}
1503b20251a355c88193c439f928a84ae69483fb488John Reck
1510b8d0677be2289bbc9e0b48c0878fb67d1cc0ebdJohn ReckGLuint RenderState::createFramebuffer() {
152818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik    GLuint ret;
153818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik    glGenFramebuffers(1, &ret);
154818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik    return ret;
155818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik}
156818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik
157818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craikvoid RenderState::deleteFramebuffer(GLuint fbo) {
158818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik    if (mFramebuffer == fbo) {
159818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik        // GL defines that deleting the currently bound FBO rebinds FBO 0.
160818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik        // Reflect this in our cached value.
161818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik        mFramebuffer = 0;
162818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik    }
163818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik    glDeleteFramebuffers(1, &fbo);
164818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik}
165818c9fbf1d76d5df19253ba4eb964efa939ec9ecChris Craik
1663b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
16795cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck    if (mode == DrawGlInfo::kModeProcessNoContext) {
16895cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck        // If there's no context we don't need to interrupt as there's
16995cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck        // no gl state to save/restore
17095cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck        (*functor)(mode, info);
17195cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck    } else {
17295cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck        interruptForFunctorInvoke();
17395cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck        (*functor)(mode, info);
17495cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck        resumeFromFunctorInvoke();
17595cd24bb9d000eb541bc7ec7e6b53d1c7e313076John Reck    }
1763b20251a355c88193c439f928a84ae69483fb488John Reck}
1773b20251a355c88193c439f928a84ae69483fb488John Reck
1783b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::interruptForFunctorInvoke() {
1796c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    mCaches->setProgram(nullptr);
18044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    mCaches->textureState().resetActiveTexture();
18196a5c4c7bab6718524de7253da8309143ab48befChris Craik    meshState().unbindMeshBuffer();
18296a5c4c7bab6718524de7253da8309143ab48befChris Craik    meshState().unbindIndicesBuffer();
18396a5c4c7bab6718524de7253da8309143ab48befChris Craik    meshState().resetVertexPointers();
18496a5c4c7bab6718524de7253da8309143ab48befChris Craik    meshState().disableTexCoordsVertexArray();
1853b20251a355c88193c439f928a84ae69483fb488John Reck    debugOverdraw(false, false);
186253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    // TODO: We need a way to know whether the functor is sRGB aware (b/32072673)
187efb4b06493fe7b1604c762a448b13c7af2845a8dRomain Guy    if (mCaches->extensions().hasLinearBlending() &&
188efb4b06493fe7b1604c762a448b13c7af2845a8dRomain Guy            mCaches->extensions().hasSRGBWriteControl()) {
189253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy        glDisable(GL_FRAMEBUFFER_SRGB_EXT);
190253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    }
1913b20251a355c88193c439f928a84ae69483fb488John Reck}
1923b20251a355c88193c439f928a84ae69483fb488John Reck
1933b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::resumeFromFunctorInvoke() {
194efb4b06493fe7b1604c762a448b13c7af2845a8dRomain Guy    if (mCaches->extensions().hasLinearBlending() &&
195efb4b06493fe7b1604c762a448b13c7af2845a8dRomain Guy            mCaches->extensions().hasSRGBWriteControl()) {
196253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy        glEnable(GL_FRAMEBUFFER_SRGB_EXT);
197253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    }
198253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy
1993b20251a355c88193c439f928a84ae69483fb488John Reck    glViewport(0, 0, mViewportWidth, mViewportHeight);
2003b20251a355c88193c439f928a84ae69483fb488John Reck    glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
2013b20251a355c88193c439f928a84ae69483fb488John Reck    debugOverdraw(false, false);
2023b20251a355c88193c439f928a84ae69483fb488John Reck
2033b20251a355c88193c439f928a84ae69483fb488John Reck    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
2043b20251a355c88193c439f928a84ae69483fb488John Reck
20565fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik    scissor().invalidate();
20644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    blend().invalidate();
2073b20251a355c88193c439f928a84ae69483fb488John Reck
20844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    mCaches->textureState().activateTexture(0);
20944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    mCaches->textureState().resetBoundTextures();
2103b20251a355c88193c439f928a84ae69483fb488John Reck}
2113b20251a355c88193c439f928a84ae69483fb488John Reck
2123b20251a355c88193c439f928a84ae69483fb488John Reckvoid RenderState::debugOverdraw(bool enable, bool clear) {
2132507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik    if (Properties::debugOverdraw && mFramebuffer == 0) {
2143b20251a355c88193c439f928a84ae69483fb488John Reck        if (clear) {
21565fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik            scissor().setEnabled(false);
21696a5c4c7bab6718524de7253da8309143ab48befChris Craik            stencil().clear();
2173b20251a355c88193c439f928a84ae69483fb488John Reck        }
2183b20251a355c88193c439f928a84ae69483fb488John Reck        if (enable) {
21996a5c4c7bab6718524de7253da8309143ab48befChris Craik            stencil().enableDebugWrite();
2203b20251a355c88193c439f928a84ae69483fb488John Reck        } else {
22196a5c4c7bab6718524de7253da8309143ab48befChris Craik            stencil().disable();
2223b20251a355c88193c439f928a84ae69483fb488John Reck        }
2233b20251a355c88193c439f928a84ae69483fb488John Reck    }
2243b20251a355c88193c439f928a84ae69483fb488John Reck}
2253b20251a355c88193c439f928a84ae69483fb488John Reck
2263e9999bd866fac71c72e6b484a9836c87c328a08sergeyvstatic void destroyLayerInUpdater(DeferredLayerUpdater* layerUpdater) {
2273e9999bd866fac71c72e6b484a9836c87c328a08sergeyv    layerUpdater->destroyLayer();
2283e9999bd866fac71c72e6b484a9836c87c328a08sergeyv}
2293e9999bd866fac71c72e6b484a9836c87c328a08sergeyv
2303e9999bd866fac71c72e6b484a9836c87c328a08sergeyvvoid RenderState::destroyLayersInUpdater() {
2313e9999bd866fac71c72e6b484a9836c87c328a08sergeyv    std::for_each(mActiveLayerUpdaters.begin(), mActiveLayerUpdaters.end(), destroyLayerInUpdater);
2323e9999bd866fac71c72e6b484a9836c87c328a08sergeyv}
2333e9999bd866fac71c72e6b484a9836c87c328a08sergeyv
2340e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reckclass DecStrongTask : public renderthread::RenderTask {
2350e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reckpublic:
236c6baf563ba6aa207a48317c177b29f1d2b70cf3dChih-Hung Hsieh    explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
2370e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck
238d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void run() override {
239d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik        mObject->decStrong(nullptr);
240d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik        mObject = nullptr;
2410e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck        delete this;
2420e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    }
2430e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck
2440e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reckprivate:
2450e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    VirtualLightRefBase* mObject;
2460e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck};
2470e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck
2480e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reckvoid RenderState::postDecStrong(VirtualLightRefBase* object) {
249a55b5d6c65cde2b7cc28bb3ea160bfaaef7a446aJohn Reck    if (pthread_equal(mThreadId, pthread_self())) {
250a55b5d6c65cde2b7cc28bb3ea160bfaaef7a446aJohn Reck        object->decStrong(nullptr);
251a55b5d6c65cde2b7cc28bb3ea160bfaaef7a446aJohn Reck    } else {
252a55b5d6c65cde2b7cc28bb3ea160bfaaef7a446aJohn Reck        mRenderThread.queue(new DecStrongTask(object));
253a55b5d6c65cde2b7cc28bb3ea160bfaaef7a446aJohn Reck    }
2540e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck}
2550e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck
2566c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik///////////////////////////////////////////////////////////////////////////////
2576c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik// Render
2586c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik///////////////////////////////////////////////////////////////////////////////
2596c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
26012efe649d3f5df8e81f4b78179939c1d488673a0Chris Craikvoid RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
2616c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    const Glop::Mesh& mesh = glop.mesh;
262ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    const Glop::Mesh::Vertices& vertices = mesh.vertices;
263ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    const Glop::Mesh::Indices& indices = mesh.indices;
2640519c810a56bded1284fcb2ae40f438878c6585fChris Craik    const Glop::Fill& fill = glop.fill;
2656c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
266975591a7af883d866d86ab819e164c6004694744John Reck    GL_CHECKPOINT(MODERATE);
2679372ac3621848085e77b867f220c0b5ffce4010dJohn Reck
2680519c810a56bded1284fcb2ae40f438878c6585fChris Craik    // ---------------------------------------------
2690519c810a56bded1284fcb2ae40f438878c6585fChris Craik    // ---------- Program + uniform setup ----------
2700519c810a56bded1284fcb2ae40f438878c6585fChris Craik    // ---------------------------------------------
2710519c810a56bded1284fcb2ae40f438878c6585fChris Craik    mCaches->setProgram(fill.program);
2726c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
2730519c810a56bded1284fcb2ae40f438878c6585fChris Craik    if (fill.colorEnabled) {
2740519c810a56bded1284fcb2ae40f438878c6585fChris Craik        fill.program->setColor(fill.color);
2750519c810a56bded1284fcb2ae40f438878c6585fChris Craik    }
2766c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
27712efe649d3f5df8e81f4b78179939c1d488673a0Chris Craik    fill.program->set(orthoMatrix,
2786c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik            glop.transform.modelView,
27953e51e4aa933f9603587e1780f446c18816bf9beChris Craik            glop.transform.meshTransform(),
28053e51e4aa933f9603587e1780f446c18816bf9beChris Craik            glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
281117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik
2820519c810a56bded1284fcb2ae40f438878c6585fChris Craik    // Color filter uniforms
283b9ce116dac378b4cf4490f265dcbd5704a1dd43cChris Craik    if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
284ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        const FloatColor& color = fill.filter.color;
285117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik        glUniform4f(mCaches->program().getUniform("colorBlend"),
286117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik                color.r, color.g, color.b, color.a);
287b9ce116dac378b4cf4490f265dcbd5704a1dd43cChris Craik    } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
288117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik        glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
289ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik                fill.filter.matrix.matrix);
290117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik        glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
291ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik                fill.filter.matrix.vector);
292117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    }
2936c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
2940519c810a56bded1284fcb2ae40f438878c6585fChris Craik    // Round rect clipping uniforms
2950519c810a56bded1284fcb2ae40f438878c6585fChris Craik    if (glop.roundRectClipState) {
2960519c810a56bded1284fcb2ae40f438878c6585fChris Craik        // TODO: avoid query, and cache values (or RRCS ptr) in program
2970519c810a56bded1284fcb2ae40f438878c6585fChris Craik        const RoundRectClipState* state = glop.roundRectClipState;
2980519c810a56bded1284fcb2ae40f438878c6585fChris Craik        const Rect& innerRect = state->innerRect;
2990519c810a56bded1284fcb2ae40f438878c6585fChris Craik        glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
3000519c810a56bded1284fcb2ae40f438878c6585fChris Craik                innerRect.left, innerRect.top,
3010519c810a56bded1284fcb2ae40f438878c6585fChris Craik                innerRect.right, innerRect.bottom);
3020519c810a56bded1284fcb2ae40f438878c6585fChris Craik        glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
3030519c810a56bded1284fcb2ae40f438878c6585fChris Craik                1, GL_FALSE, &state->matrix.data[0]);
3040519c810a56bded1284fcb2ae40f438878c6585fChris Craik
3050519c810a56bded1284fcb2ae40f438878c6585fChris Craik        // add half pixel to round out integer rect space to cover pixel centers
3060519c810a56bded1284fcb2ae40f438878c6585fChris Craik        float roundedOutRadius = state->radius + 0.5f;
3070519c810a56bded1284fcb2ae40f438878c6585fChris Craik        glUniform1f(fill.program->getUniform("roundRectRadius"),
3080519c810a56bded1284fcb2ae40f438878c6585fChris Craik                roundedOutRadius);
3090519c810a56bded1284fcb2ae40f438878c6585fChris Craik    }
310ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik
311975591a7af883d866d86ab819e164c6004694744John Reck    GL_CHECKPOINT(MODERATE);
3129372ac3621848085e77b867f220c0b5ffce4010dJohn Reck
313117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // --------------------------------
3146c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    // ---------- Mesh setup ----------
315117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // --------------------------------
316117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // vertices
3171b7db4000eabb570697f4c5097588acbfa4df62bChris Craik    meshState().bindMeshBuffer(vertices.bufferObject);
3181b7db4000eabb570697f4c5097588acbfa4df62bChris Craik    meshState().bindPositionVertexPointer(vertices.position, vertices.stride);
319117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik
320117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // indices
3211b7db4000eabb570697f4c5097588acbfa4df62bChris Craik    meshState().bindIndicesBuffer(indices.bufferObject);
322117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik
323138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik    // texture
324138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik    if (fill.texture.texture != nullptr) {
32526bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik        const Glop::Fill::TextureData& texture = fill.texture;
32626bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik        // texture always takes slot 0, shader samplers increment from there
3270519c810a56bded1284fcb2ae40f438878c6585fChris Craik        mCaches->textureState().activateTexture(0);
3280519c810a56bded1284fcb2ae40f438878c6585fChris Craik
3292a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv        mCaches->textureState().bindTexture(texture.texture->target(), texture.texture->id());
33026bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik        if (texture.clamp != GL_INVALID_ENUM) {
3312a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv            texture.texture->setWrap(texture.clamp, false, false);
33230036092b40badecbe64d9c2bff4850132147f78Chris Craik        }
33326bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik        if (texture.filter != GL_INVALID_ENUM) {
3342a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv            texture.texture->setFilter(texture.filter, false, false);
33530036092b40badecbe64d9c2bff4850132147f78Chris Craik        }
3360519c810a56bded1284fcb2ae40f438878c6585fChris Craik
33726bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik        if (texture.textureTransform) {
33826bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik            glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
33926bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik                    GL_FALSE, &texture.textureTransform->data[0]);
34026bf34200e40a0fa8c66366559aa016380cd8c6fChris Craik        }
341138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik    }
342138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik
343138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik    // vertex attributes (tex coord, color, alpha)
344138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik    if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
345138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik        meshState().enableTexCoordsVertexArray();
346138c21fbec12bead3c7ca1f181c3fd35542ccb00Chris Craik        meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride);
3476c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    } else {
3486c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik        meshState().disableTexCoordsVertexArray();
3496c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    }
350ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    int colorLocation = -1;
35153e51e4aa933f9603587e1780f446c18816bf9beChris Craik    if (vertices.attribFlags & VertexAttribFlags::Color) {
352ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        colorLocation = fill.program->getAttrib("colors");
353ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glEnableVertexAttribArray(colorLocation);
354ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
3556c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    }
356ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    int alphaLocation = -1;
35753e51e4aa933f9603587e1780f446c18816bf9beChris Craik    if (vertices.attribFlags & VertexAttribFlags::Alpha) {
358ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        // NOTE: alpha vertex position is computed assuming no VBO
359ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
360ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        alphaLocation = fill.program->getAttrib("vtxAlpha");
361ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glEnableVertexAttribArray(alphaLocation);
362ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
3636c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    }
364922d3a7f6f8c1c05a996ee3e91e8cbadfff560c9Chris Craik    // Shader uniforms
365253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
366922d3a7f6f8c1c05a996ee3e91e8cbadfff560c9Chris Craik
367975591a7af883d866d86ab819e164c6004694744John Reck    GL_CHECKPOINT(MODERATE);
368c5a3efd28668a62df3e3b364b49624c5af7549b6Dohyun Lee    Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
369c5a3efd28668a62df3e3b364b49624c5af7549b6Dohyun Lee            fill.skiaShaderData.bitmapData.bitmapTexture : nullptr;
370c5a3efd28668a62df3e3b364b49624c5af7549b6Dohyun Lee    const AutoTexture autoCleanup(texture);
3719372ac3621848085e77b867f220c0b5ffce4010dJohn Reck
372caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    // If we have a shader and a base texture, the base texture is assumed to be an alpha mask
373caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    // which means the color space conversion applies to the shader's bitmap
374caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    Texture* colorSpaceTexture = texture != nullptr ? texture : fill.texture.texture;
375caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    if (colorSpaceTexture != nullptr) {
376caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        if (colorSpaceTexture->hasColorSpaceConversion()) {
377caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy            const ColorSpaceConnector* connector = colorSpaceTexture->getColorSpaceConnector();
378caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy            glUniformMatrix3fv(fill.program->getUniform("colorSpaceMatrix"), 1,
379caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    GL_FALSE, connector->getTransform().asArray());
380caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        }
381caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
382caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        TransferFunctionType transferFunction = colorSpaceTexture->getTransferFunctionType();
383caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        if (transferFunction != TransferFunctionType::None) {
384caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy            const ColorSpaceConnector* connector = colorSpaceTexture->getColorSpaceConnector();
385caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy            const ColorSpace& source = connector->getSource();
386caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
387caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy            switch (transferFunction) {
388caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                case TransferFunctionType::None:
389caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    break;
390caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                case TransferFunctionType::Full:
391caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    glUniform1fv(fill.program->getUniform("transferFunction"), 7,
392caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                            reinterpret_cast<const float*>(&source.getTransferParameters().g));
393caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    break;
394caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                case TransferFunctionType::Limited:
395caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    glUniform1fv(fill.program->getUniform("transferFunction"), 5,
396caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                            reinterpret_cast<const float*>(&source.getTransferParameters().g));
397caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    break;
398caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                case TransferFunctionType::Gamma:
399caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    glUniform1f(fill.program->getUniform("transferFunctionGamma"),
400caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                            source.getTransferParameters().g);
401caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy                    break;
402caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy            }
403caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        }
404caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    }
405caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
406117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // ------------------------------------
4076c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    // ---------- GL state setup ----------
408117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // ------------------------------------
409031888744e24b5c7243ac99ec98b78aff5db1c78Chris Craik    blend().setFactors(glop.blend.src, glop.blend.dst);
4106c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
411975591a7af883d866d86ab819e164c6004694744John Reck    GL_CHECKPOINT(MODERATE);
4129372ac3621848085e77b867f220c0b5ffce4010dJohn Reck
413117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // ------------------------------------
4142ab95d780b023152556d9f8659de734ec7b55047Chris Craik    // ---------- Actual drawing ----------
415117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    // ------------------------------------
416ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    if (indices.bufferObject == meshState().getQuadListIBO()) {
4172ab95d780b023152556d9f8659de734ec7b55047Chris Craik        // Since the indexed quad list is of limited length, we loop over
4182ab95d780b023152556d9f8659de734ec7b55047Chris Craik        // the glDrawXXX method while updating the vertex pointer
4190519c810a56bded1284fcb2ae40f438878c6585fChris Craik        GLsizei elementsCount = mesh.elementCount;
420ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
4212ab95d780b023152556d9f8659de734ec7b55047Chris Craik        while (elementsCount > 0) {
4229db58c031f8ffa102a6d585cb585bed3bdb911a9Chris Craik            GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
4231b7db4000eabb570697f4c5097588acbfa4df62bChris Craik            meshState().bindPositionVertexPointer(vertexData, vertices.stride);
42453e51e4aa933f9603587e1780f446c18816bf9beChris Craik            if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
4251b7db4000eabb570697f4c5097588acbfa4df62bChris Craik                meshState().bindTexCoordsVertexPointer(
426ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik                        vertexData + kMeshTextureOffset, vertices.stride);
427f27133df2d179c99d6bc1ae644af09e9153a0071Chris Craik            }
428f27133df2d179c99d6bc1ae644af09e9153a0071Chris Craik
4292ab95d780b023152556d9f8659de734ec7b55047Chris Craik            glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
4302ab95d780b023152556d9f8659de734ec7b55047Chris Craik            elementsCount -= drawCount;
431ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik            vertexData += (drawCount / 6) * 4 * vertices.stride;
4322ab95d780b023152556d9f8659de734ec7b55047Chris Craik        }
433ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    } else if (indices.bufferObject || indices.indices) {
434ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
4356c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    } else {
4360519c810a56bded1284fcb2ae40f438878c6585fChris Craik        glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
437117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    }
438117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik
439975591a7af883d866d86ab819e164c6004694744John Reck    GL_CHECKPOINT(MODERATE);
4409372ac3621848085e77b867f220c0b5ffce4010dJohn Reck
4412ab95d780b023152556d9f8659de734ec7b55047Chris Craik    // -----------------------------------
4422ab95d780b023152556d9f8659de734ec7b55047Chris Craik    // ---------- Mesh teardown ----------
4432ab95d780b023152556d9f8659de734ec7b55047Chris Craik    // -----------------------------------
44453e51e4aa933f9603587e1780f446c18816bf9beChris Craik    if (vertices.attribFlags & VertexAttribFlags::Alpha) {
445ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glDisableVertexAttribArray(alphaLocation);
446ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik    }
44753e51e4aa933f9603587e1780f446c18816bf9beChris Craik    if (vertices.attribFlags & VertexAttribFlags::Color) {
448ef2507439c08f4e9c4c9bba1c6243ca9df2ee827Chris Craik        glDisableVertexAttribArray(colorLocation);
4496c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik    }
4509372ac3621848085e77b867f220c0b5ffce4010dJohn Reck
451975591a7af883d866d86ab819e164c6004694744John Reck    GL_CHECKPOINT(MODERATE);
4526c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik}
4536c15ffa196fc9b7724c189d833c3435d8db12266Chris Craik
454117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craikvoid RenderState::dump() {
455117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    blend().dump();
456117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    meshState().dump();
457117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    scissor().dump();
458117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik    stencil().dump();
459117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik}
460117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik
4613b20251a355c88193c439f928a84ae69483fb488John Reck} /* namespace uirenderer */
4623b20251a355c88193c439f928a84ae69483fb488John Reck} /* namespace android */
463