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" |
| 22 | #include "renderstate/RenderState.h" |
| 23 | #include "utils/GLUtils.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | Texture* BakedOpRenderer::Info::getTexture(const SkBitmap* bitmap) { |
| 29 | Texture* texture = renderState.assetAtlas().getEntryTexture(bitmap); |
| 30 | if (!texture) { |
| 31 | return caches.textureCache.get(bitmap); |
| 32 | } |
| 33 | return texture; |
| 34 | } |
| 35 | |
| 36 | void BakedOpRenderer::Info::renderGlop(const BakedOpState& state, const Glop& glop) { |
| 37 | bool useScissor = state.computedState.clipSideFlags != OpClipSideFlags::None; |
| 38 | renderState.scissor().setEnabled(useScissor); |
| 39 | if (useScissor) { |
| 40 | const Rect& clip = state.computedState.clipRect; |
| 41 | renderState.scissor().set(clip.left, viewportHeight - clip.bottom, |
| 42 | clip.getWidth(), clip.getHeight()); |
| 43 | } |
| 44 | renderState.render(glop, orthoMatrix); |
| 45 | didDraw = true; |
| 46 | } |
| 47 | |
| 48 | void BakedOpRenderer::startFrame(Info& info) { |
| 49 | info.renderState.setViewport(info.viewportWidth, info.viewportHeight); |
| 50 | info.renderState.blend().syncEnabled(); |
| 51 | Caches::getInstance().clearGarbage(); |
| 52 | |
| 53 | if (!info.opaque) { |
| 54 | // TODO: partial invalidate! |
| 55 | info.renderState.scissor().setEnabled(false); |
| 56 | glClear(GL_COLOR_BUFFER_BIT); |
| 57 | info.didDraw = true; |
| 58 | } |
| 59 | } |
| 60 | void BakedOpRenderer::endFrame(Info& info) { |
| 61 | info.caches.pathCache.trim(); |
| 62 | info.caches.tessellationCache.trim(); |
| 63 | |
| 64 | #if DEBUG_OPENGL |
| 65 | GLUtils::dumpGLErrors(); |
| 66 | #endif |
| 67 | |
| 68 | #if DEBUG_MEMORY_USAGE |
| 69 | info.caches.dumpMemoryUsage(); |
| 70 | #else |
| 71 | if (Properties::debugLevel & kDebugMemory) { |
| 72 | info.caches.dumpMemoryUsage(); |
| 73 | } |
| 74 | #endif |
| 75 | } |
| 76 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 77 | void BakedOpRenderer::onRenderNodeOp(Info&, const RenderNodeOp&, const BakedOpState&) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 78 | LOG_ALWAYS_FATAL("unsupported operation"); |
| 79 | } |
| 80 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 81 | void BakedOpRenderer::onBitmapOp(Info& info, const BitmapOp& op, const BakedOpState& state) { |
| 82 | info.caches.textureState().activateTexture(0); // TODO: should this be automatic, and/or elsewhere? |
| 83 | Texture* texture = info.getTexture(op.bitmap); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 84 | if (!texture) return; |
| 85 | const AutoTexture autoCleanup(texture); |
| 86 | |
| 87 | const int textureFillFlags = (op.bitmap->colorType() == kAlpha_8_SkColorType) |
| 88 | ? TextureFillFlags::IsAlphaMaskTexture : TextureFillFlags::None; |
| 89 | Glop glop; |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 90 | GlopBuilder(info.renderState, info.caches, &glop) |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 91 | .setRoundRectClipState(state.roundRectClipState) |
| 92 | .setMeshTexturedUnitQuad(texture->uvMapper) |
| 93 | .setFillTexturePaint(*texture, textureFillFlags, op.paint, state.alpha) |
| 94 | .setTransform(state.computedState.transform, TransformFlags::None) |
| 95 | .setModelViewMapUnitToRectSnap(Rect(0, 0, texture->width, texture->height)) |
| 96 | .build(); |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 97 | info.renderGlop(state, glop); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 100 | void BakedOpRenderer::onRectOp(Info& info, const RectOp& op, const BakedOpState& state) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 101 | Glop glop; |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 102 | GlopBuilder(info.renderState, info.caches, &glop) |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 103 | .setRoundRectClipState(state.roundRectClipState) |
| 104 | .setMeshUnitQuad() |
| 105 | .setFillPaint(*op.paint, state.alpha) |
| 106 | .setTransform(state.computedState.transform, TransformFlags::None) |
| 107 | .setModelViewMapUnitToRect(op.unmappedBounds) |
| 108 | .build(); |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 109 | info.renderGlop(state, glop); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 112 | void BakedOpRenderer::onSimpleRectsOp(Info& info, const SimpleRectsOp& op, const BakedOpState& state) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 113 | Glop glop; |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 114 | GlopBuilder(info.renderState, info.caches, &glop) |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 115 | .setRoundRectClipState(state.roundRectClipState) |
| 116 | .setMeshIndexedQuads(&op.vertices[0], op.vertexCount / 4) |
| 117 | .setFillPaint(*op.paint, state.alpha) |
| 118 | .setTransform(state.computedState.transform, TransformFlags::None) |
| 119 | .setModelViewOffsetRect(0, 0, op.unmappedBounds) |
| 120 | .build(); |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 121 | info.renderGlop(state, glop); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 124 | void BakedOpRenderer::onBeginLayerOp(Info& info, const BeginLayerOp& op, const BakedOpState& state) { |
| 125 | LOG_ALWAYS_FATAL("unsupported operation"); |
| 126 | } |
| 127 | |
| 128 | void BakedOpRenderer::onEndLayerOp(Info& info, const EndLayerOp& op, const BakedOpState& state) { |
| 129 | LOG_ALWAYS_FATAL("unsupported operation"); |
| 130 | } |
| 131 | |
| 132 | void BakedOpRenderer::onLayerOp(Info& info, const LayerOp& op, const BakedOpState& state) { |
| 133 | LOG_ALWAYS_FATAL("unsupported operation"); |
| 134 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 135 | |
| 136 | } // namespace uirenderer |
| 137 | } // namespace android |