blob: e78cd7296f42253b8d30470da5441be3deda370a [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
John Reck38e0c322015-11-10 12:19:17 -080016#include <GpuMemoryTracker.h>
Chris Craik96a5c4c2015-01-27 15:46:35 -080017#include "renderstate/RenderState.h"
John Reck3b202512014-06-23 13:13:08 -070018
John Reck443a7142014-09-04 17:40:05 -070019#include "renderthread/CanvasContext.h"
John Reck0e89e2b2014-10-31 14:49:06 -070020#include "renderthread/EglManager.h"
Chris Craik117bdbc2015-02-05 10:12:38 -080021#include "utils/GLUtils.h"
Chris Craik9db58c02015-08-19 15:19:18 -070022#include <algorithm>
23
John Reck3b202512014-06-23 13:13:08 -070024namespace android {
25namespace uirenderer {
26
John Reck0e89e2b2014-10-31 14:49:06 -070027RenderState::RenderState(renderthread::RenderThread& thread)
28 : mRenderThread(thread)
John Reck3b202512014-06-23 13:13:08 -070029 , mViewportWidth(0)
30 , mViewportHeight(0)
31 , mFramebuffer(0) {
John Reck0e89e2b2014-10-31 14:49:06 -070032 mThreadId = pthread_self();
John Reck3b202512014-06-23 13:13:08 -070033}
34
35RenderState::~RenderState() {
Chris Craik44eb2c02015-01-29 09:45:09 -080036 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080037 "State object lifecycle not managed correctly");
John Reck3b202512014-06-23 13:13:08 -070038}
39
40void RenderState::onGLContextCreated() {
Chris Craik44eb2c02015-01-29 09:45:09 -080041 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080042 "State object lifecycle not managed correctly");
John Reck38e0c322015-11-10 12:19:17 -080043 GpuMemoryTracker::onGLContextCreated();
44
Chris Craik44eb2c02015-01-29 09:45:09 -080045 mBlend = new Blend();
Chris Craik96a5c4c2015-01-27 15:46:35 -080046 mMeshState = new MeshState();
47 mScissor = new Scissor();
48 mStencil = new Stencil();
Chris Craik65fe5ee2015-01-26 18:06:29 -080049
Chris Craik96a5c4c2015-01-27 15:46:35 -080050 // This is delayed because the first access of Caches makes GL calls
Chris Craikff5c8e82015-01-30 09:46:18 -080051 if (!mCaches) {
52 mCaches = &Caches::createInstance(*this);
53 }
Chris Craik96a5c4c2015-01-27 15:46:35 -080054 mCaches->init();
55 mCaches->textureCache.setAssetAtlas(&mAssetAtlas);
John Reck3b202512014-06-23 13:13:08 -070056}
57
John Reck49bc4ac2015-01-29 12:53:38 -080058static void layerLostGlContext(Layer* layer) {
59 layer->onGlContextLost();
60}
61
Chris Craik1d477422014-08-26 17:30:15 -070062void RenderState::onGLContextDestroyed() {
Chris Craik21029ef2014-09-12 09:29:10 -070063/*
Chris Craikbfd1cd62014-09-10 13:04:31 -070064 size_t size = mActiveLayers.size();
65 if (CC_UNLIKELY(size != 0)) {
66 ALOGE("Crashing, have %d contexts and %d layers at context destruction. isempty %d",
67 mRegisteredContexts.size(), size, mActiveLayers.empty());
John Reck17035b02014-09-03 07:39:53 -070068 mCaches->dumpMemoryUsage();
John Reck443a7142014-09-04 17:40:05 -070069 for (std::set<renderthread::CanvasContext*>::iterator cit = mRegisteredContexts.begin();
70 cit != mRegisteredContexts.end(); cit++) {
71 renderthread::CanvasContext* context = *cit;
Chris Craikbfd1cd62014-09-10 13:04:31 -070072 ALOGE("Context: %p (root = %p)", context, context->mRootRenderNode.get());
73 ALOGE(" Prefeteched layers: %zu", context->mPrefetechedLayers.size());
John Reck443a7142014-09-04 17:40:05 -070074 for (std::set<RenderNode*>::iterator pit = context->mPrefetechedLayers.begin();
75 pit != context->mPrefetechedLayers.end(); pit++) {
76 (*pit)->debugDumpLayers(" ");
77 }
78 context->mRootRenderNode->debugDumpLayers(" ");
79 }
Chris Craik599e2542014-09-05 15:17:11 -070080
Chris Craikbfd1cd62014-09-10 13:04:31 -070081
82 if (mActiveLayers.begin() == mActiveLayers.end()) {
83 ALOGE("set has become empty. wat.");
84 }
Chris Craik599e2542014-09-05 15:17:11 -070085 for (std::set<const Layer*>::iterator lit = mActiveLayers.begin();
86 lit != mActiveLayers.end(); lit++) {
87 const Layer* layer = *(lit);
Chris Craikbfd1cd62014-09-10 13:04:31 -070088 ALOGE("Layer %p, state %d, texlayer %d, fbo %d, buildlayered %d",
89 layer, layer->state, layer->isTextureLayer(), layer->getFbo(), layer->wasBuildLayered);
Chris Craik599e2542014-09-05 15:17:11 -070090 }
Chris Craikbfd1cd62014-09-10 13:04:31 -070091 LOG_ALWAYS_FATAL("%d layers have survived gl context destruction", size);
John Reck17035b02014-09-03 07:39:53 -070092 }
Chris Craik21029ef2014-09-12 09:29:10 -070093*/
John Reck49bc4ac2015-01-29 12:53:38 -080094
Chris Craik9fded232015-11-11 16:42:34 -080095 mLayerPool.clear();
96
Chris Craik96a5c4c2015-01-27 15:46:35 -080097 // TODO: reset all cached state in state objects
John Reck49bc4ac2015-01-29 12:53:38 -080098 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
John Reckebd52612014-12-10 16:47:36 -080099 mAssetAtlas.terminate();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800100
Chris Craik44eb2c02015-01-29 09:45:09 -0800101 mCaches->terminate();
102
103 delete mBlend;
104 mBlend = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800105 delete mMeshState;
106 mMeshState = nullptr;
107 delete mScissor;
108 mScissor = nullptr;
109 delete mStencil;
110 mStencil = nullptr;
John Reck38e0c322015-11-10 12:19:17 -0800111
112 GpuMemoryTracker::onGLContextDestroyed();
Chris Craik1d477422014-08-26 17:30:15 -0700113}
114
Chris Craik9fded232015-11-11 16:42:34 -0800115void RenderState::flush(Caches::FlushMode mode) {
116 switch (mode) {
117 case Caches::FlushMode::Full:
118 // fall through
119 case Caches::FlushMode::Moderate:
120 // fall through
121 case Caches::FlushMode::Layers:
122 mLayerPool.clear();
123 break;
124 }
125 mCaches->flush(mode);
126}
127
John Reck3b202512014-06-23 13:13:08 -0700128void RenderState::setViewport(GLsizei width, GLsizei height) {
129 mViewportWidth = width;
130 mViewportHeight = height;
131 glViewport(0, 0, mViewportWidth, mViewportHeight);
132}
133
134
135void RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
136 *outWidth = mViewportWidth;
137 *outHeight = mViewportHeight;
138}
139
140void RenderState::bindFramebuffer(GLuint fbo) {
141 if (mFramebuffer != fbo) {
142 mFramebuffer = fbo;
143 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
144 }
145}
146
John Reck0b8d0672016-01-29 14:18:22 -0800147GLuint RenderState::createFramebuffer() {
Chris Craik818c9fb2015-10-23 14:33:42 -0700148 GLuint ret;
149 glGenFramebuffers(1, &ret);
150 return ret;
151}
152
153void RenderState::deleteFramebuffer(GLuint fbo) {
154 if (mFramebuffer == fbo) {
155 // GL defines that deleting the currently bound FBO rebinds FBO 0.
156 // Reflect this in our cached value.
157 mFramebuffer = 0;
158 }
159 glDeleteFramebuffers(1, &fbo);
160}
161
John Reck3b202512014-06-23 13:13:08 -0700162void RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
John Reck95cd24b2015-08-04 11:17:39 -0700163 if (mode == DrawGlInfo::kModeProcessNoContext) {
164 // If there's no context we don't need to interrupt as there's
165 // no gl state to save/restore
166 (*functor)(mode, info);
167 } else {
168 interruptForFunctorInvoke();
169 (*functor)(mode, info);
170 resumeFromFunctorInvoke();
171 }
John Reck3b202512014-06-23 13:13:08 -0700172}
173
174void RenderState::interruptForFunctorInvoke() {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800175 mCaches->setProgram(nullptr);
Chris Craik44eb2c02015-01-29 09:45:09 -0800176 mCaches->textureState().resetActiveTexture();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800177 meshState().unbindMeshBuffer();
178 meshState().unbindIndicesBuffer();
179 meshState().resetVertexPointers();
180 meshState().disableTexCoordsVertexArray();
John Reck3b202512014-06-23 13:13:08 -0700181 debugOverdraw(false, false);
182}
183
184void RenderState::resumeFromFunctorInvoke() {
185 glViewport(0, 0, mViewportWidth, mViewportHeight);
186 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
187 debugOverdraw(false, false);
188
189 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
190
Chris Craik65fe5ee2015-01-26 18:06:29 -0800191 scissor().invalidate();
Chris Craik44eb2c02015-01-29 09:45:09 -0800192 blend().invalidate();
John Reck3b202512014-06-23 13:13:08 -0700193
Chris Craik44eb2c02015-01-29 09:45:09 -0800194 mCaches->textureState().activateTexture(0);
195 mCaches->textureState().resetBoundTextures();
John Reck3b202512014-06-23 13:13:08 -0700196}
197
198void RenderState::debugOverdraw(bool enable, bool clear) {
Chris Craik2507c342015-05-04 14:36:49 -0700199 if (Properties::debugOverdraw && mFramebuffer == 0) {
John Reck3b202512014-06-23 13:13:08 -0700200 if (clear) {
Chris Craik65fe5ee2015-01-26 18:06:29 -0800201 scissor().setEnabled(false);
Chris Craik96a5c4c2015-01-27 15:46:35 -0800202 stencil().clear();
John Reck3b202512014-06-23 13:13:08 -0700203 }
204 if (enable) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800205 stencil().enableDebugWrite();
John Reck3b202512014-06-23 13:13:08 -0700206 } else {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800207 stencil().disable();
John Reck3b202512014-06-23 13:13:08 -0700208 }
209 }
210}
211
John Reck0e89e2b2014-10-31 14:49:06 -0700212class DecStrongTask : public renderthread::RenderTask {
213public:
214 DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
215
Chris Craikd41c4d82015-01-05 15:51:13 -0800216 virtual void run() override {
217 mObject->decStrong(nullptr);
218 mObject = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700219 delete this;
220 }
221
222private:
223 VirtualLightRefBase* mObject;
224};
225
226void RenderState::postDecStrong(VirtualLightRefBase* object) {
John Recka55b5d62016-01-14 15:09:10 -0800227 if (pthread_equal(mThreadId, pthread_self())) {
228 object->decStrong(nullptr);
229 } else {
230 mRenderThread.queue(new DecStrongTask(object));
231 }
John Reck0e89e2b2014-10-31 14:49:06 -0700232}
233
Chris Craik6c15ffa2015-02-02 13:50:55 -0800234///////////////////////////////////////////////////////////////////////////////
235// Render
236///////////////////////////////////////////////////////////////////////////////
237
Chris Craik12efe642015-09-28 15:52:12 -0700238void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800239 const Glop::Mesh& mesh = glop.mesh;
Chris Craikef250742015-02-25 17:16:16 -0800240 const Glop::Mesh::Vertices& vertices = mesh.vertices;
241 const Glop::Mesh::Indices& indices = mesh.indices;
Chris Craik0519c812015-02-11 13:17:06 -0800242 const Glop::Fill& fill = glop.fill;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800243
John Reck975591a2016-01-22 16:28:07 -0800244 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800245
Chris Craik0519c812015-02-11 13:17:06 -0800246 // ---------------------------------------------
247 // ---------- Program + uniform setup ----------
248 // ---------------------------------------------
249 mCaches->setProgram(fill.program);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800250
Chris Craik0519c812015-02-11 13:17:06 -0800251 if (fill.colorEnabled) {
252 fill.program->setColor(fill.color);
253 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800254
Chris Craik12efe642015-09-28 15:52:12 -0700255 fill.program->set(orthoMatrix,
Chris Craik6c15ffa2015-02-02 13:50:55 -0800256 glop.transform.modelView,
Chris Craik53e51e42015-06-01 10:35:35 -0700257 glop.transform.meshTransform(),
258 glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800259
Chris Craik0519c812015-02-11 13:17:06 -0800260 // Color filter uniforms
Chris Craikb9ce116d2015-08-20 15:14:06 -0700261 if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
Chris Craikef250742015-02-25 17:16:16 -0800262 const FloatColor& color = fill.filter.color;
Chris Craik117bdbc2015-02-05 10:12:38 -0800263 glUniform4f(mCaches->program().getUniform("colorBlend"),
264 color.r, color.g, color.b, color.a);
Chris Craikb9ce116d2015-08-20 15:14:06 -0700265 } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
Chris Craik117bdbc2015-02-05 10:12:38 -0800266 glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
Chris Craikef250742015-02-25 17:16:16 -0800267 fill.filter.matrix.matrix);
Chris Craik117bdbc2015-02-05 10:12:38 -0800268 glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
Chris Craikef250742015-02-25 17:16:16 -0800269 fill.filter.matrix.vector);
Chris Craik117bdbc2015-02-05 10:12:38 -0800270 }
271
Chris Craik0519c812015-02-11 13:17:06 -0800272 // Round rect clipping uniforms
273 if (glop.roundRectClipState) {
274 // TODO: avoid query, and cache values (or RRCS ptr) in program
275 const RoundRectClipState* state = glop.roundRectClipState;
276 const Rect& innerRect = state->innerRect;
277 glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
278 innerRect.left, innerRect.top,
279 innerRect.right, innerRect.bottom);
280 glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
281 1, GL_FALSE, &state->matrix.data[0]);
282
283 // add half pixel to round out integer rect space to cover pixel centers
284 float roundedOutRadius = state->radius + 0.5f;
285 glUniform1f(fill.program->getUniform("roundRectRadius"),
286 roundedOutRadius);
287 }
Chris Craikef250742015-02-25 17:16:16 -0800288
John Reck975591a2016-01-22 16:28:07 -0800289 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800290
Chris Craik117bdbc2015-02-05 10:12:38 -0800291 // --------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800292 // ---------- Mesh setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800293 // --------------------------------
294 // vertices
Chris Craik1b7db402016-02-24 18:25:32 -0800295 meshState().bindMeshBuffer(vertices.bufferObject);
296 meshState().bindPositionVertexPointer(vertices.position, vertices.stride);
Chris Craik117bdbc2015-02-05 10:12:38 -0800297
298 // indices
Chris Craik1b7db402016-02-24 18:25:32 -0800299 meshState().bindIndicesBuffer(indices.bufferObject);
Chris Craik117bdbc2015-02-05 10:12:38 -0800300
Chris Craik138c21f2016-04-28 16:59:42 -0700301 // texture
302 if (fill.texture.texture != nullptr) {
Chris Craik26bf3422015-02-26 16:28:17 -0800303 const Glop::Fill::TextureData& texture = fill.texture;
304 // texture always takes slot 0, shader samplers increment from there
Chris Craik0519c812015-02-11 13:17:06 -0800305 mCaches->textureState().activateTexture(0);
306
Chris Craik1b7db402016-02-24 18:25:32 -0800307 mCaches->textureState().bindTexture(texture.target, texture.texture->id());
Chris Craik26bf3422015-02-26 16:28:17 -0800308 if (texture.clamp != GL_INVALID_ENUM) {
Chris Craik1b7db402016-02-24 18:25:32 -0800309 texture.texture->setWrap(texture.clamp, false, false, texture.target);
Chris Craik30036092015-02-12 10:41:39 -0800310 }
Chris Craik26bf3422015-02-26 16:28:17 -0800311 if (texture.filter != GL_INVALID_ENUM) {
Chris Craik1b7db402016-02-24 18:25:32 -0800312 texture.texture->setFilter(texture.filter, false, false, texture.target);
Chris Craik30036092015-02-12 10:41:39 -0800313 }
Chris Craik0519c812015-02-11 13:17:06 -0800314
Chris Craik26bf3422015-02-26 16:28:17 -0800315 if (texture.textureTransform) {
316 glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
317 GL_FALSE, &texture.textureTransform->data[0]);
318 }
Chris Craik138c21f2016-04-28 16:59:42 -0700319 }
320
321 // vertex attributes (tex coord, color, alpha)
322 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
323 meshState().enableTexCoordsVertexArray();
324 meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800325 } else {
326 meshState().disableTexCoordsVertexArray();
327 }
Chris Craikef250742015-02-25 17:16:16 -0800328 int colorLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700329 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800330 colorLocation = fill.program->getAttrib("colors");
331 glEnableVertexAttribArray(colorLocation);
332 glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800333 }
Chris Craikef250742015-02-25 17:16:16 -0800334 int alphaLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700335 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800336 // NOTE: alpha vertex position is computed assuming no VBO
337 const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
338 alphaLocation = fill.program->getAttrib("vtxAlpha");
339 glEnableVertexAttribArray(alphaLocation);
340 glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800341 }
Chris Craik922d3a72015-02-13 17:47:21 -0800342 // Shader uniforms
Chris Craikef250742015-02-25 17:16:16 -0800343 SkiaShader::apply(*mCaches, fill.skiaShaderData);
Chris Craik922d3a72015-02-13 17:47:21 -0800344
John Reck975591a2016-01-22 16:28:07 -0800345 GL_CHECKPOINT(MODERATE);
Dohyun Leec5a3efd2016-01-21 13:46:21 +0900346 Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
347 fill.skiaShaderData.bitmapData.bitmapTexture : nullptr;
348 const AutoTexture autoCleanup(texture);
John Reck9372ac32016-01-19 11:46:52 -0800349
Chris Craik117bdbc2015-02-05 10:12:38 -0800350 // ------------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800351 // ---------- GL state setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800352 // ------------------------------------
Chris Craik03188872015-02-02 18:39:33 -0800353 blend().setFactors(glop.blend.src, glop.blend.dst);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800354
John Reck975591a2016-01-22 16:28:07 -0800355 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800356
Chris Craik117bdbc2015-02-05 10:12:38 -0800357 // ------------------------------------
Chris Craik2ab95d72015-02-06 15:25:51 -0800358 // ---------- Actual drawing ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800359 // ------------------------------------
Chris Craikef250742015-02-25 17:16:16 -0800360 if (indices.bufferObject == meshState().getQuadListIBO()) {
Chris Craik2ab95d72015-02-06 15:25:51 -0800361 // Since the indexed quad list is of limited length, we loop over
362 // the glDrawXXX method while updating the vertex pointer
Chris Craik0519c812015-02-11 13:17:06 -0800363 GLsizei elementsCount = mesh.elementCount;
Chris Craikef250742015-02-25 17:16:16 -0800364 const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
Chris Craik2ab95d72015-02-06 15:25:51 -0800365 while (elementsCount > 0) {
Chris Craik9db58c02015-08-19 15:19:18 -0700366 GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
Chris Craik1b7db402016-02-24 18:25:32 -0800367 meshState().bindPositionVertexPointer(vertexData, vertices.stride);
Chris Craik53e51e42015-06-01 10:35:35 -0700368 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craik1b7db402016-02-24 18:25:32 -0800369 meshState().bindTexCoordsVertexPointer(
Chris Craikef250742015-02-25 17:16:16 -0800370 vertexData + kMeshTextureOffset, vertices.stride);
Chris Craikf27133d2015-02-19 09:51:53 -0800371 }
372
Chris Craik2ab95d72015-02-06 15:25:51 -0800373 glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
374 elementsCount -= drawCount;
Chris Craikef250742015-02-25 17:16:16 -0800375 vertexData += (drawCount / 6) * 4 * vertices.stride;
Chris Craik2ab95d72015-02-06 15:25:51 -0800376 }
Chris Craikef250742015-02-25 17:16:16 -0800377 } else if (indices.bufferObject || indices.indices) {
378 glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800379 } else {
Chris Craik0519c812015-02-11 13:17:06 -0800380 glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800381 }
Chris Craik117bdbc2015-02-05 10:12:38 -0800382
John Reck975591a2016-01-22 16:28:07 -0800383 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800384
Chris Craik2ab95d72015-02-06 15:25:51 -0800385 // -----------------------------------
386 // ---------- Mesh teardown ----------
387 // -----------------------------------
Chris Craik53e51e42015-06-01 10:35:35 -0700388 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800389 glDisableVertexAttribArray(alphaLocation);
390 }
Chris Craik53e51e42015-06-01 10:35:35 -0700391 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800392 glDisableVertexAttribArray(colorLocation);
Chris Craik117bdbc2015-02-05 10:12:38 -0800393 }
John Reck9372ac32016-01-19 11:46:52 -0800394
John Reck975591a2016-01-22 16:28:07 -0800395 GL_CHECKPOINT(MODERATE);
Chris Craik117bdbc2015-02-05 10:12:38 -0800396}
397
398void RenderState::dump() {
399 blend().dump();
400 meshState().dump();
401 scissor().dump();
402 stencil().dump();
Chris Craik6c15ffa2015-02-02 13:50:55 -0800403}
404
John Reck3b202512014-06-23 13:13:08 -0700405} /* namespace uirenderer */
406} /* namespace android */