blob: 55ea93531bc7259d8604d70e5201c82e445af9a4 [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"
Chris Craik7435eb12016-01-07 17:41:40 -080022#include "utils/Macros.h"
Chris Craikb565df12015-10-05 13:00:52 -070023
24namespace android {
25namespace uirenderer {
26
27class Caches;
28struct Glop;
Chris Craik818c9fb2015-10-23 14:33:42 -070029class Layer;
Chris Craikb565df12015-10-05 13:00:52 -070030class RenderState;
Chris Craike4db79d2015-12-22 16:32:23 -080031struct ClipBase;
Chris Craikb565df12015-10-05 13:00:52 -070032
Chris Craik5854b342015-10-26 15:49:56 -070033/**
Chris Craik5854b342015-10-26 15:49:56 -070034 * Main rendering manager for a collection of work - one frame + any contained FBOs.
35 *
36 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only
37 * place where FBOs are bound, created, and destroyed.
38 *
39 * All rendering operations will be sent by the Dispatcher, a collection of static methods,
40 * which has intentionally limited access to the renderer functionality.
41 */
Chris Craikb565df12015-10-05 13:00:52 -070042class BakedOpRenderer {
43public:
Chris Craik98787e62015-11-13 10:55:30 -080044 /**
45 * Position agnostic shadow lighting info. Used with all shadow ops in scene.
46 */
47 struct LightInfo {
Chris Craik6e068c012016-01-15 16:15:30 -080048 LightInfo() : LightInfo(0, 0) {}
49 LightInfo(uint8_t ambientShadowAlpha,
John Reck7db5ffb2016-01-15 13:17:09 -080050 uint8_t spotShadowAlpha)
Chris Craik6e068c012016-01-15 16:15:30 -080051 : ambientShadowAlpha(ambientShadowAlpha)
John Reck7db5ffb2016-01-15 13:17:09 -080052 , spotShadowAlpha(spotShadowAlpha) {}
John Reck7db5ffb2016-01-15 13:17:09 -080053 uint8_t ambientShadowAlpha;
54 uint8_t spotShadowAlpha;
Chris Craik98787e62015-11-13 10:55:30 -080055 };
56
57 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque, const LightInfo& lightInfo)
Chris Craik5854b342015-10-26 15:49:56 -070058 : mRenderState(renderState)
59 , mCaches(caches)
Chris Craik98787e62015-11-13 10:55:30 -080060 , mOpaque(opaque)
61 , mLightInfo(lightInfo) {
Chris Craik5854b342015-10-26 15:49:56 -070062 }
Chris Craikb565df12015-10-05 13:00:52 -070063
Chris Craik5854b342015-10-26 15:49:56 -070064 RenderState& renderState() { return mRenderState; }
65 Caches& caches() { return mCaches; }
Chris Craik818c9fb2015-10-23 14:33:42 -070066
Chris Craik98787e62015-11-13 10:55:30 -080067 void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect);
Chris Craike4db79d2015-12-22 16:32:23 -080068 void endFrame(const Rect& repaintRect);
Chris Craik7435eb12016-01-07 17:41:40 -080069 WARN_UNUSED_RESULT OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height);
Chris Craik98787e62015-11-13 10:55:30 -080070 void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect);
Chris Craik5854b342015-10-26 15:49:56 -070071 void endLayer();
Chris Craik7435eb12016-01-07 17:41:40 -080072 WARN_UNUSED_RESULT OffscreenBuffer* copyToLayer(const Rect& area);
Chris Craikb565df12015-10-05 13:00:52 -070073
Chris Craik5854b342015-10-26 15:49:56 -070074 Texture* getTexture(const SkBitmap* bitmap);
Chris Craike29ce6f2015-12-10 16:25:13 -080075 const LightInfo& getLightInfo() const { return mLightInfo; }
Chris Craikb565df12015-10-05 13:00:52 -070076
Chris Craik15c3f192015-12-03 12:16:56 -080077 void renderGlop(const BakedOpState& state, const Glop& glop) {
Chris Craik15c3f192015-12-03 12:16:56 -080078 renderGlop(&state.computedState.clippedBounds,
Chris Craike4db79d2015-12-22 16:32:23 -080079 state.computedState.getClipIfNeeded(),
Chris Craik15c3f192015-12-03 12:16:56 -080080 glop);
81 }
Chris Craike29ce6f2015-12-10 16:25:13 -080082 void renderFunctor(const FunctorOp& op, const BakedOpState& state);
Chris Craik15c3f192015-12-03 12:16:56 -080083
Chris Craike4db79d2015-12-22 16:32:23 -080084 void renderGlop(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop);
Chris Craik15c3f192015-12-03 12:16:56 -080085 bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; }
86 void dirtyRenderTarget(const Rect& dirtyRect);
Chris Craike29ce6f2015-12-10 16:25:13 -080087 bool didDraw() const { return mHasDrawn; }
Chris Craik5854b342015-10-26 15:49:56 -070088private:
89 void setViewport(uint32_t width, uint32_t height);
Chris Craik98787e62015-11-13 10:55:30 -080090 void clearColorBuffer(const Rect& clearRect);
Chris Craike4db79d2015-12-22 16:32:23 -080091 void prepareRender(const Rect* dirtyBounds, const ClipBase* clip);
92 void setupStencilRectList(const ClipBase* clip);
93 void setupStencilRegion(const ClipBase* clip);
94 void setupStencilQuads(std::vector<Vertex>& quadVertices, int incrementThreshold);
Chris Craikb565df12015-10-05 13:00:52 -070095
Chris Craik5854b342015-10-26 15:49:56 -070096 RenderState& mRenderState;
97 Caches& mCaches;
98 bool mOpaque;
99 bool mHasDrawn = false;
Chris Craikb565df12015-10-05 13:00:52 -0700100
Chris Craik5854b342015-10-26 15:49:56 -0700101 // render target state - setup by start/end layer/frame
102 // only valid to use in between start/end pairs.
103 struct {
Chris Craike5b50192016-01-04 15:09:19 -0800104 // If not drawing to a layer: fbo = 0, offscreenBuffer = null,
105 // Otherwise these refer to currently painting layer's state
Chris Craik5854b342015-10-26 15:49:56 -0700106 GLuint frameBufferId = 0;
107 OffscreenBuffer* offscreenBuffer = nullptr;
Chris Craike5b50192016-01-04 15:09:19 -0800108
109 // Used when drawing to a layer and using stencil clipping. otherwise null.
110 RenderBuffer* stencil = nullptr;
111
112 // value representing the ClipRectList* or ClipRegion* currently stored in
113 // the stencil of the current render target
114 const ClipBase* lastStencilClip = nullptr;
115
116 // Size of renderable region in current render target - for layers, may not match actual
117 // bounds of FBO texture. offscreenBuffer->texture has this information.
Chris Craik818c9fb2015-10-23 14:33:42 -0700118 uint32_t viewportWidth = 0;
119 uint32_t viewportHeight = 0;
Chris Craike5b50192016-01-04 15:09:19 -0800120
Chris Craikb565df12015-10-05 13:00:52 -0700121 Matrix4 orthoMatrix;
Chris Craik5854b342015-10-26 15:49:56 -0700122 } mRenderTarget;
Chris Craik98787e62015-11-13 10:55:30 -0800123
124 const LightInfo mLightInfo;
Chris Craik5854b342015-10-26 15:49:56 -0700125};
Chris Craikb565df12015-10-05 13:00:52 -0700126
Chris Craikb565df12015-10-05 13:00:52 -0700127}; // namespace uirenderer
128}; // namespace android
129
130#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H