blob: 0d567f7601f2f75720f731f2d3cc27f6dc712540 [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 */
sergeyv3e9999b2017-01-19 15:37:02 -080016#include "DeferredLayerUpdater.h"
Greg Daniel8cd3edf2017-01-09 14:15:41 -050017#include "GlLayer.h"
Greg Daniel45ec62b2017-01-04 14:27:00 -050018#include "VkLayer.h"
John Reck38e0c322015-11-10 12:19:17 -080019#include <GpuMemoryTracker.h>
Chris Craik96a5c4c2015-01-27 15:46:35 -080020#include "renderstate/RenderState.h"
John Reck3b202512014-06-23 13:13:08 -070021
John Reck443a7142014-09-04 17:40:05 -070022#include "renderthread/CanvasContext.h"
John Reck0e89e2b2014-10-31 14:49:06 -070023#include "renderthread/EglManager.h"
Chris Craik117bdbc2015-02-05 10:12:38 -080024#include "utils/GLUtils.h"
Chris Craik9db58c02015-08-19 15:19:18 -070025#include <algorithm>
26
John Reck3b202512014-06-23 13:13:08 -070027namespace android {
28namespace uirenderer {
29
John Reck0e89e2b2014-10-31 14:49:06 -070030RenderState::RenderState(renderthread::RenderThread& thread)
31 : mRenderThread(thread)
John Reck3b202512014-06-23 13:13:08 -070032 , mViewportWidth(0)
33 , mViewportHeight(0)
34 , mFramebuffer(0) {
John Reck0e89e2b2014-10-31 14:49:06 -070035 mThreadId = pthread_self();
John Reck3b202512014-06-23 13:13:08 -070036}
37
38RenderState::~RenderState() {
Chris Craik44eb2c02015-01-29 09:45:09 -080039 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080040 "State object lifecycle not managed correctly");
John Reck3b202512014-06-23 13:13:08 -070041}
42
43void RenderState::onGLContextCreated() {
Chris Craik44eb2c02015-01-29 09:45:09 -080044 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080045 "State object lifecycle not managed correctly");
Greg Daniel45ec62b2017-01-04 14:27:00 -050046 GpuMemoryTracker::onGpuContextCreated();
John Reck38e0c322015-11-10 12:19:17 -080047
Chris Craik44eb2c02015-01-29 09:45:09 -080048 mBlend = new Blend();
Chris Craik96a5c4c2015-01-27 15:46:35 -080049 mMeshState = new MeshState();
50 mScissor = new Scissor();
51 mStencil = new Stencil();
Chris Craik65fe5ee2015-01-26 18:06:29 -080052
Chris Craik96a5c4c2015-01-27 15:46:35 -080053 // This is delayed because the first access of Caches makes GL calls
Chris Craikff5c8e82015-01-30 09:46:18 -080054 if (!mCaches) {
55 mCaches = &Caches::createInstance(*this);
56 }
Chris Craik96a5c4c2015-01-27 15:46:35 -080057 mCaches->init();
John Reck3b202512014-06-23 13:13:08 -070058}
59
John Reck49bc4ac2015-01-29 12:53:38 -080060static void layerLostGlContext(Layer* layer) {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050061 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::OpenGL,
62 "layerLostGlContext on non GL layer");
63 static_cast<GlLayer*>(layer)->onGlContextLost();
John Reck49bc4ac2015-01-29 12:53:38 -080064}
65
Chris Craik1d477422014-08-26 17:30:15 -070066void RenderState::onGLContextDestroyed() {
Chris Craik9fded232015-11-11 16:42:34 -080067 mLayerPool.clear();
68
Chris Craik96a5c4c2015-01-27 15:46:35 -080069 // TODO: reset all cached state in state objects
John Reck49bc4ac2015-01-29 12:53:38 -080070 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
Chris Craik96a5c4c2015-01-27 15:46:35 -080071
Chris Craik44eb2c02015-01-29 09:45:09 -080072 mCaches->terminate();
73
74 delete mBlend;
75 mBlend = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -080076 delete mMeshState;
77 mMeshState = nullptr;
78 delete mScissor;
79 mScissor = nullptr;
80 delete mStencil;
81 mStencil = nullptr;
John Reck38e0c322015-11-10 12:19:17 -080082
Greg Daniel45ec62b2017-01-04 14:27:00 -050083 GpuMemoryTracker::onGpuContextDestroyed();
84}
85
86void RenderState::onVkContextCreated() {
87 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
88 "State object lifecycle not managed correctly");
89 GpuMemoryTracker::onGpuContextCreated();
90}
91
92static void layerDestroyedVkContext(Layer* layer) {
93 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::Vulkan,
94 "layerLostVkContext on non Vulkan layer");
95 static_cast<VkLayer*>(layer)->onVkContextDestroyed();
96}
97
98void RenderState::onVkContextDestroyed() {
99 mLayerPool.clear();
100 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerDestroyedVkContext);
101 GpuMemoryTracker::onGpuContextDestroyed();
102}
103
104GrContext* RenderState::getGrContext() const {
105 return mRenderThread.getGrContext();
Chris Craik1d477422014-08-26 17:30:15 -0700106}
107
Chris Craik9fded232015-11-11 16:42:34 -0800108void RenderState::flush(Caches::FlushMode mode) {
109 switch (mode) {
110 case Caches::FlushMode::Full:
111 // fall through
112 case Caches::FlushMode::Moderate:
113 // fall through
114 case Caches::FlushMode::Layers:
115 mLayerPool.clear();
116 break;
117 }
118 mCaches->flush(mode);
119}
120
John Reck3b202512014-06-23 13:13:08 -0700121void RenderState::setViewport(GLsizei width, GLsizei height) {
122 mViewportWidth = width;
123 mViewportHeight = height;
124 glViewport(0, 0, mViewportWidth, mViewportHeight);
125}
126
127
128void RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
129 *outWidth = mViewportWidth;
130 *outHeight = mViewportHeight;
131}
132
133void RenderState::bindFramebuffer(GLuint fbo) {
134 if (mFramebuffer != fbo) {
135 mFramebuffer = fbo;
136 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
137 }
138}
139
John Reck0b8d0672016-01-29 14:18:22 -0800140GLuint RenderState::createFramebuffer() {
Chris Craik818c9fb2015-10-23 14:33:42 -0700141 GLuint ret;
142 glGenFramebuffers(1, &ret);
143 return ret;
144}
145
146void RenderState::deleteFramebuffer(GLuint fbo) {
147 if (mFramebuffer == fbo) {
148 // GL defines that deleting the currently bound FBO rebinds FBO 0.
149 // Reflect this in our cached value.
150 mFramebuffer = 0;
151 }
152 glDeleteFramebuffers(1, &fbo);
153}
154
John Reck3b202512014-06-23 13:13:08 -0700155void RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
John Reck95cd24b2015-08-04 11:17:39 -0700156 if (mode == DrawGlInfo::kModeProcessNoContext) {
157 // If there's no context we don't need to interrupt as there's
158 // no gl state to save/restore
159 (*functor)(mode, info);
160 } else {
161 interruptForFunctorInvoke();
162 (*functor)(mode, info);
163 resumeFromFunctorInvoke();
164 }
John Reck3b202512014-06-23 13:13:08 -0700165}
166
167void RenderState::interruptForFunctorInvoke() {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800168 mCaches->setProgram(nullptr);
Chris Craik44eb2c02015-01-29 09:45:09 -0800169 mCaches->textureState().resetActiveTexture();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800170 meshState().unbindMeshBuffer();
171 meshState().unbindIndicesBuffer();
172 meshState().resetVertexPointers();
173 meshState().disableTexCoordsVertexArray();
John Reck3b202512014-06-23 13:13:08 -0700174 debugOverdraw(false, false);
Romain Guy253f2c22016-09-28 17:34:42 -0700175 // TODO: We need a way to know whether the functor is sRGB aware (b/32072673)
176 if (mCaches->extensions().hasSRGBWriteControl()) {
177 glDisable(GL_FRAMEBUFFER_SRGB_EXT);
178 }
John Reck3b202512014-06-23 13:13:08 -0700179}
180
181void RenderState::resumeFromFunctorInvoke() {
Romain Guy253f2c22016-09-28 17:34:42 -0700182 if (mCaches->extensions().hasSRGBWriteControl()) {
183 glEnable(GL_FRAMEBUFFER_SRGB_EXT);
184 }
185
John Reck3b202512014-06-23 13:13:08 -0700186 glViewport(0, 0, mViewportWidth, mViewportHeight);
187 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
188 debugOverdraw(false, false);
189
190 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
191
Chris Craik65fe5ee2015-01-26 18:06:29 -0800192 scissor().invalidate();
Chris Craik44eb2c02015-01-29 09:45:09 -0800193 blend().invalidate();
John Reck3b202512014-06-23 13:13:08 -0700194
Chris Craik44eb2c02015-01-29 09:45:09 -0800195 mCaches->textureState().activateTexture(0);
196 mCaches->textureState().resetBoundTextures();
John Reck3b202512014-06-23 13:13:08 -0700197}
198
199void RenderState::debugOverdraw(bool enable, bool clear) {
Chris Craik2507c342015-05-04 14:36:49 -0700200 if (Properties::debugOverdraw && mFramebuffer == 0) {
John Reck3b202512014-06-23 13:13:08 -0700201 if (clear) {
Chris Craik65fe5ee2015-01-26 18:06:29 -0800202 scissor().setEnabled(false);
Chris Craik96a5c4c2015-01-27 15:46:35 -0800203 stencil().clear();
John Reck3b202512014-06-23 13:13:08 -0700204 }
205 if (enable) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800206 stencil().enableDebugWrite();
John Reck3b202512014-06-23 13:13:08 -0700207 } else {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800208 stencil().disable();
John Reck3b202512014-06-23 13:13:08 -0700209 }
210 }
211}
212
sergeyv3e9999b2017-01-19 15:37:02 -0800213static void destroyLayerInUpdater(DeferredLayerUpdater* layerUpdater) {
214 layerUpdater->destroyLayer();
215}
216
217void RenderState::destroyLayersInUpdater() {
218 std::for_each(mActiveLayerUpdaters.begin(), mActiveLayerUpdaters.end(), destroyLayerInUpdater);
219}
220
John Reck0e89e2b2014-10-31 14:49:06 -0700221class DecStrongTask : public renderthread::RenderTask {
222public:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -0700223 explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
John Reck0e89e2b2014-10-31 14:49:06 -0700224
Chris Craikd41c4d82015-01-05 15:51:13 -0800225 virtual void run() override {
226 mObject->decStrong(nullptr);
227 mObject = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700228 delete this;
229 }
230
231private:
232 VirtualLightRefBase* mObject;
233};
234
235void RenderState::postDecStrong(VirtualLightRefBase* object) {
John Recka55b5d62016-01-14 15:09:10 -0800236 if (pthread_equal(mThreadId, pthread_self())) {
237 object->decStrong(nullptr);
238 } else {
239 mRenderThread.queue(new DecStrongTask(object));
240 }
John Reck0e89e2b2014-10-31 14:49:06 -0700241}
242
Chris Craik6c15ffa2015-02-02 13:50:55 -0800243///////////////////////////////////////////////////////////////////////////////
244// Render
245///////////////////////////////////////////////////////////////////////////////
246
Chris Craik12efe642015-09-28 15:52:12 -0700247void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800248 const Glop::Mesh& mesh = glop.mesh;
Chris Craikef250742015-02-25 17:16:16 -0800249 const Glop::Mesh::Vertices& vertices = mesh.vertices;
250 const Glop::Mesh::Indices& indices = mesh.indices;
Chris Craik0519c8102015-02-11 13:17:06 -0800251 const Glop::Fill& fill = glop.fill;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800252
John Reck975591a2016-01-22 16:28:07 -0800253 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800254
Chris Craik0519c8102015-02-11 13:17:06 -0800255 // ---------------------------------------------
256 // ---------- Program + uniform setup ----------
257 // ---------------------------------------------
258 mCaches->setProgram(fill.program);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800259
Chris Craik0519c8102015-02-11 13:17:06 -0800260 if (fill.colorEnabled) {
261 fill.program->setColor(fill.color);
262 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800263
Chris Craik12efe642015-09-28 15:52:12 -0700264 fill.program->set(orthoMatrix,
Chris Craik6c15ffa2015-02-02 13:50:55 -0800265 glop.transform.modelView,
Chris Craik53e51e42015-06-01 10:35:35 -0700266 glop.transform.meshTransform(),
267 glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800268
Chris Craik0519c8102015-02-11 13:17:06 -0800269 // Color filter uniforms
Chris Craikb9ce116d2015-08-20 15:14:06 -0700270 if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
Chris Craikef250742015-02-25 17:16:16 -0800271 const FloatColor& color = fill.filter.color;
Chris Craik117bdbc2015-02-05 10:12:38 -0800272 glUniform4f(mCaches->program().getUniform("colorBlend"),
273 color.r, color.g, color.b, color.a);
Chris Craikb9ce116d2015-08-20 15:14:06 -0700274 } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
Chris Craik117bdbc2015-02-05 10:12:38 -0800275 glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
Chris Craikef250742015-02-25 17:16:16 -0800276 fill.filter.matrix.matrix);
Chris Craik117bdbc2015-02-05 10:12:38 -0800277 glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
Chris Craikef250742015-02-25 17:16:16 -0800278 fill.filter.matrix.vector);
Chris Craik117bdbc2015-02-05 10:12:38 -0800279 }
280
Chris Craik0519c8102015-02-11 13:17:06 -0800281 // Round rect clipping uniforms
282 if (glop.roundRectClipState) {
283 // TODO: avoid query, and cache values (or RRCS ptr) in program
284 const RoundRectClipState* state = glop.roundRectClipState;
285 const Rect& innerRect = state->innerRect;
286 glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
287 innerRect.left, innerRect.top,
288 innerRect.right, innerRect.bottom);
289 glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
290 1, GL_FALSE, &state->matrix.data[0]);
291
292 // add half pixel to round out integer rect space to cover pixel centers
293 float roundedOutRadius = state->radius + 0.5f;
294 glUniform1f(fill.program->getUniform("roundRectRadius"),
295 roundedOutRadius);
296 }
Chris Craikef250742015-02-25 17:16:16 -0800297
John Reck975591a2016-01-22 16:28:07 -0800298 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800299
Chris Craik117bdbc2015-02-05 10:12:38 -0800300 // --------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800301 // ---------- Mesh setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800302 // --------------------------------
303 // vertices
Chris Craik1b7db402016-02-24 18:25:32 -0800304 meshState().bindMeshBuffer(vertices.bufferObject);
305 meshState().bindPositionVertexPointer(vertices.position, vertices.stride);
Chris Craik117bdbc2015-02-05 10:12:38 -0800306
307 // indices
Chris Craik1b7db402016-02-24 18:25:32 -0800308 meshState().bindIndicesBuffer(indices.bufferObject);
Chris Craik117bdbc2015-02-05 10:12:38 -0800309
Chris Craik138c21f2016-04-28 16:59:42 -0700310 // texture
311 if (fill.texture.texture != nullptr) {
Chris Craik26bf3422015-02-26 16:28:17 -0800312 const Glop::Fill::TextureData& texture = fill.texture;
313 // texture always takes slot 0, shader samplers increment from there
Chris Craik0519c8102015-02-11 13:17:06 -0800314 mCaches->textureState().activateTexture(0);
315
sergeyv2a38c422016-10-25 15:21:50 -0700316 mCaches->textureState().bindTexture(texture.texture->target(), texture.texture->id());
Chris Craik26bf3422015-02-26 16:28:17 -0800317 if (texture.clamp != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700318 texture.texture->setWrap(texture.clamp, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800319 }
Chris Craik26bf3422015-02-26 16:28:17 -0800320 if (texture.filter != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700321 texture.texture->setFilter(texture.filter, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800322 }
Chris Craik0519c8102015-02-11 13:17:06 -0800323
Chris Craik26bf3422015-02-26 16:28:17 -0800324 if (texture.textureTransform) {
325 glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
326 GL_FALSE, &texture.textureTransform->data[0]);
327 }
Chris Craik138c21f2016-04-28 16:59:42 -0700328 }
329
330 // vertex attributes (tex coord, color, alpha)
331 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
332 meshState().enableTexCoordsVertexArray();
333 meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800334 } else {
335 meshState().disableTexCoordsVertexArray();
336 }
Chris Craikef250742015-02-25 17:16:16 -0800337 int colorLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700338 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800339 colorLocation = fill.program->getAttrib("colors");
340 glEnableVertexAttribArray(colorLocation);
341 glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800342 }
Chris Craikef250742015-02-25 17:16:16 -0800343 int alphaLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700344 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800345 // NOTE: alpha vertex position is computed assuming no VBO
346 const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
347 alphaLocation = fill.program->getAttrib("vtxAlpha");
348 glEnableVertexAttribArray(alphaLocation);
349 glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800350 }
Chris Craik922d3a72015-02-13 17:47:21 -0800351 // Shader uniforms
Romain Guy253f2c22016-09-28 17:34:42 -0700352 SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
Chris Craik922d3a72015-02-13 17:47:21 -0800353
John Reck975591a2016-01-22 16:28:07 -0800354 GL_CHECKPOINT(MODERATE);
Dohyun Leec5a3efd2016-01-21 13:46:21 +0900355 Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
356 fill.skiaShaderData.bitmapData.bitmapTexture : nullptr;
357 const AutoTexture autoCleanup(texture);
John Reck9372ac32016-01-19 11:46:52 -0800358
Chris Craik117bdbc2015-02-05 10:12:38 -0800359 // ------------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800360 // ---------- GL state setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800361 // ------------------------------------
Chris Craik03188872015-02-02 18:39:33 -0800362 blend().setFactors(glop.blend.src, glop.blend.dst);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800363
John Reck975591a2016-01-22 16:28:07 -0800364 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800365
Chris Craik117bdbc2015-02-05 10:12:38 -0800366 // ------------------------------------
Chris Craik2ab95d72015-02-06 15:25:51 -0800367 // ---------- Actual drawing ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800368 // ------------------------------------
Chris Craikef250742015-02-25 17:16:16 -0800369 if (indices.bufferObject == meshState().getQuadListIBO()) {
Chris Craik2ab95d72015-02-06 15:25:51 -0800370 // Since the indexed quad list is of limited length, we loop over
371 // the glDrawXXX method while updating the vertex pointer
Chris Craik0519c8102015-02-11 13:17:06 -0800372 GLsizei elementsCount = mesh.elementCount;
Chris Craikef250742015-02-25 17:16:16 -0800373 const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
Chris Craik2ab95d72015-02-06 15:25:51 -0800374 while (elementsCount > 0) {
Chris Craik9db58c02015-08-19 15:19:18 -0700375 GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
Chris Craik1b7db402016-02-24 18:25:32 -0800376 meshState().bindPositionVertexPointer(vertexData, vertices.stride);
Chris Craik53e51e42015-06-01 10:35:35 -0700377 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craik1b7db402016-02-24 18:25:32 -0800378 meshState().bindTexCoordsVertexPointer(
Chris Craikef250742015-02-25 17:16:16 -0800379 vertexData + kMeshTextureOffset, vertices.stride);
Chris Craikf27133d2015-02-19 09:51:53 -0800380 }
381
Chris Craik2ab95d72015-02-06 15:25:51 -0800382 glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
383 elementsCount -= drawCount;
Chris Craikef250742015-02-25 17:16:16 -0800384 vertexData += (drawCount / 6) * 4 * vertices.stride;
Chris Craik2ab95d72015-02-06 15:25:51 -0800385 }
Chris Craikef250742015-02-25 17:16:16 -0800386 } else if (indices.bufferObject || indices.indices) {
387 glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800388 } else {
Chris Craik0519c8102015-02-11 13:17:06 -0800389 glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800390 }
Chris Craik117bdbc2015-02-05 10:12:38 -0800391
John Reck975591a2016-01-22 16:28:07 -0800392 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800393
Chris Craik2ab95d72015-02-06 15:25:51 -0800394 // -----------------------------------
395 // ---------- Mesh teardown ----------
396 // -----------------------------------
Chris Craik53e51e42015-06-01 10:35:35 -0700397 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800398 glDisableVertexAttribArray(alphaLocation);
399 }
Chris Craik53e51e42015-06-01 10:35:35 -0700400 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800401 glDisableVertexAttribArray(colorLocation);
Chris Craik117bdbc2015-02-05 10:12:38 -0800402 }
John Reck9372ac32016-01-19 11:46:52 -0800403
John Reck975591a2016-01-22 16:28:07 -0800404 GL_CHECKPOINT(MODERATE);
Chris Craik117bdbc2015-02-05 10:12:38 -0800405}
406
407void RenderState::dump() {
408 blend().dump();
409 meshState().dump();
410 scissor().dump();
411 stencil().dump();
Chris Craik6c15ffa2015-02-02 13:50:55 -0800412}
413
John Reck3b202512014-06-23 13:13:08 -0700414} /* namespace uirenderer */
415} /* namespace android */