blob: 4c3a2d0fb88ad709406356ff3a5982e86147cb3b [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#ifndef ANDROID_HWUI_BAKED_OP_RENDERER_H
18#define ANDROID_HWUI_BAKED_OP_RENDERER_H
19
20#include "BakedOpState.h"
21#include "Matrix.h"
22
23namespace android {
24namespace uirenderer {
25
26class Caches;
27struct Glop;
Chris Craik818c9fb2015-10-23 14:33:42 -070028class Layer;
Chris Craikb565df12015-10-05 13:00:52 -070029class RenderState;
30
Chris Craik5854b342015-10-26 15:49:56 -070031/**
32 * Lightweight alternative to Layer. Owns the persistent state of an offscreen render target, and
33 * encompasses enough information to draw it back on screen (minus paint properties, which are held
34 * by LayerOp).
35 */
36class OffscreenBuffer {
37public:
Chris Craik8d2cf942015-11-02 14:52:21 -080038 OffscreenBuffer(RenderState& renderState, Caches& caches,
39 uint32_t textureWidth, uint32_t textureHeight,
Chris Craik5854b342015-10-26 15:49:56 -070040 uint32_t viewportWidth, uint32_t viewportHeight);
Chris Craik8d2cf942015-11-02 14:52:21 -080041 ~OffscreenBuffer();
42
43 // must be called prior to rendering, to construct/update vertex buffer
44 void updateMeshFromRegion();
45
46 RenderState& renderState;
Chris Craik0b7e8242015-10-28 16:50:44 -070047 uint32_t viewportWidth;
48 uint32_t viewportHeight;
Chris Craik5854b342015-10-26 15:49:56 -070049 Texture texture;
Chris Craik8d2cf942015-11-02 14:52:21 -080050
51 // Portion of offscreen buffer that has been drawn to. Used to minimize drawing area when
52 // drawing back to screen / parent FBO.
Chris Craik5854b342015-10-26 15:49:56 -070053 Region region;
Chris Craik8d2cf942015-11-02 14:52:21 -080054 GLsizei elementCount = 0;
55 GLuint vbo = 0;
Chris Craik5854b342015-10-26 15:49:56 -070056};
57
58/**
59 * Main rendering manager for a collection of work - one frame + any contained FBOs.
60 *
61 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only
62 * place where FBOs are bound, created, and destroyed.
63 *
64 * All rendering operations will be sent by the Dispatcher, a collection of static methods,
65 * which has intentionally limited access to the renderer functionality.
66 */
Chris Craikb565df12015-10-05 13:00:52 -070067class BakedOpRenderer {
68public:
Chris Craik5854b342015-10-26 15:49:56 -070069 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque)
70 : mRenderState(renderState)
71 , mCaches(caches)
72 , mOpaque(opaque) {
73 }
Chris Craikb565df12015-10-05 13:00:52 -070074
Chris Craik8d2cf942015-11-02 14:52:21 -080075 static OffscreenBuffer* createOffscreenBuffer(RenderState& renderState,
76 uint32_t width, uint32_t height);
Chris Craik0b7e8242015-10-28 16:50:44 -070077 static void destroyOffscreenBuffer(OffscreenBuffer*);
78
Chris Craik5854b342015-10-26 15:49:56 -070079 RenderState& renderState() { return mRenderState; }
80 Caches& caches() { return mCaches; }
Chris Craik818c9fb2015-10-23 14:33:42 -070081
Chris Craik5854b342015-10-26 15:49:56 -070082 void startFrame(uint32_t width, uint32_t height);
83 void endFrame();
Chris Craikd3daa312015-11-06 10:59:56 -080084 OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height);
85 void startRepaintLayer(OffscreenBuffer* offscreenBuffer);
Chris Craik5854b342015-10-26 15:49:56 -070086 void endLayer();
Chris Craikb565df12015-10-05 13:00:52 -070087
Chris Craik5854b342015-10-26 15:49:56 -070088 Texture* getTexture(const SkBitmap* bitmap);
Chris Craikb565df12015-10-05 13:00:52 -070089
Chris Craik5854b342015-10-26 15:49:56 -070090 void renderGlop(const BakedOpState& state, const Glop& glop);
91 bool didDraw() { return mHasDrawn; }
92private:
93 void setViewport(uint32_t width, uint32_t height);
Chris Craikb565df12015-10-05 13:00:52 -070094
Chris Craik5854b342015-10-26 15:49:56 -070095 RenderState& mRenderState;
96 Caches& mCaches;
97 bool mOpaque;
98 bool mHasDrawn = false;
Chris Craikb565df12015-10-05 13:00:52 -070099
Chris Craik5854b342015-10-26 15:49:56 -0700100 // render target state - setup by start/end layer/frame
101 // only valid to use in between start/end pairs.
102 struct {
103 GLuint frameBufferId = 0;
104 OffscreenBuffer* offscreenBuffer = nullptr;
Chris Craik818c9fb2015-10-23 14:33:42 -0700105 uint32_t viewportWidth = 0;
106 uint32_t viewportHeight = 0;
Chris Craikb565df12015-10-05 13:00:52 -0700107 Matrix4 orthoMatrix;
Chris Craik5854b342015-10-26 15:49:56 -0700108 } mRenderTarget;
109};
Chris Craikb565df12015-10-05 13:00:52 -0700110
Chris Craik5854b342015-10-26 15:49:56 -0700111/**
112 * Provides all "onBitmapOp(...)" style static methods for every op type, which convert the
113 * RecordedOps and their state to Glops, and renders them with the provided BakedOpRenderer.
114 *
115 * This dispatcher is separate from the renderer so that the dispatcher / renderer interaction is
116 * minimal through public BakedOpRenderer APIs.
117 */
118class BakedOpDispatcher {
119public:
120 // Declares all "onBitmapOp(...)" style methods for every op type
121#define DISPATCH_METHOD(Type) \
122 static void on##Type(BakedOpRenderer& renderer, const Type& op, const BakedOpState& state);
123 MAP_OPS(DISPATCH_METHOD);
Chris Craikb565df12015-10-05 13:00:52 -0700124};
125
126}; // namespace uirenderer
127}; // namespace android
128
129#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H