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