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