2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "BakedOpState.h"
21 #include "utils/Macros.h"
24 namespace uirenderer {
33 * Main rendering manager for a collection of work - one frame + any contained FBOs.
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.
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.
41 class BakedOpRenderer {
43 typedef void (*GlopReceiver)(BakedOpRenderer&, const Rect*, const ClipBase*, const Glop&);
45 * Position agnostic shadow lighting info. Used with all shadow ops in scene.
48 LightInfo() : LightInfo(0, 0) {}
49 LightInfo(uint8_t ambientShadowAlpha,
50 uint8_t spotShadowAlpha)
51 : ambientShadowAlpha(ambientShadowAlpha)
52 , spotShadowAlpha(spotShadowAlpha) {}
53 uint8_t ambientShadowAlpha;
54 uint8_t spotShadowAlpha;
57 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque, bool wideColorGamut,
58 const LightInfo& lightInfo)
59 : mGlopReceiver(DefaultGlopReceiver)
60 , mRenderState(renderState)
63 , mWideColorGamut(wideColorGamut)
64 , mLightInfo(lightInfo) {
67 RenderState& renderState() { return mRenderState; }
68 Caches& caches() { return mCaches; }
70 void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect);
71 void endFrame(const Rect& repaintRect);
72 WARN_UNUSED_RESULT OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height);
73 void recycleTemporaryLayer(OffscreenBuffer* offscreenBuffer);
74 void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect);
76 WARN_UNUSED_RESULT OffscreenBuffer* copyToLayer(const Rect& area);
78 Texture* getTexture(Bitmap* bitmap);
79 const LightInfo& getLightInfo() const { return mLightInfo; }
81 void renderGlop(const BakedOpState& state, const Glop& glop) {
82 renderGlop(&state.computedState.clippedBounds,
83 state.computedState.getClipIfNeeded(),
86 void renderFunctor(const FunctorOp& op, const BakedOpState& state);
88 void renderGlop(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop) {
89 mGlopReceiver(*this, dirtyBounds, clip, glop);
91 bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; }
92 void dirtyRenderTarget(const Rect& dirtyRect);
93 bool didDraw() const { return mHasDrawn; }
95 uint32_t getViewportWidth() const { return mRenderTarget.viewportWidth; }
96 uint32_t getViewportHeight() const { return mRenderTarget.viewportHeight; }
98 // simple draw methods, to be used for end frame decoration
99 void drawRect(float left, float top, float right, float bottom, const SkPaint* paint) {
100 float ltrb[4] = { left, top, right, bottom };
101 drawRects(ltrb, 4, paint);
103 void drawRects(const float* rects, int count, const SkPaint* paint);
105 GlopReceiver mGlopReceiver;
107 static void DefaultGlopReceiver(BakedOpRenderer& renderer, const Rect* dirtyBounds,
108 const ClipBase* clip, const Glop& glop) {
109 renderer.renderGlopImpl(dirtyBounds, clip, glop);
111 void renderGlopImpl(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop);
112 void setViewport(uint32_t width, uint32_t height);
113 void clearColorBuffer(const Rect& clearRect);
114 void prepareRender(const Rect* dirtyBounds, const ClipBase* clip);
115 void setupStencilRectList(const ClipBase* clip);
116 void setupStencilRegion(const ClipBase* clip);
117 void setupStencilQuads(std::vector<Vertex>& quadVertices, int incrementThreshold);
119 RenderState& mRenderState;
122 bool mWideColorGamut;
123 bool mHasDrawn = false;
125 // render target state - setup by start/end layer/frame
126 // only valid to use in between start/end pairs.
128 // If not drawing to a layer: fbo = 0, offscreenBuffer = null,
129 // Otherwise these refer to currently painting layer's state
130 GLuint frameBufferId = 0;
131 OffscreenBuffer* offscreenBuffer = nullptr;
133 // Used when drawing to a layer and using stencil clipping. otherwise null.
134 RenderBuffer* stencil = nullptr;
136 // value representing the ClipRectList* or ClipRegion* currently stored in
137 // the stencil of the current render target
138 const ClipBase* lastStencilClip = nullptr;
140 // Size of renderable region in current render target - for layers, may not match actual
141 // bounds of FBO texture. offscreenBuffer->texture has this information.
142 uint32_t viewportWidth = 0;
143 uint32_t viewportHeight = 0;
148 const LightInfo mLightInfo;
151 }; // namespace uirenderer
152 }; // namespace android