blob: 5bd2c0a1fd5fc0ff5a4f35d18a7db19077f3c651 [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;
Chris Craike4db79d2015-12-22 16:32:23 -080030struct ClipBase;
Chris Craikb565df12015-10-05 13:00:52 -070031
Chris Craik5854b342015-10-26 15:49:56 -070032/**
Chris Craik5854b342015-10-26 15:49:56 -070033 * Main rendering manager for a collection of work - one frame + any contained FBOs.
34 *
35 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only
36 * place where FBOs are bound, created, and destroyed.
37 *
38 * All rendering operations will be sent by the Dispatcher, a collection of static methods,
39 * which has intentionally limited access to the renderer functionality.
40 */
Chris Craikb565df12015-10-05 13:00:52 -070041class BakedOpRenderer {
42public:
Chris Craik98787e62015-11-13 10:55:30 -080043 /**
44 * Position agnostic shadow lighting info. Used with all shadow ops in scene.
45 */
46 struct LightInfo {
47 float lightRadius = 0;
48 uint8_t ambientShadowAlpha = 0;
49 uint8_t spotShadowAlpha = 0;
50 };
51
52 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque, const LightInfo& lightInfo)
Chris Craik5854b342015-10-26 15:49:56 -070053 : mRenderState(renderState)
54 , mCaches(caches)
Chris Craik98787e62015-11-13 10:55:30 -080055 , mOpaque(opaque)
56 , mLightInfo(lightInfo) {
Chris Craik5854b342015-10-26 15:49:56 -070057 }
Chris Craikb565df12015-10-05 13:00:52 -070058
Chris Craik5854b342015-10-26 15:49:56 -070059 RenderState& renderState() { return mRenderState; }
60 Caches& caches() { return mCaches; }
Chris Craik818c9fb2015-10-23 14:33:42 -070061
Chris Craik98787e62015-11-13 10:55:30 -080062 void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect);
Chris Craike4db79d2015-12-22 16:32:23 -080063 void endFrame(const Rect& repaintRect);
Chris Craikd3daa312015-11-06 10:59:56 -080064 OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height);
Chris Craik98787e62015-11-13 10:55:30 -080065 void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect);
Chris Craik5854b342015-10-26 15:49:56 -070066 void endLayer();
Chris Craikb565df12015-10-05 13:00:52 -070067
Chris Craik5854b342015-10-26 15:49:56 -070068 Texture* getTexture(const SkBitmap* bitmap);
Chris Craike29ce6f2015-12-10 16:25:13 -080069 const LightInfo& getLightInfo() const { return mLightInfo; }
Chris Craikb565df12015-10-05 13:00:52 -070070
Chris Craik15c3f192015-12-03 12:16:56 -080071 void renderGlop(const BakedOpState& state, const Glop& glop) {
Chris Craik15c3f192015-12-03 12:16:56 -080072 renderGlop(&state.computedState.clippedBounds,
Chris Craike4db79d2015-12-22 16:32:23 -080073 state.computedState.getClipIfNeeded(),
Chris Craik15c3f192015-12-03 12:16:56 -080074 glop);
75 }
Chris Craike29ce6f2015-12-10 16:25:13 -080076 void renderFunctor(const FunctorOp& op, const BakedOpState& state);
Chris Craik15c3f192015-12-03 12:16:56 -080077
Chris Craike4db79d2015-12-22 16:32:23 -080078 void renderGlop(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop);
Chris Craik15c3f192015-12-03 12:16:56 -080079 bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; }
80 void dirtyRenderTarget(const Rect& dirtyRect);
Chris Craike29ce6f2015-12-10 16:25:13 -080081 bool didDraw() const { return mHasDrawn; }
Chris Craik5854b342015-10-26 15:49:56 -070082private:
83 void setViewport(uint32_t width, uint32_t height);
Chris Craik98787e62015-11-13 10:55:30 -080084 void clearColorBuffer(const Rect& clearRect);
Chris Craike4db79d2015-12-22 16:32:23 -080085 void prepareRender(const Rect* dirtyBounds, const ClipBase* clip);
86 void setupStencilRectList(const ClipBase* clip);
87 void setupStencilRegion(const ClipBase* clip);
88 void setupStencilQuads(std::vector<Vertex>& quadVertices, int incrementThreshold);
Chris Craikb565df12015-10-05 13:00:52 -070089
Chris Craik5854b342015-10-26 15:49:56 -070090 RenderState& mRenderState;
91 Caches& mCaches;
92 bool mOpaque;
93 bool mHasDrawn = false;
Chris Craikb565df12015-10-05 13:00:52 -070094
Chris Craik5854b342015-10-26 15:49:56 -070095 // render target state - setup by start/end layer/frame
96 // only valid to use in between start/end pairs.
97 struct {
98 GLuint frameBufferId = 0;
99 OffscreenBuffer* offscreenBuffer = nullptr;
Chris Craik818c9fb2015-10-23 14:33:42 -0700100 uint32_t viewportWidth = 0;
101 uint32_t viewportHeight = 0;
Chris Craikb565df12015-10-05 13:00:52 -0700102 Matrix4 orthoMatrix;
Chris Craike4db79d2015-12-22 16:32:23 -0800103 const ClipBase* lastStencilClip = nullptr;
Chris Craik5854b342015-10-26 15:49:56 -0700104 } mRenderTarget;
Chris Craik98787e62015-11-13 10:55:30 -0800105
106 const LightInfo mLightInfo;
Chris Craik5854b342015-10-26 15:49:56 -0700107};
Chris Craikb565df12015-10-05 13:00:52 -0700108
Chris Craikb565df12015-10-05 13:00:52 -0700109}; // namespace uirenderer
110}; // namespace android
111
112#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H