blob: 94806cab2fc5830902739716d7474aa4af9c9b91 [file] [log] [blame]
Chris Craikb565df12015-10-05 13:00:52 -07001/*
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
25namespace android {
26namespace uirenderer {
27
28Texture* 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
36void 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
48void 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}
60void 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 Craik6fe991e52015-10-20 09:39:42 -070077void BakedOpRenderer::onRenderNodeOp(Info&, const RenderNodeOp&, const BakedOpState&) {
Chris Craikb565df12015-10-05 13:00:52 -070078 LOG_ALWAYS_FATAL("unsupported operation");
79}
80
Chris Craik6fe991e52015-10-20 09:39:42 -070081void 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 Craikb565df12015-10-05 13:00:52 -070084 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 Craik6fe991e52015-10-20 09:39:42 -070090 GlopBuilder(info.renderState, info.caches, &glop)
Chris Craikb565df12015-10-05 13:00:52 -070091 .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 Craik6fe991e52015-10-20 09:39:42 -070097 info.renderGlop(state, glop);
Chris Craikb565df12015-10-05 13:00:52 -070098}
99
Chris Craik6fe991e52015-10-20 09:39:42 -0700100void BakedOpRenderer::onRectOp(Info& info, const RectOp& op, const BakedOpState& state) {
Chris Craikb565df12015-10-05 13:00:52 -0700101 Glop glop;
Chris Craik6fe991e52015-10-20 09:39:42 -0700102 GlopBuilder(info.renderState, info.caches, &glop)
Chris Craikb565df12015-10-05 13:00:52 -0700103 .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 Craik6fe991e52015-10-20 09:39:42 -0700109 info.renderGlop(state, glop);
Chris Craikb565df12015-10-05 13:00:52 -0700110}
111
Chris Craik6fe991e52015-10-20 09:39:42 -0700112void BakedOpRenderer::onSimpleRectsOp(Info& info, const SimpleRectsOp& op, const BakedOpState& state) {
Chris Craikb565df12015-10-05 13:00:52 -0700113 Glop glop;
Chris Craik6fe991e52015-10-20 09:39:42 -0700114 GlopBuilder(info.renderState, info.caches, &glop)
Chris Craikb565df12015-10-05 13:00:52 -0700115 .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 Craik6fe991e52015-10-20 09:39:42 -0700121 info.renderGlop(state, glop);
Chris Craikb565df12015-10-05 13:00:52 -0700122}
123
Chris Craik6fe991e52015-10-20 09:39:42 -0700124void BakedOpRenderer::onBeginLayerOp(Info& info, const BeginLayerOp& op, const BakedOpState& state) {
125 LOG_ALWAYS_FATAL("unsupported operation");
126}
127
128void BakedOpRenderer::onEndLayerOp(Info& info, const EndLayerOp& op, const BakedOpState& state) {
129 LOG_ALWAYS_FATAL("unsupported operation");
130}
131
132void BakedOpRenderer::onLayerOp(Info& info, const LayerOp& op, const BakedOpState& state) {
133 LOG_ALWAYS_FATAL("unsupported operation");
134}
Chris Craikb565df12015-10-05 13:00:52 -0700135
136} // namespace uirenderer
137} // namespace android