Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | */ |
| 16 | |
| 17 | #include "BakedOpRenderer.h" |
| 18 | |
| 19 | #include "Caches.h" |
| 20 | #include "Glop.h" |
| 21 | #include "GlopBuilder.h" |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 22 | #include "renderstate/OffscreenBufferPool.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 23 | #include "renderstate/RenderState.h" |
| 24 | #include "utils/GLUtils.h" |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 25 | #include "VertexBuffer.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 26 | |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 27 | #include <algorithm> |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 28 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 32 | OffscreenBuffer* BakedOpRenderer::startTemporaryLayer(uint32_t width, uint32_t height) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 33 | LOG_ALWAYS_FATAL_IF(mRenderTarget.offscreenBuffer, "already has layer..."); |
| 34 | |
| 35 | OffscreenBuffer* buffer = mRenderState.layerPool().get(mRenderState, width, height); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 36 | startRepaintLayer(buffer, Rect(width, height)); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 37 | return buffer; |
| 38 | } |
| 39 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 40 | void BakedOpRenderer::startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect) { |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 41 | LOG_ALWAYS_FATAL_IF(mRenderTarget.offscreenBuffer, "already has layer..."); |
| 42 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 43 | mRenderTarget.offscreenBuffer = offscreenBuffer; |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 44 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 45 | // create and bind framebuffer |
| 46 | mRenderTarget.frameBufferId = mRenderState.genFramebuffer(); |
| 47 | mRenderState.bindFramebuffer(mRenderTarget.frameBufferId); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 48 | |
| 49 | // attach the texture to the FBO |
| 50 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 51 | offscreenBuffer->texture.id, 0); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 52 | LOG_ALWAYS_FATAL_IF(GLUtils::dumpGLErrors(), "startLayer FAILED"); |
| 53 | LOG_ALWAYS_FATAL_IF(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE, |
| 54 | "framebuffer incomplete!"); |
| 55 | |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 56 | // Change the viewport & ortho projection |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 57 | setViewport(offscreenBuffer->viewportWidth, offscreenBuffer->viewportHeight); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 58 | |
| 59 | clearColorBuffer(repaintRect); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 62 | void BakedOpRenderer::endLayer() { |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 63 | if (mRenderTarget.stencil) { |
| 64 | // if stencil was used for clipping, detach it and return it to pool |
| 65 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); |
| 66 | LOG_ALWAYS_FATAL_IF(GLUtils::dumpGLErrors(), "glfbrb endlayer failed"); |
| 67 | mCaches.renderBufferCache.put(mRenderTarget.stencil); |
| 68 | mRenderTarget.stencil = nullptr; |
| 69 | } |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 70 | mRenderTarget.lastStencilClip = nullptr; |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 71 | |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 72 | mRenderTarget.offscreenBuffer->updateMeshFromRegion(); |
| 73 | mRenderTarget.offscreenBuffer = nullptr; // It's in drawLayerOp's hands now. |
| 74 | |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 75 | // Detach the texture from the FBO |
| 76 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); |
| 77 | LOG_ALWAYS_FATAL_IF(GLUtils::dumpGLErrors(), "endLayer FAILED"); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 78 | mRenderState.deleteFramebuffer(mRenderTarget.frameBufferId); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 79 | mRenderTarget.frameBufferId = 0; |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 82 | void BakedOpRenderer::startFrame(uint32_t width, uint32_t height, const Rect& repaintRect) { |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 83 | LOG_ALWAYS_FATAL_IF(mRenderTarget.frameBufferId != 0, "primary framebufferId must be 0"); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 84 | mRenderState.bindFramebuffer(0); |
| 85 | setViewport(width, height); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 86 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 87 | if (!mOpaque) { |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 88 | clearColorBuffer(repaintRect); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 89 | } |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 90 | |
| 91 | mRenderState.debugOverdraw(true, true); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 92 | } |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 93 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 94 | void BakedOpRenderer::endFrame(const Rect& repaintRect) { |
| 95 | if (CC_UNLIKELY(Properties::debugOverdraw)) { |
| 96 | ClipRect overdrawClip(repaintRect); |
| 97 | Rect viewportRect(mRenderTarget.viewportWidth, mRenderTarget.viewportHeight); |
| 98 | // overdraw visualization |
| 99 | for (int i = 1; i <= 4; i++) { |
| 100 | if (i < 4) { |
| 101 | // nth level of overdraw tests for n+1 draws per pixel |
| 102 | mRenderState.stencil().enableDebugTest(i + 1, false); |
| 103 | } else { |
| 104 | // 4th level tests for 4 or higher draws per pixel |
| 105 | mRenderState.stencil().enableDebugTest(4, true); |
| 106 | } |
| 107 | |
| 108 | SkPaint paint; |
| 109 | paint.setColor(mCaches.getOverdrawColor(i)); |
| 110 | Glop glop; |
| 111 | GlopBuilder(mRenderState, mCaches, &glop) |
| 112 | .setRoundRectClipState(nullptr) |
| 113 | .setMeshUnitQuad() |
| 114 | .setFillPaint(paint, 1.0f) |
| 115 | .setTransform(Matrix4::identity(), TransformFlags::None) |
| 116 | .setModelViewMapUnitToRect(viewportRect) |
| 117 | .build(); |
| 118 | renderGlop(nullptr, &overdrawClip, glop); |
| 119 | } |
| 120 | mRenderState.stencil().disable(); |
| 121 | } |
| 122 | |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 123 | mCaches.clearGarbage(); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 124 | mCaches.pathCache.trim(); |
| 125 | mCaches.tessellationCache.trim(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 126 | |
| 127 | #if DEBUG_OPENGL |
| 128 | GLUtils::dumpGLErrors(); |
| 129 | #endif |
| 130 | |
| 131 | #if DEBUG_MEMORY_USAGE |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 132 | mCaches.dumpMemoryUsage(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 133 | #else |
| 134 | if (Properties::debugLevel & kDebugMemory) { |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 135 | mCaches.dumpMemoryUsage(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 136 | } |
| 137 | #endif |
| 138 | } |
| 139 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 140 | void BakedOpRenderer::setViewport(uint32_t width, uint32_t height) { |
| 141 | mRenderTarget.viewportWidth = width; |
| 142 | mRenderTarget.viewportHeight = height; |
| 143 | mRenderTarget.orthoMatrix.loadOrtho(width, height); |
| 144 | |
| 145 | mRenderState.setViewport(width, height); |
| 146 | mRenderState.blend().syncEnabled(); |
| 147 | } |
| 148 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 149 | void BakedOpRenderer::clearColorBuffer(const Rect& rect) { |
| 150 | if (Rect(mRenderTarget.viewportWidth, mRenderTarget.viewportHeight).contains(rect)) { |
| 151 | // Full viewport is being cleared - disable scissor |
| 152 | mRenderState.scissor().setEnabled(false); |
| 153 | } else { |
| 154 | // Requested rect is subset of viewport - scissor to it to avoid over-clearing |
| 155 | mRenderState.scissor().setEnabled(true); |
| 156 | mRenderState.scissor().set(rect.left, mRenderTarget.viewportHeight - rect.bottom, |
| 157 | rect.getWidth(), rect.getHeight()); |
| 158 | } |
| 159 | glClear(GL_COLOR_BUFFER_BIT); |
| 160 | if (!mRenderTarget.frameBufferId) mHasDrawn = true; |
| 161 | } |
| 162 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 163 | Texture* BakedOpRenderer::getTexture(const SkBitmap* bitmap) { |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 164 | Texture* texture = mRenderState.assetAtlas().getEntryTexture(bitmap->pixelRef()); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 165 | if (!texture) { |
| 166 | return mCaches.textureCache.get(bitmap); |
| 167 | } |
| 168 | return texture; |
| 169 | } |
| 170 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 171 | // clears and re-fills stencil with provided rendertarget space quads, |
| 172 | // and then put stencil into test mode |
| 173 | void BakedOpRenderer::setupStencilQuads(std::vector<Vertex>& quadVertices, |
| 174 | int incrementThreshold) { |
| 175 | mRenderState.stencil().enableWrite(incrementThreshold); |
| 176 | mRenderState.stencil().clear(); |
| 177 | Glop glop; |
| 178 | GlopBuilder(mRenderState, mCaches, &glop) |
| 179 | .setRoundRectClipState(nullptr) |
| 180 | .setMeshIndexedQuads(quadVertices.data(), quadVertices.size() / 4) |
| 181 | .setFillBlack() |
| 182 | .setTransform(Matrix4::identity(), TransformFlags::None) |
| 183 | .setModelViewIdentityEmptyBounds() |
| 184 | .build(); |
| 185 | mRenderState.render(glop, mRenderTarget.orthoMatrix); |
| 186 | mRenderState.stencil().enableTest(incrementThreshold); |
| 187 | } |
| 188 | |
| 189 | void BakedOpRenderer::setupStencilRectList(const ClipBase* clip) { |
| 190 | auto&& rectList = reinterpret_cast<const ClipRectList*>(clip)->rectList; |
| 191 | int quadCount = rectList.getTransformedRectanglesCount(); |
| 192 | std::vector<Vertex> rectangleVertices; |
| 193 | rectangleVertices.reserve(quadCount * 4); |
| 194 | for (int i = 0; i < quadCount; i++) { |
| 195 | const TransformedRectangle& tr(rectList.getTransformedRectangle(i)); |
| 196 | const Matrix4& transform = tr.getTransform(); |
| 197 | Rect bounds = tr.getBounds(); |
| 198 | if (transform.rectToRect()) { |
| 199 | // If rectToRect, can simply map bounds before storing verts |
| 200 | transform.mapRect(bounds); |
| 201 | bounds.doIntersect(clip->rect); |
| 202 | if (bounds.isEmpty()) { |
| 203 | continue; // will be outside of scissor, skip |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | rectangleVertices.push_back(Vertex{bounds.left, bounds.top}); |
| 208 | rectangleVertices.push_back(Vertex{bounds.right, bounds.top}); |
| 209 | rectangleVertices.push_back(Vertex{bounds.left, bounds.bottom}); |
| 210 | rectangleVertices.push_back(Vertex{bounds.right, bounds.bottom}); |
| 211 | |
| 212 | if (!transform.rectToRect()) { |
| 213 | // If not rectToRect, must map each point individually |
| 214 | for (auto cur = rectangleVertices.end() - 4; cur < rectangleVertices.end(); cur++) { |
| 215 | transform.mapPoint(cur->x, cur->y); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | setupStencilQuads(rectangleVertices, rectList.getTransformedRectanglesCount()); |
| 220 | } |
| 221 | |
| 222 | void BakedOpRenderer::setupStencilRegion(const ClipBase* clip) { |
| 223 | auto&& region = reinterpret_cast<const ClipRegion*>(clip)->region; |
| 224 | |
| 225 | std::vector<Vertex> regionVertices; |
| 226 | SkRegion::Cliperator it(region, clip->rect.toSkIRect()); |
| 227 | while (!it.done()) { |
| 228 | const SkIRect& r = it.rect(); |
| 229 | regionVertices.push_back(Vertex{(float)r.fLeft, (float)r.fTop}); |
| 230 | regionVertices.push_back(Vertex{(float)r.fRight, (float)r.fTop}); |
| 231 | regionVertices.push_back(Vertex{(float)r.fLeft, (float)r.fBottom}); |
| 232 | regionVertices.push_back(Vertex{(float)r.fRight, (float)r.fBottom}); |
| 233 | it.next(); |
| 234 | } |
| 235 | setupStencilQuads(regionVertices, 0); |
| 236 | } |
| 237 | |
| 238 | void BakedOpRenderer::prepareRender(const Rect* dirtyBounds, const ClipBase* clip) { |
| 239 | // prepare scissor / stencil |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 240 | mRenderState.scissor().setEnabled(clip != nullptr); |
| 241 | if (clip) { |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 242 | mRenderState.scissor().set(mRenderTarget.viewportHeight, clip->rect); |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 243 | } |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 244 | |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 245 | if (CC_LIKELY(!Properties::debugOverdraw)) { |
| 246 | // only modify stencil mode and content when it's not used for overdraw visualization |
| 247 | if (CC_UNLIKELY(clip && clip->mode != ClipMode::Rectangle)) { |
| 248 | // NOTE: this pointer check is only safe for non-rect clips, |
| 249 | // since rect clips may be created on the stack |
| 250 | if (mRenderTarget.lastStencilClip != clip) { |
| 251 | // Stencil needed, but current stencil isn't up to date |
| 252 | mRenderTarget.lastStencilClip = clip; |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 253 | |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 254 | if (mRenderTarget.frameBufferId != 0 && !mRenderTarget.stencil) { |
| 255 | OffscreenBuffer* layer = mRenderTarget.offscreenBuffer; |
| 256 | mRenderTarget.stencil = mCaches.renderBufferCache.get( |
| 257 | Stencil::getLayerStencilFormat(), |
| 258 | layer->texture.width, layer->texture.height); |
| 259 | // stencil is bound + allocated - associate it with current FBO |
| 260 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, |
| 261 | GL_RENDERBUFFER, mRenderTarget.stencil->getName()); |
| 262 | } |
| 263 | |
| 264 | if (clip->mode == ClipMode::RectangleList) { |
| 265 | setupStencilRectList(clip); |
| 266 | } else { |
| 267 | setupStencilRegion(clip); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 268 | } |
| 269 | } else { |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 270 | // stencil is up to date - just need to ensure it's enabled (since an unclipped |
| 271 | // or scissor-only clipped op may have been drawn, disabling the stencil) |
| 272 | int incrementThreshold = 0; |
| 273 | if (CC_LIKELY(clip->mode == ClipMode::RectangleList)) { |
| 274 | auto&& rectList = reinterpret_cast<const ClipRectList*>(clip)->rectList; |
| 275 | incrementThreshold = rectList.getTransformedRectanglesCount(); |
| 276 | } |
| 277 | mRenderState.stencil().enableTest(incrementThreshold); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 278 | } |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame^] | 279 | } else { |
| 280 | // either scissor or no clip, so disable stencil test |
| 281 | mRenderState.stencil().disable(); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 282 | } |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 283 | } |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 284 | |
| 285 | // dirty offscreenbuffer |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 286 | if (dirtyBounds && mRenderTarget.offscreenBuffer) { |
Chris Craik | 8d2cf94 | 2015-11-02 14:52:21 -0800 | [diff] [blame] | 287 | // register layer damage to draw-back region |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 288 | android::Rect dirty(dirtyBounds->left, dirtyBounds->top, |
| 289 | dirtyBounds->right, dirtyBounds->bottom); |
Chris Craik | 8d2cf94 | 2015-11-02 14:52:21 -0800 | [diff] [blame] | 290 | mRenderTarget.offscreenBuffer->region.orSelf(dirty); |
| 291 | } |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 294 | void BakedOpRenderer::renderGlop(const Rect* dirtyBounds, const ClipBase* clip, |
| 295 | const Glop& glop) { |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 296 | prepareRender(dirtyBounds, clip); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 297 | mRenderState.render(glop, mRenderTarget.orthoMatrix); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 298 | if (!mRenderTarget.frameBufferId) mHasDrawn = true; |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 301 | void BakedOpRenderer::renderFunctor(const FunctorOp& op, const BakedOpState& state) { |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 302 | prepareRender(&state.computedState.clippedBounds, state.computedState.getClipIfNeeded()); |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 303 | |
| 304 | DrawGlInfo info; |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 305 | auto&& clip = state.computedState.clipRect(); |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 306 | info.clipLeft = clip.left; |
| 307 | info.clipTop = clip.top; |
| 308 | info.clipRight = clip.right; |
| 309 | info.clipBottom = clip.bottom; |
| 310 | info.isLayer = offscreenRenderTarget(); |
| 311 | info.width = mRenderTarget.viewportWidth; |
| 312 | info.height = mRenderTarget.viewportHeight; |
| 313 | state.computedState.transform.copyTo(&info.transform[0]); |
| 314 | |
| 315 | mRenderState.invokeFunctor(op.functor, DrawGlInfo::kModeDraw, &info); |
| 316 | } |
| 317 | |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 318 | void BakedOpRenderer::dirtyRenderTarget(const Rect& uiDirty) { |
| 319 | if (mRenderTarget.offscreenBuffer) { |
| 320 | android::Rect dirty(uiDirty.left, uiDirty.top, uiDirty.right, uiDirty.bottom); |
| 321 | mRenderTarget.offscreenBuffer->region.orSelf(dirty); |
| 322 | } |
| 323 | } |
| 324 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 325 | } // namespace uirenderer |
| 326 | } // namespace android |