blob: 7dfc2ee4fbe5ae96d6d20f20c50a4b5bf5ea4e3c [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)
177 if (mCaches->extensions().hasSRGBWriteControl()) {
178 glDisable(GL_FRAMEBUFFER_SRGB_EXT);
179 }
John Reck3b202512014-06-23 13:13:08 -0700180}
181
182void RenderState::resumeFromFunctorInvoke() {
Romain Guy253f2c22016-09-28 17:34:42 -0700183 if (mCaches->extensions().hasSRGBWriteControl()) {
184 glEnable(GL_FRAMEBUFFER_SRGB_EXT);
185 }
186
John Reck3b202512014-06-23 13:13:08 -0700187 glViewport(0, 0, mViewportWidth, mViewportHeight);
188 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
189 debugOverdraw(false, false);
190
191 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
192
Chris Craik65fe5ee2015-01-26 18:06:29 -0800193 scissor().invalidate();
Chris Craik44eb2c02015-01-29 09:45:09 -0800194 blend().invalidate();
John Reck3b202512014-06-23 13:13:08 -0700195
Chris Craik44eb2c02015-01-29 09:45:09 -0800196 mCaches->textureState().activateTexture(0);
197 mCaches->textureState().resetBoundTextures();
John Reck3b202512014-06-23 13:13:08 -0700198}
199
200void RenderState::debugOverdraw(bool enable, bool clear) {
Chris Craik2507c342015-05-04 14:36:49 -0700201 if (Properties::debugOverdraw && mFramebuffer == 0) {
John Reck3b202512014-06-23 13:13:08 -0700202 if (clear) {
Chris Craik65fe5ee2015-01-26 18:06:29 -0800203 scissor().setEnabled(false);
Chris Craik96a5c4c2015-01-27 15:46:35 -0800204 stencil().clear();
John Reck3b202512014-06-23 13:13:08 -0700205 }
206 if (enable) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800207 stencil().enableDebugWrite();
John Reck3b202512014-06-23 13:13:08 -0700208 } else {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800209 stencil().disable();
John Reck3b202512014-06-23 13:13:08 -0700210 }
211 }
212}
213
sergeyv3e9999b2017-01-19 15:37:02 -0800214static void destroyLayerInUpdater(DeferredLayerUpdater* layerUpdater) {
215 layerUpdater->destroyLayer();
216}
217
218void RenderState::destroyLayersInUpdater() {
219 std::for_each(mActiveLayerUpdaters.begin(), mActiveLayerUpdaters.end(), destroyLayerInUpdater);
220}
221
John Reck0e89e2b2014-10-31 14:49:06 -0700222class DecStrongTask : public renderthread::RenderTask {
223public:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -0700224 explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
John Reck0e89e2b2014-10-31 14:49:06 -0700225
Chris Craikd41c4d82015-01-05 15:51:13 -0800226 virtual void run() override {
227 mObject->decStrong(nullptr);
228 mObject = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700229 delete this;
230 }
231
232private:
233 VirtualLightRefBase* mObject;
234};
235
236void RenderState::postDecStrong(VirtualLightRefBase* object) {
John Recka55b5d62016-01-14 15:09:10 -0800237 if (pthread_equal(mThreadId, pthread_self())) {
238 object->decStrong(nullptr);
239 } else {
240 mRenderThread.queue(new DecStrongTask(object));
241 }
John Reck0e89e2b2014-10-31 14:49:06 -0700242}
243
Chris Craik6c15ffa2015-02-02 13:50:55 -0800244///////////////////////////////////////////////////////////////////////////////
245// Render
246///////////////////////////////////////////////////////////////////////////////
247
Chris Craik12efe642015-09-28 15:52:12 -0700248void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800249 const Glop::Mesh& mesh = glop.mesh;
Chris Craikef250742015-02-25 17:16:16 -0800250 const Glop::Mesh::Vertices& vertices = mesh.vertices;
251 const Glop::Mesh::Indices& indices = mesh.indices;
Chris Craik0519c8102015-02-11 13:17:06 -0800252 const Glop::Fill& fill = glop.fill;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800253
John Reck975591a2016-01-22 16:28:07 -0800254 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800255
Chris Craik0519c8102015-02-11 13:17:06 -0800256 // ---------------------------------------------
257 // ---------- Program + uniform setup ----------
258 // ---------------------------------------------
259 mCaches->setProgram(fill.program);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800260
Chris Craik0519c8102015-02-11 13:17:06 -0800261 if (fill.colorEnabled) {
262 fill.program->setColor(fill.color);
263 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800264
Chris Craik12efe642015-09-28 15:52:12 -0700265 fill.program->set(orthoMatrix,
Chris Craik6c15ffa2015-02-02 13:50:55 -0800266 glop.transform.modelView,
Chris Craik53e51e42015-06-01 10:35:35 -0700267 glop.transform.meshTransform(),
268 glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800269
Chris Craik0519c8102015-02-11 13:17:06 -0800270 // Color filter uniforms
Chris Craikb9ce116d2015-08-20 15:14:06 -0700271 if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
Chris Craikef250742015-02-25 17:16:16 -0800272 const FloatColor& color = fill.filter.color;
Chris Craik117bdbc2015-02-05 10:12:38 -0800273 glUniform4f(mCaches->program().getUniform("colorBlend"),
274 color.r, color.g, color.b, color.a);
Chris Craikb9ce116d2015-08-20 15:14:06 -0700275 } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
Chris Craik117bdbc2015-02-05 10:12:38 -0800276 glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
Chris Craikef250742015-02-25 17:16:16 -0800277 fill.filter.matrix.matrix);
Chris Craik117bdbc2015-02-05 10:12:38 -0800278 glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
Chris Craikef250742015-02-25 17:16:16 -0800279 fill.filter.matrix.vector);
Chris Craik117bdbc2015-02-05 10:12:38 -0800280 }
281
Chris Craik0519c8102015-02-11 13:17:06 -0800282 // Round rect clipping uniforms
283 if (glop.roundRectClipState) {
284 // TODO: avoid query, and cache values (or RRCS ptr) in program
285 const RoundRectClipState* state = glop.roundRectClipState;
286 const Rect& innerRect = state->innerRect;
287 glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
288 innerRect.left, innerRect.top,
289 innerRect.right, innerRect.bottom);
290 glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
291 1, GL_FALSE, &state->matrix.data[0]);
292
293 // add half pixel to round out integer rect space to cover pixel centers
294 float roundedOutRadius = state->radius + 0.5f;
295 glUniform1f(fill.program->getUniform("roundRectRadius"),
296 roundedOutRadius);
297 }
Chris Craikef250742015-02-25 17:16:16 -0800298
John Reck975591a2016-01-22 16:28:07 -0800299 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800300
Chris Craik117bdbc2015-02-05 10:12:38 -0800301 // --------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800302 // ---------- Mesh setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800303 // --------------------------------
304 // vertices
Chris Craik1b7db402016-02-24 18:25:32 -0800305 meshState().bindMeshBuffer(vertices.bufferObject);
306 meshState().bindPositionVertexPointer(vertices.position, vertices.stride);
Chris Craik117bdbc2015-02-05 10:12:38 -0800307
308 // indices
Chris Craik1b7db402016-02-24 18:25:32 -0800309 meshState().bindIndicesBuffer(indices.bufferObject);
Chris Craik117bdbc2015-02-05 10:12:38 -0800310
Chris Craik138c21f2016-04-28 16:59:42 -0700311 // texture
312 if (fill.texture.texture != nullptr) {
Chris Craik26bf3422015-02-26 16:28:17 -0800313 const Glop::Fill::TextureData& texture = fill.texture;
314 // texture always takes slot 0, shader samplers increment from there
Chris Craik0519c8102015-02-11 13:17:06 -0800315 mCaches->textureState().activateTexture(0);
316
sergeyv2a38c422016-10-25 15:21:50 -0700317 mCaches->textureState().bindTexture(texture.texture->target(), texture.texture->id());
Chris Craik26bf3422015-02-26 16:28:17 -0800318 if (texture.clamp != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700319 texture.texture->setWrap(texture.clamp, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800320 }
Chris Craik26bf3422015-02-26 16:28:17 -0800321 if (texture.filter != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700322 texture.texture->setFilter(texture.filter, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800323 }
Chris Craik0519c8102015-02-11 13:17:06 -0800324
Chris Craik26bf3422015-02-26 16:28:17 -0800325 if (texture.textureTransform) {
326 glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
327 GL_FALSE, &texture.textureTransform->data[0]);
328 }
Chris Craik138c21f2016-04-28 16:59:42 -0700329 }
330
331 // vertex attributes (tex coord, color, alpha)
332 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
333 meshState().enableTexCoordsVertexArray();
334 meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800335 } else {
336 meshState().disableTexCoordsVertexArray();
337 }
Chris Craikef250742015-02-25 17:16:16 -0800338 int colorLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700339 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800340 colorLocation = fill.program->getAttrib("colors");
341 glEnableVertexAttribArray(colorLocation);
342 glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800343 }
Chris Craikef250742015-02-25 17:16:16 -0800344 int alphaLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700345 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800346 // NOTE: alpha vertex position is computed assuming no VBO
347 const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
348 alphaLocation = fill.program->getAttrib("vtxAlpha");
349 glEnableVertexAttribArray(alphaLocation);
350 glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800351 }
Chris Craik922d3a72015-02-13 17:47:21 -0800352 // Shader uniforms
Romain Guy253f2c22016-09-28 17:34:42 -0700353 SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
Chris Craik922d3a72015-02-13 17:47:21 -0800354
John Reck975591a2016-01-22 16:28:07 -0800355 GL_CHECKPOINT(MODERATE);
Dohyun Leec5a3efd2016-01-21 13:46:21 +0900356 Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
357 fill.skiaShaderData.bitmapData.bitmapTexture : nullptr;
358 const AutoTexture autoCleanup(texture);
John Reck9372ac32016-01-19 11:46:52 -0800359
Chris Craik117bdbc2015-02-05 10:12:38 -0800360 // ------------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800361 // ---------- GL state setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800362 // ------------------------------------
Chris Craik03188872015-02-02 18:39:33 -0800363 blend().setFactors(glop.blend.src, glop.blend.dst);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800364
John Reck975591a2016-01-22 16:28:07 -0800365 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800366
Chris Craik117bdbc2015-02-05 10:12:38 -0800367 // ------------------------------------
Chris Craik2ab95d72015-02-06 15:25:51 -0800368 // ---------- Actual drawing ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800369 // ------------------------------------
Chris Craikef250742015-02-25 17:16:16 -0800370 if (indices.bufferObject == meshState().getQuadListIBO()) {
Chris Craik2ab95d72015-02-06 15:25:51 -0800371 // Since the indexed quad list is of limited length, we loop over
372 // the glDrawXXX method while updating the vertex pointer
Chris Craik0519c8102015-02-11 13:17:06 -0800373 GLsizei elementsCount = mesh.elementCount;
Chris Craikef250742015-02-25 17:16:16 -0800374 const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
Chris Craik2ab95d72015-02-06 15:25:51 -0800375 while (elementsCount > 0) {
Chris Craik9db58c02015-08-19 15:19:18 -0700376 GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
Chris Craik1b7db402016-02-24 18:25:32 -0800377 meshState().bindPositionVertexPointer(vertexData, vertices.stride);
Chris Craik53e51e42015-06-01 10:35:35 -0700378 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craik1b7db402016-02-24 18:25:32 -0800379 meshState().bindTexCoordsVertexPointer(
Chris Craikef250742015-02-25 17:16:16 -0800380 vertexData + kMeshTextureOffset, vertices.stride);
Chris Craikf27133d2015-02-19 09:51:53 -0800381 }
382
Chris Craik2ab95d72015-02-06 15:25:51 -0800383 glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
384 elementsCount -= drawCount;
Chris Craikef250742015-02-25 17:16:16 -0800385 vertexData += (drawCount / 6) * 4 * vertices.stride;
Chris Craik2ab95d72015-02-06 15:25:51 -0800386 }
Chris Craikef250742015-02-25 17:16:16 -0800387 } else if (indices.bufferObject || indices.indices) {
388 glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800389 } else {
Chris Craik0519c8102015-02-11 13:17:06 -0800390 glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800391 }
Chris Craik117bdbc2015-02-05 10:12:38 -0800392
John Reck975591a2016-01-22 16:28:07 -0800393 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800394
Chris Craik2ab95d72015-02-06 15:25:51 -0800395 // -----------------------------------
396 // ---------- Mesh teardown ----------
397 // -----------------------------------
Chris Craik53e51e42015-06-01 10:35:35 -0700398 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800399 glDisableVertexAttribArray(alphaLocation);
400 }
Chris Craik53e51e42015-06-01 10:35:35 -0700401 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800402 glDisableVertexAttribArray(colorLocation);
Chris Craik117bdbc2015-02-05 10:12:38 -0800403 }
John Reck9372ac32016-01-19 11:46:52 -0800404
John Reck975591a2016-01-22 16:28:07 -0800405 GL_CHECKPOINT(MODERATE);
Chris Craik117bdbc2015-02-05 10:12:38 -0800406}
407
408void RenderState::dump() {
409 blend().dump();
410 meshState().dump();
411 scissor().dump();
412 stencil().dump();
Chris Craik6c15ffa2015-02-02 13:50:55 -0800413}
414
John Reck3b202512014-06-23 13:13:08 -0700415} /* namespace uirenderer */
416} /* namespace android */