blob: c8833d2a74892969823a2acb84df129401b354b8 [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"
Romain Guycaaaa662017-03-27 00:40:21 -070025
Chris Craik9db58c02015-08-19 15:19:18 -070026#include <algorithm>
27
Romain Guycaaaa662017-03-27 00:40:21 -070028#include <ui/ColorSpace.h>
29
John Reck3b202512014-06-23 13:13:08 -070030namespace android {
31namespace uirenderer {
32
John Reck0e89e2b2014-10-31 14:49:06 -070033RenderState::RenderState(renderthread::RenderThread& thread)
34 : mRenderThread(thread)
John Reck3b202512014-06-23 13:13:08 -070035 , mViewportWidth(0)
36 , mViewportHeight(0)
37 , mFramebuffer(0) {
John Reck0e89e2b2014-10-31 14:49:06 -070038 mThreadId = pthread_self();
John Reck3b202512014-06-23 13:13:08 -070039}
40
41RenderState::~RenderState() {
Chris Craik44eb2c02015-01-29 09:45:09 -080042 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080043 "State object lifecycle not managed correctly");
John Reck3b202512014-06-23 13:13:08 -070044}
45
46void RenderState::onGLContextCreated() {
Chris Craik44eb2c02015-01-29 09:45:09 -080047 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
Chris Craik96a5c4c2015-01-27 15:46:35 -080048 "State object lifecycle not managed correctly");
Greg Daniel45ec62b2017-01-04 14:27:00 -050049 GpuMemoryTracker::onGpuContextCreated();
John Reck38e0c322015-11-10 12:19:17 -080050
Chris Craik44eb2c02015-01-29 09:45:09 -080051 mBlend = new Blend();
Chris Craik96a5c4c2015-01-27 15:46:35 -080052 mMeshState = new MeshState();
53 mScissor = new Scissor();
54 mStencil = new Stencil();
Chris Craik65fe5ee2015-01-26 18:06:29 -080055
Chris Craik96a5c4c2015-01-27 15:46:35 -080056 // This is delayed because the first access of Caches makes GL calls
Chris Craikff5c8e82015-01-30 09:46:18 -080057 if (!mCaches) {
58 mCaches = &Caches::createInstance(*this);
59 }
Chris Craik96a5c4c2015-01-27 15:46:35 -080060 mCaches->init();
John Reck3b202512014-06-23 13:13:08 -070061}
62
John Reck49bc4ac2015-01-29 12:53:38 -080063static void layerLostGlContext(Layer* layer) {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050064 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::OpenGL,
65 "layerLostGlContext on non GL layer");
66 static_cast<GlLayer*>(layer)->onGlContextLost();
John Reck49bc4ac2015-01-29 12:53:38 -080067}
68
Chris Craik1d477422014-08-26 17:30:15 -070069void RenderState::onGLContextDestroyed() {
Chris Craik9fded232015-11-11 16:42:34 -080070 mLayerPool.clear();
71
Chris Craik96a5c4c2015-01-27 15:46:35 -080072 // TODO: reset all cached state in state objects
John Reck49bc4ac2015-01-29 12:53:38 -080073 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
Chris Craik96a5c4c2015-01-27 15:46:35 -080074
Chris Craik44eb2c02015-01-29 09:45:09 -080075 mCaches->terminate();
76
77 delete mBlend;
78 mBlend = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -080079 delete mMeshState;
80 mMeshState = nullptr;
81 delete mScissor;
82 mScissor = nullptr;
83 delete mStencil;
84 mStencil = nullptr;
John Reck38e0c322015-11-10 12:19:17 -080085
sergeyvc3f13162017-02-06 11:45:14 -080086 destroyLayersInUpdater();
Greg Daniel45ec62b2017-01-04 14:27:00 -050087 GpuMemoryTracker::onGpuContextDestroyed();
88}
89
90void RenderState::onVkContextCreated() {
91 LOG_ALWAYS_FATAL_IF(mBlend || mMeshState || mScissor || mStencil,
92 "State object lifecycle not managed correctly");
93 GpuMemoryTracker::onGpuContextCreated();
94}
95
96static void layerDestroyedVkContext(Layer* layer) {
97 LOG_ALWAYS_FATAL_IF(layer->getApi() != Layer::Api::Vulkan,
98 "layerLostVkContext on non Vulkan layer");
99 static_cast<VkLayer*>(layer)->onVkContextDestroyed();
100}
101
102void RenderState::onVkContextDestroyed() {
103 mLayerPool.clear();
104 std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerDestroyedVkContext);
105 GpuMemoryTracker::onGpuContextDestroyed();
106}
107
108GrContext* RenderState::getGrContext() const {
109 return mRenderThread.getGrContext();
Chris Craik1d477422014-08-26 17:30:15 -0700110}
111
Chris Craik9fded232015-11-11 16:42:34 -0800112void RenderState::flush(Caches::FlushMode mode) {
113 switch (mode) {
114 case Caches::FlushMode::Full:
115 // fall through
116 case Caches::FlushMode::Moderate:
117 // fall through
118 case Caches::FlushMode::Layers:
119 mLayerPool.clear();
120 break;
121 }
122 mCaches->flush(mode);
123}
124
John Reck3b202512014-06-23 13:13:08 -0700125void RenderState::setViewport(GLsizei width, GLsizei height) {
126 mViewportWidth = width;
127 mViewportHeight = height;
128 glViewport(0, 0, mViewportWidth, mViewportHeight);
129}
130
131
132void RenderState::getViewport(GLsizei* outWidth, GLsizei* outHeight) {
133 *outWidth = mViewportWidth;
134 *outHeight = mViewportHeight;
135}
136
137void RenderState::bindFramebuffer(GLuint fbo) {
138 if (mFramebuffer != fbo) {
139 mFramebuffer = fbo;
140 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
141 }
142}
143
John Reck0b8d0672016-01-29 14:18:22 -0800144GLuint RenderState::createFramebuffer() {
Chris Craik818c9fb2015-10-23 14:33:42 -0700145 GLuint ret;
146 glGenFramebuffers(1, &ret);
147 return ret;
148}
149
150void RenderState::deleteFramebuffer(GLuint fbo) {
151 if (mFramebuffer == fbo) {
152 // GL defines that deleting the currently bound FBO rebinds FBO 0.
153 // Reflect this in our cached value.
154 mFramebuffer = 0;
155 }
156 glDeleteFramebuffers(1, &fbo);
157}
158
John Reck3b202512014-06-23 13:13:08 -0700159void RenderState::invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info) {
John Reck95cd24b2015-08-04 11:17:39 -0700160 if (mode == DrawGlInfo::kModeProcessNoContext) {
161 // If there's no context we don't need to interrupt as there's
162 // no gl state to save/restore
163 (*functor)(mode, info);
164 } else {
165 interruptForFunctorInvoke();
166 (*functor)(mode, info);
167 resumeFromFunctorInvoke();
168 }
John Reck3b202512014-06-23 13:13:08 -0700169}
170
171void RenderState::interruptForFunctorInvoke() {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800172 mCaches->setProgram(nullptr);
Chris Craik44eb2c02015-01-29 09:45:09 -0800173 mCaches->textureState().resetActiveTexture();
Chris Craik96a5c4c2015-01-27 15:46:35 -0800174 meshState().unbindMeshBuffer();
175 meshState().unbindIndicesBuffer();
176 meshState().resetVertexPointers();
177 meshState().disableTexCoordsVertexArray();
John Reck3b202512014-06-23 13:13:08 -0700178 debugOverdraw(false, false);
Romain Guy253f2c22016-09-28 17:34:42 -0700179 // TODO: We need a way to know whether the functor is sRGB aware (b/32072673)
Romain Guyefb4b062017-02-27 11:00:04 -0800180 if (mCaches->extensions().hasLinearBlending() &&
181 mCaches->extensions().hasSRGBWriteControl()) {
Romain Guy253f2c22016-09-28 17:34:42 -0700182 glDisable(GL_FRAMEBUFFER_SRGB_EXT);
183 }
John Reck3b202512014-06-23 13:13:08 -0700184}
185
186void RenderState::resumeFromFunctorInvoke() {
Romain Guyefb4b062017-02-27 11:00:04 -0800187 if (mCaches->extensions().hasLinearBlending() &&
188 mCaches->extensions().hasSRGBWriteControl()) {
Romain Guy253f2c22016-09-28 17:34:42 -0700189 glEnable(GL_FRAMEBUFFER_SRGB_EXT);
190 }
191
John Reck3b202512014-06-23 13:13:08 -0700192 glViewport(0, 0, mViewportWidth, mViewportHeight);
193 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
194 debugOverdraw(false, false);
195
196 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
197
Chris Craik65fe5ee2015-01-26 18:06:29 -0800198 scissor().invalidate();
Chris Craik44eb2c02015-01-29 09:45:09 -0800199 blend().invalidate();
John Reck3b202512014-06-23 13:13:08 -0700200
Chris Craik44eb2c02015-01-29 09:45:09 -0800201 mCaches->textureState().activateTexture(0);
202 mCaches->textureState().resetBoundTextures();
John Reck3b202512014-06-23 13:13:08 -0700203}
204
205void RenderState::debugOverdraw(bool enable, bool clear) {
Chris Craik2507c342015-05-04 14:36:49 -0700206 if (Properties::debugOverdraw && mFramebuffer == 0) {
John Reck3b202512014-06-23 13:13:08 -0700207 if (clear) {
Chris Craik65fe5ee2015-01-26 18:06:29 -0800208 scissor().setEnabled(false);
Chris Craik96a5c4c2015-01-27 15:46:35 -0800209 stencil().clear();
John Reck3b202512014-06-23 13:13:08 -0700210 }
211 if (enable) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800212 stencil().enableDebugWrite();
John Reck3b202512014-06-23 13:13:08 -0700213 } else {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800214 stencil().disable();
John Reck3b202512014-06-23 13:13:08 -0700215 }
216 }
217}
218
sergeyv3e9999b2017-01-19 15:37:02 -0800219static void destroyLayerInUpdater(DeferredLayerUpdater* layerUpdater) {
220 layerUpdater->destroyLayer();
221}
222
223void RenderState::destroyLayersInUpdater() {
224 std::for_each(mActiveLayerUpdaters.begin(), mActiveLayerUpdaters.end(), destroyLayerInUpdater);
225}
226
John Reck0e89e2b2014-10-31 14:49:06 -0700227class DecStrongTask : public renderthread::RenderTask {
228public:
Chih-Hung Hsiehc6baf562016-04-27 11:29:23 -0700229 explicit DecStrongTask(VirtualLightRefBase* object) : mObject(object) {}
John Reck0e89e2b2014-10-31 14:49:06 -0700230
Chris Craikd41c4d82015-01-05 15:51:13 -0800231 virtual void run() override {
232 mObject->decStrong(nullptr);
233 mObject = nullptr;
John Reck0e89e2b2014-10-31 14:49:06 -0700234 delete this;
235 }
236
237private:
238 VirtualLightRefBase* mObject;
239};
240
241void RenderState::postDecStrong(VirtualLightRefBase* object) {
John Recka55b5d62016-01-14 15:09:10 -0800242 if (pthread_equal(mThreadId, pthread_self())) {
243 object->decStrong(nullptr);
244 } else {
245 mRenderThread.queue(new DecStrongTask(object));
246 }
John Reck0e89e2b2014-10-31 14:49:06 -0700247}
248
Chris Craik6c15ffa2015-02-02 13:50:55 -0800249///////////////////////////////////////////////////////////////////////////////
250// Render
251///////////////////////////////////////////////////////////////////////////////
252
Chris Craik12efe642015-09-28 15:52:12 -0700253void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
Chris Craik6c15ffa2015-02-02 13:50:55 -0800254 const Glop::Mesh& mesh = glop.mesh;
Chris Craikef250742015-02-25 17:16:16 -0800255 const Glop::Mesh::Vertices& vertices = mesh.vertices;
256 const Glop::Mesh::Indices& indices = mesh.indices;
Chris Craik0519c812015-02-11 13:17:06 -0800257 const Glop::Fill& fill = glop.fill;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800258
John Reck975591a2016-01-22 16:28:07 -0800259 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800260
Chris Craik0519c812015-02-11 13:17:06 -0800261 // ---------------------------------------------
262 // ---------- Program + uniform setup ----------
263 // ---------------------------------------------
264 mCaches->setProgram(fill.program);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800265
Chris Craik0519c812015-02-11 13:17:06 -0800266 if (fill.colorEnabled) {
267 fill.program->setColor(fill.color);
268 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800269
Chris Craik12efe642015-09-28 15:52:12 -0700270 fill.program->set(orthoMatrix,
Chris Craik6c15ffa2015-02-02 13:50:55 -0800271 glop.transform.modelView,
Chris Craik53e51e42015-06-01 10:35:35 -0700272 glop.transform.meshTransform(),
273 glop.transform.transformFlags & TransformFlags::OffsetByFudgeFactor);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800274
Chris Craik0519c812015-02-11 13:17:06 -0800275 // Color filter uniforms
Chris Craikb9ce116d2015-08-20 15:14:06 -0700276 if (fill.filterMode == ProgramDescription::ColorFilterMode::Blend) {
Chris Craikef250742015-02-25 17:16:16 -0800277 const FloatColor& color = fill.filter.color;
Chris Craik117bdbc2015-02-05 10:12:38 -0800278 glUniform4f(mCaches->program().getUniform("colorBlend"),
279 color.r, color.g, color.b, color.a);
Chris Craikb9ce116d2015-08-20 15:14:06 -0700280 } else if (fill.filterMode == ProgramDescription::ColorFilterMode::Matrix) {
Chris Craik117bdbc2015-02-05 10:12:38 -0800281 glUniformMatrix4fv(mCaches->program().getUniform("colorMatrix"), 1, GL_FALSE,
Chris Craikef250742015-02-25 17:16:16 -0800282 fill.filter.matrix.matrix);
Chris Craik117bdbc2015-02-05 10:12:38 -0800283 glUniform4fv(mCaches->program().getUniform("colorMatrixVector"), 1,
Chris Craikef250742015-02-25 17:16:16 -0800284 fill.filter.matrix.vector);
Chris Craik117bdbc2015-02-05 10:12:38 -0800285 }
286
Chris Craik0519c812015-02-11 13:17:06 -0800287 // Round rect clipping uniforms
288 if (glop.roundRectClipState) {
289 // TODO: avoid query, and cache values (or RRCS ptr) in program
290 const RoundRectClipState* state = glop.roundRectClipState;
291 const Rect& innerRect = state->innerRect;
292 glUniform4f(fill.program->getUniform("roundRectInnerRectLTRB"),
293 innerRect.left, innerRect.top,
294 innerRect.right, innerRect.bottom);
295 glUniformMatrix4fv(fill.program->getUniform("roundRectInvTransform"),
296 1, GL_FALSE, &state->matrix.data[0]);
297
298 // add half pixel to round out integer rect space to cover pixel centers
299 float roundedOutRadius = state->radius + 0.5f;
300 glUniform1f(fill.program->getUniform("roundRectRadius"),
301 roundedOutRadius);
302 }
Chris Craikef250742015-02-25 17:16:16 -0800303
John Reck975591a2016-01-22 16:28:07 -0800304 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800305
Chris Craik117bdbc2015-02-05 10:12:38 -0800306 // --------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800307 // ---------- Mesh setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800308 // --------------------------------
309 // vertices
Chris Craik1b7db402016-02-24 18:25:32 -0800310 meshState().bindMeshBuffer(vertices.bufferObject);
311 meshState().bindPositionVertexPointer(vertices.position, vertices.stride);
Chris Craik117bdbc2015-02-05 10:12:38 -0800312
313 // indices
Chris Craik1b7db402016-02-24 18:25:32 -0800314 meshState().bindIndicesBuffer(indices.bufferObject);
Chris Craik117bdbc2015-02-05 10:12:38 -0800315
Chris Craik138c21f2016-04-28 16:59:42 -0700316 // texture
317 if (fill.texture.texture != nullptr) {
Chris Craik26bf3422015-02-26 16:28:17 -0800318 const Glop::Fill::TextureData& texture = fill.texture;
319 // texture always takes slot 0, shader samplers increment from there
Chris Craik0519c812015-02-11 13:17:06 -0800320 mCaches->textureState().activateTexture(0);
321
sergeyv2a38c422016-10-25 15:21:50 -0700322 mCaches->textureState().bindTexture(texture.texture->target(), texture.texture->id());
Chris Craik26bf3422015-02-26 16:28:17 -0800323 if (texture.clamp != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700324 texture.texture->setWrap(texture.clamp, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800325 }
Chris Craik26bf3422015-02-26 16:28:17 -0800326 if (texture.filter != GL_INVALID_ENUM) {
sergeyv2a38c422016-10-25 15:21:50 -0700327 texture.texture->setFilter(texture.filter, false, false);
Chris Craik30036092015-02-12 10:41:39 -0800328 }
Chris Craik0519c812015-02-11 13:17:06 -0800329
Chris Craik26bf3422015-02-26 16:28:17 -0800330 if (texture.textureTransform) {
331 glUniformMatrix4fv(fill.program->getUniform("mainTextureTransform"), 1,
332 GL_FALSE, &texture.textureTransform->data[0]);
333 }
Chris Craik138c21f2016-04-28 16:59:42 -0700334 }
335
336 // vertex attributes (tex coord, color, alpha)
337 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
338 meshState().enableTexCoordsVertexArray();
339 meshState().bindTexCoordsVertexPointer(vertices.texCoord, vertices.stride);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800340 } else {
341 meshState().disableTexCoordsVertexArray();
342 }
Chris Craikef250742015-02-25 17:16:16 -0800343 int colorLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700344 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800345 colorLocation = fill.program->getAttrib("colors");
346 glEnableVertexAttribArray(colorLocation);
347 glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, vertices.stride, vertices.color);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800348 }
Chris Craikef250742015-02-25 17:16:16 -0800349 int alphaLocation = -1;
Chris Craik53e51e42015-06-01 10:35:35 -0700350 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800351 // NOTE: alpha vertex position is computed assuming no VBO
352 const void* alphaCoords = ((const GLbyte*) vertices.position) + kVertexAlphaOffset;
353 alphaLocation = fill.program->getAttrib("vtxAlpha");
354 glEnableVertexAttribArray(alphaLocation);
355 glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800356 }
Chris Craik922d3a72015-02-13 17:47:21 -0800357 // Shader uniforms
Romain Guy253f2c22016-09-28 17:34:42 -0700358 SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
Chris Craik922d3a72015-02-13 17:47:21 -0800359
John Reck975591a2016-01-22 16:28:07 -0800360 GL_CHECKPOINT(MODERATE);
Dohyun Leec5a3efd2016-01-21 13:46:21 +0900361 Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
362 fill.skiaShaderData.bitmapData.bitmapTexture : nullptr;
363 const AutoTexture autoCleanup(texture);
John Reck9372ac32016-01-19 11:46:52 -0800364
Romain Guycaaaa662017-03-27 00:40:21 -0700365 // If we have a shader and a base texture, the base texture is assumed to be an alpha mask
366 // which means the color space conversion applies to the shader's bitmap
367 Texture* colorSpaceTexture = texture != nullptr ? texture : fill.texture.texture;
368 if (colorSpaceTexture != nullptr) {
369 if (colorSpaceTexture->hasColorSpaceConversion()) {
370 const ColorSpaceConnector* connector = colorSpaceTexture->getColorSpaceConnector();
371 glUniformMatrix3fv(fill.program->getUniform("colorSpaceMatrix"), 1,
372 GL_FALSE, connector->getTransform().asArray());
373 }
374
375 TransferFunctionType transferFunction = colorSpaceTexture->getTransferFunctionType();
376 if (transferFunction != TransferFunctionType::None) {
377 const ColorSpaceConnector* connector = colorSpaceTexture->getColorSpaceConnector();
378 const ColorSpace& source = connector->getSource();
379
380 switch (transferFunction) {
381 case TransferFunctionType::None:
382 break;
383 case TransferFunctionType::Full:
384 glUniform1fv(fill.program->getUniform("transferFunction"), 7,
385 reinterpret_cast<const float*>(&source.getTransferParameters().g));
386 break;
387 case TransferFunctionType::Limited:
388 glUniform1fv(fill.program->getUniform("transferFunction"), 5,
389 reinterpret_cast<const float*>(&source.getTransferParameters().g));
390 break;
391 case TransferFunctionType::Gamma:
392 glUniform1f(fill.program->getUniform("transferFunctionGamma"),
393 source.getTransferParameters().g);
394 break;
395 }
396 }
397 }
398
Chris Craik117bdbc2015-02-05 10:12:38 -0800399 // ------------------------------------
Chris Craik6c15ffa2015-02-02 13:50:55 -0800400 // ---------- GL state setup ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800401 // ------------------------------------
Chris Craik03188872015-02-02 18:39:33 -0800402 blend().setFactors(glop.blend.src, glop.blend.dst);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800403
John Reck975591a2016-01-22 16:28:07 -0800404 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800405
Chris Craik117bdbc2015-02-05 10:12:38 -0800406 // ------------------------------------
Chris Craik2ab95d72015-02-06 15:25:51 -0800407 // ---------- Actual drawing ----------
Chris Craik117bdbc2015-02-05 10:12:38 -0800408 // ------------------------------------
Chris Craikef250742015-02-25 17:16:16 -0800409 if (indices.bufferObject == meshState().getQuadListIBO()) {
Chris Craik2ab95d72015-02-06 15:25:51 -0800410 // Since the indexed quad list is of limited length, we loop over
411 // the glDrawXXX method while updating the vertex pointer
Chris Craik0519c812015-02-11 13:17:06 -0800412 GLsizei elementsCount = mesh.elementCount;
Chris Craikef250742015-02-25 17:16:16 -0800413 const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
Chris Craik2ab95d72015-02-06 15:25:51 -0800414 while (elementsCount > 0) {
Chris Craik9db58c02015-08-19 15:19:18 -0700415 GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
Chris Craik1b7db402016-02-24 18:25:32 -0800416 meshState().bindPositionVertexPointer(vertexData, vertices.stride);
Chris Craik53e51e42015-06-01 10:35:35 -0700417 if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
Chris Craik1b7db402016-02-24 18:25:32 -0800418 meshState().bindTexCoordsVertexPointer(
Chris Craikef250742015-02-25 17:16:16 -0800419 vertexData + kMeshTextureOffset, vertices.stride);
Chris Craikf27133d2015-02-19 09:51:53 -0800420 }
421
Chris Craik2ab95d72015-02-06 15:25:51 -0800422 glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
423 elementsCount -= drawCount;
Chris Craikef250742015-02-25 17:16:16 -0800424 vertexData += (drawCount / 6) * 4 * vertices.stride;
Chris Craik2ab95d72015-02-06 15:25:51 -0800425 }
Chris Craikef250742015-02-25 17:16:16 -0800426 } else if (indices.bufferObject || indices.indices) {
427 glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800428 } else {
Chris Craik0519c812015-02-11 13:17:06 -0800429 glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
Chris Craik6c15ffa2015-02-02 13:50:55 -0800430 }
Chris Craik117bdbc2015-02-05 10:12:38 -0800431
John Reck975591a2016-01-22 16:28:07 -0800432 GL_CHECKPOINT(MODERATE);
John Reck9372ac32016-01-19 11:46:52 -0800433
Chris Craik2ab95d72015-02-06 15:25:51 -0800434 // -----------------------------------
435 // ---------- Mesh teardown ----------
436 // -----------------------------------
Chris Craik53e51e42015-06-01 10:35:35 -0700437 if (vertices.attribFlags & VertexAttribFlags::Alpha) {
Chris Craikef250742015-02-25 17:16:16 -0800438 glDisableVertexAttribArray(alphaLocation);
439 }
Chris Craik53e51e42015-06-01 10:35:35 -0700440 if (vertices.attribFlags & VertexAttribFlags::Color) {
Chris Craikef250742015-02-25 17:16:16 -0800441 glDisableVertexAttribArray(colorLocation);
Chris Craik117bdbc2015-02-05 10:12:38 -0800442 }
John Reck9372ac32016-01-19 11:46:52 -0800443
John Reck975591a2016-01-22 16:28:07 -0800444 GL_CHECKPOINT(MODERATE);
Chris Craik117bdbc2015-02-05 10:12:38 -0800445}
446
447void RenderState::dump() {
448 blend().dump();
449 meshState().dump();
450 scissor().dump();
451 stencil().dump();
Chris Craik6c15ffa2015-02-02 13:50:55 -0800452}
453
John Reck3b202512014-06-23 13:13:08 -0700454} /* namespace uirenderer */
455} /* namespace android */