blob: d7600db0e2551b992c6c231531fd25561da0ed6d [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/**
Chris Craik5854b342015-10-26 15:49:56 -070032 * Main rendering manager for a collection of work - one frame + any contained FBOs.
33 *
34 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only
35 * place where FBOs are bound, created, and destroyed.
36 *
37 * All rendering operations will be sent by the Dispatcher, a collection of static methods,
38 * which has intentionally limited access to the renderer functionality.
39 */
Chris Craikb565df12015-10-05 13:00:52 -070040class BakedOpRenderer {
41public:
Chris Craik98787e62015-11-13 10:55:30 -080042 /**
43 * Position agnostic shadow lighting info. Used with all shadow ops in scene.
44 */
45 struct LightInfo {
46 float lightRadius = 0;
47 uint8_t ambientShadowAlpha = 0;
48 uint8_t spotShadowAlpha = 0;
49 };
50
51 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque, const LightInfo& lightInfo)
Chris Craik5854b342015-10-26 15:49:56 -070052 : mRenderState(renderState)
53 , mCaches(caches)
Chris Craik98787e62015-11-13 10:55:30 -080054 , mOpaque(opaque)
55 , mLightInfo(lightInfo) {
Chris Craik5854b342015-10-26 15:49:56 -070056 }
Chris Craikb565df12015-10-05 13:00:52 -070057
Chris Craik5854b342015-10-26 15:49:56 -070058 RenderState& renderState() { return mRenderState; }
59 Caches& caches() { return mCaches; }
Chris Craik818c9fb2015-10-23 14:33:42 -070060
Chris Craik98787e62015-11-13 10:55:30 -080061 void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect);
Chris Craik5854b342015-10-26 15:49:56 -070062 void endFrame();
Chris Craikd3daa312015-11-06 10:59:56 -080063 OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height);
Chris Craik98787e62015-11-13 10:55:30 -080064 void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect);
Chris Craik5854b342015-10-26 15:49:56 -070065 void endLayer();
Chris Craikb565df12015-10-05 13:00:52 -070066
Chris Craik5854b342015-10-26 15:49:56 -070067 Texture* getTexture(const SkBitmap* bitmap);
Chris Craik98787e62015-11-13 10:55:30 -080068 const LightInfo& getLightInfo() { return mLightInfo; }
Chris Craikb565df12015-10-05 13:00:52 -070069
Chris Craik15c3f192015-12-03 12:16:56 -080070 void renderGlop(const BakedOpState& state, const Glop& glop) {
71 bool useScissor = state.computedState.clipSideFlags != OpClipSideFlags::None;
72 renderGlop(&state.computedState.clippedBounds,
73 useScissor ? &state.computedState.clipRect : nullptr,
74 glop);
75 }
76
77 void renderGlop(const Rect* dirtyBounds, const Rect* clip, const Glop& glop);
78 bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; }
79 void dirtyRenderTarget(const Rect& dirtyRect);
Chris Craik5854b342015-10-26 15:49:56 -070080 bool didDraw() { return mHasDrawn; }
81private:
82 void setViewport(uint32_t width, uint32_t height);
Chris Craik98787e62015-11-13 10:55:30 -080083 void clearColorBuffer(const Rect& clearRect);
Chris Craikb565df12015-10-05 13:00:52 -070084
Chris Craik5854b342015-10-26 15:49:56 -070085 RenderState& mRenderState;
86 Caches& mCaches;
87 bool mOpaque;
88 bool mHasDrawn = false;
Chris Craikb565df12015-10-05 13:00:52 -070089
Chris Craik5854b342015-10-26 15:49:56 -070090 // render target state - setup by start/end layer/frame
91 // only valid to use in between start/end pairs.
92 struct {
93 GLuint frameBufferId = 0;
94 OffscreenBuffer* offscreenBuffer = nullptr;
Chris Craik818c9fb2015-10-23 14:33:42 -070095 uint32_t viewportWidth = 0;
96 uint32_t viewportHeight = 0;
Chris Craikb565df12015-10-05 13:00:52 -070097 Matrix4 orthoMatrix;
Chris Craik5854b342015-10-26 15:49:56 -070098 } mRenderTarget;
Chris Craik98787e62015-11-13 10:55:30 -080099
100 const LightInfo mLightInfo;
Chris Craik5854b342015-10-26 15:49:56 -0700101};
Chris Craikb565df12015-10-05 13:00:52 -0700102
Chris Craikb565df12015-10-05 13:00:52 -0700103}; // namespace uirenderer
104}; // namespace android
105
106#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H