blob: 17ee390c90bdfac707231183497a4f7b1d95a423 [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 */
Greg Daniel8cd3edf2017-01-09 14:15:41 -050016#include "GlLayer.h"
Greg Daniel45ec62b2017-01-04 14:27:00 -050017#include "VkLayer.h"
John Reck38e0c322015-11-10 12:19:17 -080018#include <GpuMemoryTracker.h>
Chris Craik96a5c4c2015-01-27 15:46:35 -080019#include "renderstate/RenderState.h"
John Reck3b202512014-06-23 13:13:08 -070020
John Reck443a7142014-09-04 17:40:05 -070021#include "renderthread/CanvasContext.h"
John Reck0e89e2b2014-10-31 14:49:06 -070022#include "renderthread/EglManager.h"
Chris Craik117bdbc2015-02-05 10:12:38 -080023#include "utils/GLUtils.h"
Chris Craik9db58c02015-08-19 15:19:18 -070024#include <algorithm>
25
John Reck3b202512014-06-23 13:13:08 -070026namespace android {
27namespace uirenderer {
28
John Reck0e89e2b2014-10-31 14:49:06 -070029RenderState::RenderState(renderthread::RenderThread& thread)
30 : mRenderThread(thread)
John Reck3b202512014-06-23 13:13:08 -070031 , mViewportWidth(0)
32 , mViewportHeight(0)
33 , mFramebuffer(0) {
John Reck0e89e2b2014-10-31 14:49:06 -070034 mThreadId = pthread_self();
John Reck3b202512014-06-23 13:13:08 -070035}
36
37RenderState::~RenderState() {
Chris Craik44eb2c02015-01-29 09:45:09 -080038 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080039 "State object lifecycle not managed correctly");
John Reck3b202512014-06-23 13:13:08 -070040}
41
42void RenderState::onGLContextCreated() {
Chris Craik44eb2c02015-01-29 09:45:09 -080043 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080044 "State object lifecycle not managed correctly");
Greg Daniel45ec62b2017-01-04 14:27:00 -050045 GpuMemoryTracker::onGpuContextCreated();
John Reck38e0c322015-11-10 12:19:17 -080046
Chris Craik44eb2c02015-01-29 09:45:09 -080047 mBlend = new Blend();
Chris Craik96a5c4c2015-01-27 15:46:35 -080048 mMeshState = new MeshState();
49 mScissor = new Scissor();
50 mStencil = new Stencil();
Chris Craik65fe5ee2015-01-26 18:06:29 -080051
Chris Craik96a5c4c2015-01-27 15:46:35 -080052 // This is delayed because the first access of Caches makes GL calls
Chris Craikff5c8e82015-01-30 09:46:18 -080053 if (!mCaches) {
54 mCaches = &Caches::createInstance(*this);
55 }
Chris Craik96a5c4c2015-01-27 15:46:35 -080056 mCaches->init();
John Reck3b202512014-06-23 13:13:08 -070057}
58
John Reck49bc4ac2015-01-29 12:53:38 -080059static void layerLostGlContext(Layer* layer) {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050060 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::OpenGL,
61 "layerLostGlContext on non GL layer");
62 static_cast<GlLayer*>(layer)->onGlContextLost();
John Reck49bc4ac2015-01-29 12:53:38 -080063}
64
Chris Craik1d477422014-08-26 17:30:15 -070065void RenderState::onGLContextDestroyed() {
Chris Craik9fded232015-11-11 16:42:34 -080066 mLayerPool.clear();
67
Chris Craik96a5c4c2015-01-27 15:46:35 -080068 // TODO: reset all cached state in state objects
John Reck49bc4ac2015-01-29 12:53:38 -080069 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
Chris Craik96a5c4c2015-01-27 15:46:35 -080070
Chris Craik44eb2c02015-01-29 09:45:09 -080071 mCaches->terminate();
72
73 delete mBlend;
74 mBlend = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -080075 delete mMeshState;
76 mMeshState = nullptr;
77 delete mScissor;
78 mScissor = nullptr;
79 delete mStencil;
80 mStencil = nullptr;
John Reck38e0c322015-11-10 12:19:17 -080081
Greg Daniel45ec62b2017-01-04 14:27:00 -050082 GpuMemoryTracker::onGpuContextDestroyed();
83}
84
85void RenderState::onVkContextCreated() {
86 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
87 "State object lifecycle not managed correctly");
88 GpuMemoryTracker::onGpuContextCreated();
89}
90
91static void layerDestroyedVkContext(Layer* layer) {
92 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::Vulkan,
93 "layerLostVkContext on non Vulkan layer");
94 static_cast<VkLayer*>(layer)->onVkContextDestroyed();
95}
96
97void RenderState::onVkContextDestroyed() {
98 mLayerPool.clear();
99 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerDestroyedVkContext);
100 GpuMemoryTracker::onGpuContextDestroyed();
101}
102
103GrContext* RenderState::getGrContext() const {
104 return mRenderThread.getGrContext();
Chris Craik1d477422014-08-26 17:30:15 -0700105}
106
Chris Craik9fded232015-11-11 16:42:34 -0800107void RenderState::flush(Caches::FlushMode mode) {
108 switch (mode) {
109 case Caches::FlushMode::Full:
110 // fall through
111 case Caches::FlushMode::Moderate:
112 // fall through
113 case Caches::FlushMode::Layers:
114 mLayerPool.clear();
115 break;
116 }
117 mCaches->flush(mode);
118}
119
John Reck3b202512014-06-23 13:13:08 -0700120void RenderState::setViewport(GLsizei width, GLsizei height) {
121 mViewportWidth = width;
122 mViewportHeight = height;
123 glViewport(0, 0, mViewportWidth, mViewportHeight);
124}
125
126
127void RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
128 *outWidth = mViewportWidth;
129 *outHeight = mViewportHeight;
130}
131
132void RenderState::bindFramebuffer(GLuint fbo) {
133 if (mFramebuffer != fbo) {
134 mFramebuffer = fbo;
135 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
136 }
137}
138
John Reck0b8d0672016-01-29 14:18:22 -0800139GLuint RenderState::createFramebuffer() {
Chris Craik818c9fb2015-10-23 14:33:42 -0700140 GLuint ret;
141 glGenFramebuffers(1, &ret);
142 return ret;
143}
144
145void RenderState::deleteFramebuffer(GLuint fbo) {
146 if (mFramebuffer == fbo) {
147 // GL defines that deleting the currently bound FBO rebinds FBO 0.
148 // Reflect this in our cached value.
149 mFramebuffer = 0;
150 }
151 glDeleteFramebuffers(1, &fbo);
152}
153
John Reck3b202512014-06-23 13:13:08 -0700154void RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
John Reck95cd24b2015-08-04 11:17:39 -0700155 if (mode == DrawGlInfo::kModeProcessNoContext) {
156 // If there's no context we don't need to interrupt as there's
157 // no gl state to save/restore
158 (*functor)(mode, info);
159 } else {
160 interruptForFunctorInvoke();
161 (*functor)(mode, info);
162 resumeFromFunctorInvoke();
163 }
John Reck3b202512014-06-23 13:13:08 -0700164}
165
166void RenderState::interruptForFunctorInvoke() {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800167 mCaches->setProgram(nullptr);
Chris Craik44eb2c02015-01-29 09:45:09 -0800168 mCaches->textureState().resetActiveTexture();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800169 meshState().unbindMeshBuffer();
170 meshState().unbindIndicesBuffer();
171 meshState().resetVertexPointers();
172 meshState().disableTexCoordsVertexArray();
John Reck3b202512014-06-23 13:13:08 -0700173 debugOverdraw(false, false);
Romain Guy253f2c22016-09-28 17:34:42 -0700174 // TODO: We need a way to know whether the functor is sRGB aware (b/32072673)
175 if (mCaches->extensions().hasSRGBWriteControl()) {
176 glDisable(GL_FRAMEBUFFER_SRGB_EXT);
177 }
John Reck3b202512014-06-23 13:13:08 -0700178}
179
180void RenderState::resumeFromFunctorInvoke() {
Romain Guy253f2c22016-09-28 17:34:42 -0700181 if (mCaches->extensions().hasSRGBWriteControl()) {
182 glEnable(GL_FRAMEBUFFER_SRGB_EXT);
183 }
184
John Reck3b202512014-06-23 13:13:08 -0700185 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:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -0700214 explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
John Reck0e89e2b2014-10-31 14:49:06 -0700215
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 Craik0519c8102015-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 Craik0519c8102015-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 Craik0519c8102015-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 Craik0519c8102015-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 Craik0519c8102015-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 Craik0519c8102015-02-11 13:17:06 -0800305 mCaches->textureState().activateTexture(0);
306
sergeyv2a38c422016-10-25 15:21:50 -0700307 mCaches->textureState().bindTexture(texture.texture->target(), texture.texture->id());
Chris Craik26bf3422015-02-26 16:28:17 -0800308 if (texture.clamp != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700309 texture.texture->setWrap(texture.clamp, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800310 }
Chris Craik26bf3422015-02-26 16:28:17 -0800311 if (texture.filter != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700312 texture.texture->setFilter(texture.filter, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800313 }
Chris Craik0519c8102015-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
Romain Guy253f2c22016-09-28 17:34:42 -0700343 SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
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 Craik0519c8102015-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 Craik0519c8102015-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 */