blob: 8bce990129de11d096d58e936544cbdd0fa3528c [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
sergeyvc3f13162017-02-06 11:45:14 -080083 destroyLayersInUpdater();
Greg Daniel45ec62b2017-01-04 14:27:00 -050084 GpuMemoryTracker::onGpuContextDestroyed();
85}
86
87void RenderState::onVkContextCreated() {
88 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
89 "State object lifecycle not managed correctly");
90 GpuMemoryTracker::onGpuContextCreated();
91}
92
93static void layerDestroyedVkContext(Layer* layer) {
94 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::Vulkan,
95 "layerLostVkContext on non Vulkan layer");
96 static_cast<VkLayer*>(layer)->onVkContextDestroyed();
97}
98
99void RenderState::onVkContextDestroyed() {
100 mLayerPool.clear();
101 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerDestroyedVkContext);
102 GpuMemoryTracker::onGpuContextDestroyed();
103}
104
105GrContext* RenderState::getGrContext() const {
106 return mRenderThread.getGrContext();
Chris Craik1d477422014-08-26 17:30:15 -0700107}
108
Chris Craik9fded232015-11-11 16:42:34 -0800109void RenderState::flush(Caches::FlushMode mode) {
110 switch (mode) {
111 case Caches::FlushMode::Full:
112 // fall through
113 case Caches::FlushMode::Moderate:
114 // fall through
115 case Caches::FlushMode::Layers:
116 mLayerPool.clear();
117 break;
118 }
119 mCaches->flush(mode);
120}
121
John Reck3b202512014-06-23 13:13:08 -0700122void RenderState::setViewport(GLsizei width, GLsizei height) {
123 mViewportWidth = width;
124 mViewportHeight = height;
125 glViewport(0, 0, mViewportWidth, mViewportHeight);
126}
127
128
129void RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
130 *outWidth = mViewportWidth;
131 *outHeight = mViewportHeight;
132}
133
134void RenderState::bindFramebuffer(GLuint fbo) {
135 if (mFramebuffer != fbo) {
136 mFramebuffer = fbo;
137 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
138 }
139}
140
John Reck0b8d0672016-01-29 14:18:22 -0800141GLuint RenderState::createFramebuffer() {
Chris Craik818c9fb2015-10-23 14:33:42 -0700142 GLuint ret;
143 glGenFramebuffers(1, &ret);
144 return ret;
145}
146
147void RenderState::deleteFramebuffer(GLuint fbo) {
148 if (mFramebuffer == fbo) {
149 // GL defines that deleting the currently bound FBO rebinds FBO 0.
150 // Reflect this in our cached value.
151 mFramebuffer = 0;
152 }
153 glDeleteFramebuffers(1, &fbo);
154}
155
John Reck3b202512014-06-23 13:13:08 -0700156void RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
John Reck95cd24b2015-08-04 11:17:39 -0700157 if (mode == DrawGlInfo::kModeProcessNoContext) {
158 // If there's no context we don't need to interrupt as there's
159 // no gl state to save/restore
160 (*functor)(mode, info);
161 } else {
162 interruptForFunctorInvoke();
163 (*functor)(mode, info);
164 resumeFromFunctorInvoke();
165 }
John Reck3b202512014-06-23 13:13:08 -0700166}
167
168void RenderState::interruptForFunctorInvoke() {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800169 mCaches->setProgram(nullptr);
Chris Craik44eb2c02015-01-29 09:45:09 -0800170 mCaches->textureState().resetActiveTexture();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800171 meshState().unbindMeshBuffer();
172 meshState().unbindIndicesBuffer();
173 meshState().resetVertexPointers();
174 meshState().disableTexCoordsVertexArray();
John Reck3b202512014-06-23 13:13:08 -0700175 debugOverdraw(false, false);
Romain Guy253f2c22016-09-28 17:34:42 -0700176 // TODO: We need a way to know whether the functor is sRGB aware (b/32072673)
Romain Guyefb4b062017-02-27 11:00:04 -0800177 if (mCaches->extensions().hasLinearBlending() &&
178 mCaches->extensions().hasSRGBWriteControl()) {
Romain Guy253f2c22016-09-28 17:34:42 -0700179 glDisable(GL_FRAMEBUFFER_SRGB_EXT);
180 }
John Reck3b202512014-06-23 13:13:08 -0700181}
182
183void RenderState::resumeFromFunctorInvoke() {
Romain Guyefb4b062017-02-27 11:00:04 -0800184 if (mCaches->extensions().hasLinearBlending() &&
185 mCaches->extensions().hasSRGBWriteControl()) {
Romain Guy253f2c22016-09-28 17:34:42 -0700186 glEnable(GL_FRAMEBUFFER_SRGB_EXT);
187 }
188
John Reck3b202512014-06-23 13:13:08 -0700189 glViewport(0, 0, mViewportWidth, mViewportHeight);
190 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
191 debugOverdraw(false, false);
192
193 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
194
Chris Craik65fe5ee2015-01-26 18:06:29 -0800195 scissor().invalidate();
Chris Craik44eb2c02015-01-29 09:45:09 -0800196 blend().invalidate();
John Reck3b202512014-06-23 13:13:08 -0700197
Chris Craik44eb2c02015-01-29 09:45:09 -0800198 mCaches->textureState().activateTexture(0);
199 mCaches->textureState().resetBoundTextures();
John Reck3b202512014-06-23 13:13:08 -0700200}
201
202void RenderState::debugOverdraw(bool enable, bool clear) {
Chris Craik2507c342015-05-04 14:36:49 -0700203 if (Properties::debugOverdraw && mFramebuffer == 0) {
John Reck3b202512014-06-23 13:13:08 -0700204 if (clear) {
Chris Craik65fe5ee2015-01-26 18:06:29 -0800205 scissor().setEnabled(false);
Chris Craik96a5c4c2015-01-27 15:46:35 -0800206 stencil().clear();
John Reck3b202512014-06-23 13:13:08 -0700207 }
208 if (enable) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800209 stencil().enableDebugWrite();
John Reck3b202512014-06-23 13:13:08 -0700210 } else {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800211 stencil().disable();
John Reck3b202512014-06-23 13:13:08 -0700212 }
213 }
214}
215
sergeyv3e9999b2017-01-19 15:37:02 -0800216static void destroyLayerInUpdater(DeferredLayerUpdater* layerUpdater) {
217 layerUpdater->destroyLayer();
218}
219
220void RenderState::destroyLayersInUpdater() {
221 std::for_each(mActiveLayerUpdaters.begin(), mActiveLayerUpdaters.end(), destroyLayerInUpdater);
222}
223
John Reck0e89e2b2014-10-31 14:49:06 -0700224class DecStrongTask : public renderthread::RenderTask {
225public:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -0700226 explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
John Reck0e89e2b2014-10-31 14:49:06 -0700227
Chris Craikd41c4d82015-01-05 15:51:13 -0800228 virtual void run() override {
229 mObject->decStrong(nullptr);
230 mObject = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700231 delete this;
232 }
233
234private:
235 VirtualLightRefBase* mObject;
236};
237
238void RenderState::postDecStrong(VirtualLightRefBase* object) {
John Recka55b5d62016-01-14 15:09:10 -0800239 if (pthread_equal(mThreadId, pthread_self())) {
240 object->decStrong(nullptr);
241 } else {
242 mRenderThread.queue(new DecStrongTask(object));
243 }
John Reck0e89e2b2014-10-31 14:49:06 -0700244}
245
Chris Craik6c15ffa2015-02-02 13:50:55 -0800246///////////////////////////////////////////////////////////////////////////////
247// Render
248///////////////////////////////////////////////////////////////////////////////
249
Chris Craik12efe642015-09-28 15:52:12 -0700250void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800251 const Glop::Mesh& mesh = glop.mesh;
Chris Craikef250742015-02-25 17:16:16 -0800252 const Glop::Mesh::Vertices& vertices = mesh.vertices;
253 const Glop::Mesh::Indices& indices = mesh.indices;
Chris Craik0519c8102015-02-11 13:17:06 -0800254 const Glop::Fill& fill = glop.fill;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800255
John Reck975591a2016-01-22 16:28:07 -0800256 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800257
Chris Craik0519c8102015-02-11 13:17:06 -0800258 // ---------------------------------------------
259 // ---------- Program + uniform setup ----------
260 // ---------------------------------------------
261 mCaches->setProgram(fill.program);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800262
Chris Craik0519c8102015-02-11 13:17:06 -0800263 if (fill.colorEnabled) {
264 fill.program->setColor(fill.color);
265 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800266
Chris Craik12efe642015-09-28 15:52:12 -0700267 fill.program->set(orthoMatrix,
Chris Craik6c15ffa2015-02-02 13:50:55 -0800268 glop.transform.modelView,
Chris Craik53e51e42015-06-01 10:35:35 -0700269 glop.transform.meshTransform(),
270 glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800271
Chris Craik0519c8102015-02-11 13:17:06 -0800272 // Color filter uniforms
Chris Craikb9ce116d2015-08-20 15:14:06 -0700273 if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
Chris Craikef250742015-02-25 17:16:16 -0800274 const FloatColor& color = fill.filter.color;
Chris Craik117bdbc2015-02-05 10:12:38 -0800275 glUniform4f(mCaches->program().getUniform("colorBlend"),
276 color.r, color.g, color.b, color.a);
Chris Craikb9ce116d2015-08-20 15:14:06 -0700277 } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
Chris Craik117bdbc2015-02-05 10:12:38 -0800278 glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
Chris Craikef250742015-02-25 17:16:16 -0800279 fill.filter.matrix.matrix);
Chris Craik117bdbc2015-02-05 10:12:38 -0800280 glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
Chris Craikef250742015-02-25 17:16:16 -0800281 fill.filter.matrix.vector);
Chris Craik117bdbc2015-02-05 10:12:38 -0800282 }
283
Chris Craik0519c8102015-02-11 13:17:06 -0800284 // Round rect clipping uniforms
285 if (glop.roundRectClipState) {
286 // TODO: avoid query, and cache values (or RRCS ptr) in program
287 const RoundRectClipState* state = glop.roundRectClipState;
288 const Rect& innerRect = state->innerRect;
289 glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
290 innerRect.left, innerRect.top,
291 innerRect.right, innerRect.bottom);
292 glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
293 1, GL_FALSE, &state->matrix.data[0]);
294
295 // add half pixel to round out integer rect space to cover pixel centers
296 float roundedOutRadius = state->radius + 0.5f;
297 glUniform1f(fill.program->getUniform("roundRectRadius"),
298 roundedOutRadius);
299 }
Chris Craikef250742015-02-25 17:16:16 -0800300
John Reck975591a2016-01-22 16:28:07 -0800301 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800302
Chris Craik117bdbc2015-02-05 10:12:38 -0800303 // --------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800304 // ---------- Mesh setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800305 // --------------------------------
306 // vertices
Chris Craik1b7db402016-02-24 18:25:32 -0800307 meshState().bindMeshBuffer(vertices.bufferObject);
308 meshState().bindPositionVertexPointer(vertices.position, vertices.stride);
Chris Craik117bdbc2015-02-05 10:12:38 -0800309
310 // indices
Chris Craik1b7db402016-02-24 18:25:32 -0800311 meshState().bindIndicesBuffer(indices.bufferObject);
Chris Craik117bdbc2015-02-05 10:12:38 -0800312
Chris Craik138c21f2016-04-28 16:59:42 -0700313 // texture
314 if (fill.texture.texture != nullptr) {
Chris Craik26bf3422015-02-26 16:28:17 -0800315 const Glop::Fill::TextureData& texture = fill.texture;
316 // texture always takes slot 0, shader samplers increment from there
Chris Craik0519c8102015-02-11 13:17:06 -0800317 mCaches->textureState().activateTexture(0);
318
sergeyv2a38c422016-10-25 15:21:50 -0700319 mCaches->textureState().bindTexture(texture.texture->target(), texture.texture->id());
Chris Craik26bf3422015-02-26 16:28:17 -0800320 if (texture.clamp != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700321 texture.texture->setWrap(texture.clamp, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800322 }
Chris Craik26bf3422015-02-26 16:28:17 -0800323 if (texture.filter != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700324 texture.texture->setFilter(texture.filter, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800325 }
Chris Craik0519c8102015-02-11 13:17:06 -0800326
Chris Craik26bf3422015-02-26 16:28:17 -0800327 if (texture.textureTransform) {
328 glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
329 GL_FALSE, &texture.textureTransform->data[0]);
330 }
Chris Craik138c21f2016-04-28 16:59:42 -0700331 }
332
333 // vertex attributes (tex coord, color, alpha)
334 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
335 meshState().enableTexCoordsVertexArray();
336 meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800337 } else {
338 meshState().disableTexCoordsVertexArray();
339 }
Chris Craikef250742015-02-25 17:16:16 -0800340 int colorLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700341 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800342 colorLocation = fill.program->getAttrib("colors");
343 glEnableVertexAttribArray(colorLocation);
344 glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800345 }
Chris Craikef250742015-02-25 17:16:16 -0800346 int alphaLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700347 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800348 // NOTE: alpha vertex position is computed assuming no VBO
349 const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
350 alphaLocation = fill.program->getAttrib("vtxAlpha");
351 glEnableVertexAttribArray(alphaLocation);
352 glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800353 }
Chris Craik922d3a72015-02-13 17:47:21 -0800354 // Shader uniforms
Romain Guy253f2c22016-09-28 17:34:42 -0700355 SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
Chris Craik922d3a72015-02-13 17:47:21 -0800356
John Reck975591a2016-01-22 16:28:07 -0800357 GL_CHECKPOINT(MODERATE);
Dohyun Leec5a3efd2016-01-21 13:46:21 +0900358 Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
359 fill.skiaShaderData.bitmapData.bitmapTexture : nullptr;
360 const AutoTexture autoCleanup(texture);
John Reck9372ac32016-01-19 11:46:52 -0800361
Chris Craik117bdbc2015-02-05 10:12:38 -0800362 // ------------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800363 // ---------- GL state setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800364 // ------------------------------------
Chris Craik03188872015-02-02 18:39:33 -0800365 blend().setFactors(glop.blend.src, glop.blend.dst);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800366
John Reck975591a2016-01-22 16:28:07 -0800367 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800368
Chris Craik117bdbc2015-02-05 10:12:38 -0800369 // ------------------------------------
Chris Craik2ab95d72015-02-06 15:25:51 -0800370 // ---------- Actual drawing ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800371 // ------------------------------------
Chris Craikef250742015-02-25 17:16:16 -0800372 if (indices.bufferObject == meshState().getQuadListIBO()) {
Chris Craik2ab95d72015-02-06 15:25:51 -0800373 // Since the indexed quad list is of limited length, we loop over
374 // the glDrawXXX method while updating the vertex pointer
Chris Craik0519c8102015-02-11 13:17:06 -0800375 GLsizei elementsCount = mesh.elementCount;
Chris Craikef250742015-02-25 17:16:16 -0800376 const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
Chris Craik2ab95d72015-02-06 15:25:51 -0800377 while (elementsCount > 0) {
Chris Craik9db58c02015-08-19 15:19:18 -0700378 GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
Chris Craik1b7db402016-02-24 18:25:32 -0800379 meshState().bindPositionVertexPointer(vertexData, vertices.stride);
Chris Craik53e51e42015-06-01 10:35:35 -0700380 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craik1b7db402016-02-24 18:25:32 -0800381 meshState().bindTexCoordsVertexPointer(
Chris Craikef250742015-02-25 17:16:16 -0800382 vertexData + kMeshTextureOffset, vertices.stride);
Chris Craikf27133d2015-02-19 09:51:53 -0800383 }
384
Chris Craik2ab95d72015-02-06 15:25:51 -0800385 glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
386 elementsCount -= drawCount;
Chris Craikef250742015-02-25 17:16:16 -0800387 vertexData += (drawCount / 6) * 4 * vertices.stride;
Chris Craik2ab95d72015-02-06 15:25:51 -0800388 }
Chris Craikef250742015-02-25 17:16:16 -0800389 } else if (indices.bufferObject || indices.indices) {
390 glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800391 } else {
Chris Craik0519c8102015-02-11 13:17:06 -0800392 glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800393 }
Chris Craik117bdbc2015-02-05 10:12:38 -0800394
John Reck975591a2016-01-22 16:28:07 -0800395 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800396
Chris Craik2ab95d72015-02-06 15:25:51 -0800397 // -----------------------------------
398 // ---------- Mesh teardown ----------
399 // -----------------------------------
Chris Craik53e51e42015-06-01 10:35:35 -0700400 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800401 glDisableVertexAttribArray(alphaLocation);
402 }
Chris Craik53e51e42015-06-01 10:35:35 -0700403 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800404 glDisableVertexAttribArray(colorLocation);
Chris Craik117bdbc2015-02-05 10:12:38 -0800405 }
John Reck9372ac32016-01-19 11:46:52 -0800406
John Reck975591a2016-01-22 16:28:07 -0800407 GL_CHECKPOINT(MODERATE);
Chris Craik117bdbc2015-02-05 10:12:38 -0800408}
409
410void RenderState::dump() {
411 blend().dump();
412 meshState().dump();
413 scissor().dump();
414 stencil().dump();
Chris Craik6c15ffa2015-02-02 13:50:55 -0800415}
416
John Reck3b202512014-06-23 13:13:08 -0700417} /* namespace uirenderer */
418} /* namespace android */