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 | |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 17 | #pragma once |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 18 | |
| 19 | #include "BakedOpState.h" |
John Reck | d9d7f12 | 2018-05-03 14:40:56 -0700 | [diff] [blame^] | 20 | #include "Lighting.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 21 | #include "Matrix.h" |
Chris Craik | 7435eb1 | 2016-01-07 17:41:40 -0800 | [diff] [blame] | 22 | #include "utils/Macros.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | |
| 27 | class Caches; |
| 28 | struct Glop; |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 29 | class Layer; |
Mike Reed | 8cafcc6 | 2018-05-03 11:32:46 -0400 | [diff] [blame] | 30 | struct RenderBuffer; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 31 | class RenderState; |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 32 | struct ClipBase; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 33 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 34 | /** |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 35 | * Main rendering manager for a collection of work - one frame + any contained FBOs. |
| 36 | * |
| 37 | * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only |
| 38 | * place where FBOs are bound, created, and destroyed. |
| 39 | * |
| 40 | * All rendering operations will be sent by the Dispatcher, a collection of static methods, |
| 41 | * which has intentionally limited access to the renderer functionality. |
| 42 | */ |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 43 | class BakedOpRenderer { |
| 44 | public: |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 45 | typedef void (*GlopReceiver)(BakedOpRenderer&, const Rect*, const ClipBase*, const Glop&); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 46 | |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 47 | BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque, bool wideColorGamut, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 48 | const LightInfo& lightInfo) |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 49 | : mGlopReceiver(DefaultGlopReceiver) |
| 50 | , mRenderState(renderState) |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 51 | , mCaches(caches) |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 52 | , mOpaque(opaque) |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 53 | , mWideColorGamut(wideColorGamut) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 54 | , mLightInfo(lightInfo) {} |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 55 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 56 | RenderState& renderState() { return mRenderState; } |
| 57 | Caches& caches() { return mCaches; } |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 58 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 59 | void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 60 | void endFrame(const Rect& repaintRect); |
Chris Craik | 7435eb1 | 2016-01-07 17:41:40 -0800 | [diff] [blame] | 61 | WARN_UNUSED_RESULT OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height); |
Chris Craik | 74af6e2 | 2016-04-05 13:18:56 -0700 | [diff] [blame] | 62 | void recycleTemporaryLayer(OffscreenBuffer* offscreenBuffer); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 63 | void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 64 | void endLayer(); |
Chris Craik | 7435eb1 | 2016-01-07 17:41:40 -0800 | [diff] [blame] | 65 | WARN_UNUSED_RESULT OffscreenBuffer* copyToLayer(const Rect& area); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 66 | |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 67 | Texture* getTexture(Bitmap* 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) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 71 | renderGlop(&state.computedState.clippedBounds, state.computedState.getClipIfNeeded(), glop); |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 72 | } |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 73 | void renderFunctor(const FunctorOp& op, const BakedOpState& state); |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 74 | |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 75 | void renderGlop(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop) { |
| 76 | mGlopReceiver(*this, dirtyBounds, clip, glop); |
| 77 | } |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 78 | bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; } |
| 79 | void dirtyRenderTarget(const Rect& dirtyRect); |
Chris Craik | e29ce6f | 2015-12-10 16:25:13 -0800 | [diff] [blame] | 80 | bool didDraw() const { return mHasDrawn; } |
Chris Craik | 1dfa070 | 2016-03-04 15:59:24 -0800 | [diff] [blame] | 81 | |
| 82 | uint32_t getViewportWidth() const { return mRenderTarget.viewportWidth; } |
| 83 | uint32_t getViewportHeight() const { return mRenderTarget.viewportHeight; } |
| 84 | |
| 85 | // simple draw methods, to be used for end frame decoration |
| 86 | void drawRect(float left, float top, float right, float bottom, const SkPaint* paint) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 87 | float ltrb[4] = {left, top, right, bottom}; |
Chris Craik | 1dfa070 | 2016-03-04 15:59:24 -0800 | [diff] [blame] | 88 | drawRects(ltrb, 4, paint); |
| 89 | } |
| 90 | void drawRects(const float* rects, int count, const SkPaint* paint); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 91 | |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 92 | protected: |
| 93 | GlopReceiver mGlopReceiver; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 94 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 95 | private: |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 96 | static void DefaultGlopReceiver(BakedOpRenderer& renderer, const Rect* dirtyBounds, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 97 | const ClipBase* clip, const Glop& glop) { |
Chris Craik | 419a1e7 | 2016-03-08 16:24:12 -0800 | [diff] [blame] | 98 | renderer.renderGlopImpl(dirtyBounds, clip, glop); |
| 99 | } |
| 100 | void renderGlopImpl(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 101 | void setViewport(uint32_t width, uint32_t height); |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 102 | void clearColorBuffer(const Rect& clearRect); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 103 | void prepareRender(const Rect* dirtyBounds, const ClipBase* clip); |
| 104 | void setupStencilRectList(const ClipBase* clip); |
| 105 | void setupStencilRegion(const ClipBase* clip); |
| 106 | void setupStencilQuads(std::vector<Vertex>& quadVertices, int incrementThreshold); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 107 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 108 | RenderState& mRenderState; |
| 109 | Caches& mCaches; |
| 110 | bool mOpaque; |
Romain Guy | 07ae505 | 2017-06-13 18:25:32 -0700 | [diff] [blame] | 111 | bool mWideColorGamut; |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 112 | bool mHasDrawn = false; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 113 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 114 | // render target state - setup by start/end layer/frame |
| 115 | // only valid to use in between start/end pairs. |
| 116 | struct { |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame] | 117 | // If not drawing to a layer: fbo = 0, offscreenBuffer = null, |
| 118 | // Otherwise these refer to currently painting layer's state |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 119 | GLuint frameBufferId = 0; |
| 120 | OffscreenBuffer* offscreenBuffer = nullptr; |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame] | 121 | |
| 122 | // Used when drawing to a layer and using stencil clipping. otherwise null. |
| 123 | RenderBuffer* stencil = nullptr; |
| 124 | |
| 125 | // value representing the ClipRectList* or ClipRegion* currently stored in |
| 126 | // the stencil of the current render target |
| 127 | const ClipBase* lastStencilClip = nullptr; |
| 128 | |
| 129 | // Size of renderable region in current render target - for layers, may not match actual |
| 130 | // bounds of FBO texture. offscreenBuffer->texture has this information. |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 131 | uint32_t viewportWidth = 0; |
| 132 | uint32_t viewportHeight = 0; |
Chris Craik | e5b5019 | 2016-01-04 15:09:19 -0800 | [diff] [blame] | 133 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 134 | Matrix4 orthoMatrix; |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 135 | } mRenderTarget; |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 136 | |
| 137 | const LightInfo mLightInfo; |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 138 | }; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 139 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 140 | }; // namespace uirenderer |
| 141 | }; // namespace android |