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