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_STATE_H |
| 18 | #define ANDROID_HWUI_BAKED_OP_STATE_H |
| 19 | |
| 20 | #include "Matrix.h" |
| 21 | #include "RecordedOp.h" |
| 22 | #include "Rect.h" |
| 23 | #include "Snapshot.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
Mike Reed | ebf9ffc | 2018-05-02 11:20:38 -0400 | [diff] [blame^] | 28 | class BakedOpState; |
| 29 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 30 | namespace OpClipSideFlags { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 31 | enum { |
| 32 | None = 0x0, |
| 33 | Left = 0x1, |
| 34 | Top = 0x2, |
| 35 | Right = 0x4, |
| 36 | Bottom = 0x8, |
| 37 | Full = 0xF, |
| 38 | // ConservativeFull = 0x1F needed? |
| 39 | }; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 43 | * Holds a list of BakedOpStates of ops that can be drawn together |
| 44 | */ |
| 45 | struct MergedBakedOpList { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 46 | const BakedOpState* const* states; |
Chris Craik | 15c3f19 | 2015-12-03 12:16:56 -0800 | [diff] [blame] | 47 | size_t count; |
| 48 | int clipSideFlags; |
| 49 | Rect clip; |
| 50 | }; |
| 51 | |
| 52 | /** |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 53 | * Holds the resolved clip, transform, and bounds of a recordedOp, when replayed with a snapshot |
| 54 | */ |
| 55 | class ResolvedRenderState { |
| 56 | public: |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 57 | ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 58 | const RecordedOp& recordedOp, bool expandForStroke, |
| 59 | bool expandForPathTexture); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 60 | |
Chris Craik | 4c3980b | 2016-03-15 14:20:18 -0700 | [diff] [blame] | 61 | // Constructor for unbounded ops *with* transform/clip |
| 62 | ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 63 | const Matrix4& localTransform, const ClipBase* localClip); |
Chris Craik | 4c3980b | 2016-03-15 14:20:18 -0700 | [diff] [blame] | 64 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 65 | // Constructor for unbounded ops without transform/clip (namely shadows) |
| 66 | ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot); |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 67 | |
Chris Craik | 7435eb1 | 2016-01-07 17:41:40 -0800 | [diff] [blame] | 68 | // Constructor for primitive ops provided clip, and no transform |
| 69 | ResolvedRenderState(const ClipRect* viewportRect, const Rect& dstRect); |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 70 | |
Chris Craik | d7448e6 | 2015-12-15 10:34:36 -0800 | [diff] [blame] | 71 | Rect computeLocalSpaceClip() const { |
| 72 | Matrix4 inverse; |
| 73 | inverse.loadInverse(transform); |
| 74 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 75 | Rect outClip(clipRect()); |
Chris Craik | d7448e6 | 2015-12-15 10:34:36 -0800 | [diff] [blame] | 76 | inverse.mapRect(outClip); |
| 77 | return outClip; |
| 78 | } |
| 79 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 80 | const Rect& clipRect() const { return clipState->rect; } |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 81 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 82 | bool requiresClip() const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 83 | return clipSideFlags != OpClipSideFlags::None || |
| 84 | CC_UNLIKELY(clipState->mode != ClipMode::Rectangle); |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | // returns the clip if it's needed to draw the operation, otherwise nullptr |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 88 | const ClipBase* getClipIfNeeded() const { return requiresClip() ? clipState : nullptr; } |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 89 | |
| 90 | Matrix4 transform; |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 91 | const ClipBase* clipState = nullptr; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 92 | Rect clippedBounds; |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 93 | int clipSideFlags = 0; |
Chris Craik | 678ff81 | 2016-03-01 13:27:54 -0800 | [diff] [blame] | 94 | const SkPath* localProjectionPathMask = nullptr; |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 95 | bool opaqueOverClippedBounds = false; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * Self-contained op wrapper, containing all resolved state required to draw the op. |
| 100 | * |
| 101 | * Stashed pointers within all point to longer lived objects, with no ownership implied. |
| 102 | */ |
| 103 | class BakedOpState { |
| 104 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 105 | static BakedOpState* tryConstruct(LinearAllocator& allocator, Snapshot& snapshot, |
| 106 | const RecordedOp& recordedOp); |
Chris Craik | 386aa03 | 2015-12-07 17:08:25 -0800 | [diff] [blame] | 107 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 108 | static BakedOpState* tryConstructUnbounded(LinearAllocator& allocator, Snapshot& snapshot, |
| 109 | const RecordedOp& recordedOp); |
Chris Craik | 4c3980b | 2016-03-15 14:20:18 -0700 | [diff] [blame] | 110 | |
Chris Craik | 386aa03 | 2015-12-07 17:08:25 -0800 | [diff] [blame] | 111 | enum class StrokeBehavior { |
Chris Craik | 4c3980b | 2016-03-15 14:20:18 -0700 | [diff] [blame] | 112 | // stroking is forced, regardless of style on paint (such as for lines) |
Chris Craik | 386aa03 | 2015-12-07 17:08:25 -0800 | [diff] [blame] | 113 | Forced, |
| 114 | // stroking is defined by style on paint |
| 115 | StyleDefined, |
| 116 | }; |
| 117 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 118 | static BakedOpState* tryStrokeableOpConstruct(LinearAllocator& allocator, Snapshot& snapshot, |
| 119 | const RecordedOp& recordedOp, |
| 120 | StrokeBehavior strokeBehavior, |
| 121 | bool expandForPathTexture); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 122 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 123 | static BakedOpState* tryShadowOpConstruct(LinearAllocator& allocator, Snapshot& snapshot, |
| 124 | const ShadowOp* shadowOpPtr); |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 125 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 126 | static BakedOpState* directConstruct(LinearAllocator& allocator, const ClipRect* clip, |
| 127 | const Rect& dstRect, const RecordedOp& recordedOp); |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 128 | |
| 129 | // Set opaqueOverClippedBounds. If this method isn't called, the op is assumed translucent. |
| 130 | void setupOpacity(const SkPaint* paint); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 131 | |
| 132 | // computed state: |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 133 | ResolvedRenderState computedState; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 134 | |
| 135 | // simple state (straight pointer/value storage): |
| 136 | const float alpha; |
| 137 | const RoundRectClipState* roundRectClipState; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 138 | const RecordedOp* op; |
| 139 | |
| 140 | private: |
John Reck | 7df9ff2 | 2016-02-10 16:08:08 -0800 | [diff] [blame] | 141 | friend class LinearAllocator; |
| 142 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 143 | BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const RecordedOp& recordedOp, |
| 144 | bool expandForStroke, bool expandForPathTexture) |
Chris Craik | 49b403d | 2017-03-06 13:51:43 -0800 | [diff] [blame] | 145 | : computedState(allocator, snapshot, recordedOp, expandForStroke, expandForPathTexture) |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 146 | , alpha(snapshot.alpha) |
| 147 | , roundRectClipState(snapshot.roundRectClipState) |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 148 | , op(&recordedOp) {} |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 149 | |
Chris Craik | 4c3980b | 2016-03-15 14:20:18 -0700 | [diff] [blame] | 150 | // TODO: fix this brittleness |
| 151 | BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const RecordedOp& recordedOp) |
| 152 | : computedState(allocator, snapshot, recordedOp.localMatrix, recordedOp.localClip) |
| 153 | , alpha(snapshot.alpha) |
| 154 | , roundRectClipState(snapshot.roundRectClipState) |
| 155 | , op(&recordedOp) {} |
| 156 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 157 | BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const ShadowOp* shadowOpPtr) |
| 158 | : computedState(allocator, snapshot) |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 159 | , alpha(snapshot.alpha) |
| 160 | , roundRectClipState(snapshot.roundRectClipState) |
Chris Craik | d3daa31 | 2015-11-06 10:59:56 -0800 | [diff] [blame] | 161 | , op(shadowOpPtr) {} |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 162 | |
Chris Craik | 4876de1 | 2016-02-25 16:54:08 -0800 | [diff] [blame] | 163 | BakedOpState(const ClipRect* clipRect, const Rect& dstRect, const RecordedOp& recordedOp) |
| 164 | : computedState(clipRect, dstRect) |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 165 | , alpha(1.0f) |
| 166 | , roundRectClipState(nullptr) |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame] | 167 | , op(&recordedOp) {} |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 170 | }; // namespace uirenderer |
| 171 | }; // namespace android |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 172 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 173 | #endif // ANDROID_HWUI_BAKED_OP_STATE_H |