Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
| 26 | class Caches; |
| 27 | struct Glop; |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 28 | class Layer; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 29 | class RenderState; |
| 30 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 31 | /** |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 32 | * 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 Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 40 | class BakedOpRenderer { |
| 41 | public: |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 42 | /** |
| 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 Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 52 | : mRenderState(renderState) |
| 53 | , mCaches(caches) |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 54 | , mOpaque(opaque) |
| 55 | , mLightInfo(lightInfo) { |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 56 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 57 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 58 | RenderState& renderState() { return mRenderState; } |
| 59 | Caches& caches() { return mCaches; } |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 60 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 61 | void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 62 | void endFrame(); |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 63 | OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 64 | void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 65 | void endLayer(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 66 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 67 | Texture* getTexture(const SkBitmap* bitmap); |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame^] | 68 | const LightInfo& getLightInfo() const { return mLightInfo; } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 69 | |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 70 | 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 | } |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame^] | 76 | void renderFunctor(const FunctorOp& op, const BakedOpState& state); |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 77 | |
| 78 | void renderGlop(const Rect* dirtyBounds, const Rect* clip, const Glop& glop); |
| 79 | bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; } |
| 80 | void dirtyRenderTarget(const Rect& dirtyRect); |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame^] | 81 | bool didDraw() const { return mHasDrawn; } |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 82 | private: |
| 83 | void setViewport(uint32_t width, uint32_t height); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 84 | void clearColorBuffer(const Rect& clearRect); |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame^] | 85 | void prepareRender(const Rect* dirtyBounds, const Rect* clip); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 86 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 87 | RenderState& mRenderState; |
| 88 | Caches& mCaches; |
| 89 | bool mOpaque; |
| 90 | bool mHasDrawn = false; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 91 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 92 | // render target state - setup by start/end layer/frame |
| 93 | // only valid to use in between start/end pairs. |
| 94 | struct { |
| 95 | GLuint frameBufferId = 0; |
| 96 | OffscreenBuffer* offscreenBuffer = nullptr; |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 97 | uint32_t viewportWidth = 0; |
| 98 | uint32_t viewportHeight = 0; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 99 | Matrix4 orthoMatrix; |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 100 | } mRenderTarget; |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 101 | |
| 102 | const LightInfo mLightInfo; |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 103 | }; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 104 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 105 | }; // namespace uirenderer |
| 106 | }; // namespace android |
| 107 | |
| 108 | #endif // ANDROID_HWUI_BAKED_OP_RENDERER_H |