blob: 16afad44657ef155556dc78f266a679a6e338c6d [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:
38 OffscreenBuffer(Caches& caches, uint32_t textureWidth, uint32_t textureHeight,
39 uint32_t viewportWidth, uint32_t viewportHeight);
40
41 Texture texture;
42 Rect texCoords;
43 Region region;
44};
45
46/**
47 * Main rendering manager for a collection of work - one frame + any contained FBOs.
48 *
49 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only
50 * place where FBOs are bound, created, and destroyed.
51 *
52 * All rendering operations will be sent by the Dispatcher, a collection of static methods,
53 * which has intentionally limited access to the renderer functionality.
54 */
Chris Craikb565df12015-10-05 13:00:52 -070055class BakedOpRenderer {
56public:
Chris Craik5854b342015-10-26 15:49:56 -070057 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque)
58 : mRenderState(renderState)
59 , mCaches(caches)
60 , mOpaque(opaque) {
61 }
Chris Craikb565df12015-10-05 13:00:52 -070062
Chris Craik5854b342015-10-26 15:49:56 -070063 RenderState& renderState() { return mRenderState; }
64 Caches& caches() { return mCaches; }
Chris Craik818c9fb2015-10-23 14:33:42 -070065
Chris Craik5854b342015-10-26 15:49:56 -070066 void startFrame(uint32_t width, uint32_t height);
67 void endFrame();
68 OffscreenBuffer* startLayer(uint32_t width, uint32_t height);
69 void endLayer();
Chris Craikb565df12015-10-05 13:00:52 -070070
Chris Craik5854b342015-10-26 15:49:56 -070071 Texture* getTexture(const SkBitmap* bitmap);
Chris Craikb565df12015-10-05 13:00:52 -070072
Chris Craik5854b342015-10-26 15:49:56 -070073 void renderGlop(const BakedOpState& state, const Glop& glop);
74 bool didDraw() { return mHasDrawn; }
75private:
76 void setViewport(uint32_t width, uint32_t height);
Chris Craikb565df12015-10-05 13:00:52 -070077
Chris Craik5854b342015-10-26 15:49:56 -070078 RenderState& mRenderState;
79 Caches& mCaches;
80 bool mOpaque;
81 bool mHasDrawn = false;
Chris Craikb565df12015-10-05 13:00:52 -070082
Chris Craik5854b342015-10-26 15:49:56 -070083 // render target state - setup by start/end layer/frame
84 // only valid to use in between start/end pairs.
85 struct {
86 GLuint frameBufferId = 0;
87 OffscreenBuffer* offscreenBuffer = nullptr;
Chris Craik818c9fb2015-10-23 14:33:42 -070088 uint32_t viewportWidth = 0;
89 uint32_t viewportHeight = 0;
Chris Craikb565df12015-10-05 13:00:52 -070090 Matrix4 orthoMatrix;
Chris Craik5854b342015-10-26 15:49:56 -070091 } mRenderTarget;
92};
Chris Craikb565df12015-10-05 13:00:52 -070093
Chris Craik5854b342015-10-26 15:49:56 -070094/**
95 * Provides all "onBitmapOp(...)" style static methods for every op type, which convert the
96 * RecordedOps and their state to Glops, and renders them with the provided BakedOpRenderer.
97 *
98 * This dispatcher is separate from the renderer so that the dispatcher / renderer interaction is
99 * minimal through public BakedOpRenderer APIs.
100 */
101class BakedOpDispatcher {
102public:
103 // Declares all "onBitmapOp(...)" style methods for every op type
104#define DISPATCH_METHOD(Type) \
105 static void on##Type(BakedOpRenderer& renderer, const Type& op, const BakedOpState& state);
106 MAP_OPS(DISPATCH_METHOD);
Chris Craikb565df12015-10-05 13:00:52 -0700107};
108
109}; // namespace uirenderer
110}; // namespace android
111
112#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H