2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_HWUI_BAKED_OP_STATE_H
18 #define ANDROID_HWUI_BAKED_OP_STATE_H
21 #include "RecordedOp.h"
26 namespace uirenderer {
28 namespace OpClipSideFlags {
36 // ConservativeFull = 0x1F needed?
41 * Holds a list of BakedOpStates of ops that can be drawn together
43 struct MergedBakedOpList {
44 const BakedOpState*const* states;
51 * Holds the resolved clip, transform, and bounds of a recordedOp, when replayed with a snapshot
53 class ResolvedRenderState {
55 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
56 const RecordedOp& recordedOp, bool expandForStroke);
58 // Constructor for unbounded ops *with* transform/clip
59 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
60 const Matrix4& localTransform, const ClipBase* localClip);
62 // Constructor for unbounded ops without transform/clip (namely shadows)
63 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot);
65 // Constructor for primitive ops provided clip, and no transform
66 ResolvedRenderState(const ClipRect* viewportRect, const Rect& dstRect);
68 Rect computeLocalSpaceClip() const {
70 inverse.loadInverse(transform);
72 Rect outClip(clipRect());
73 inverse.mapRect(outClip);
77 const Rect& clipRect() const {
78 return clipState->rect;
81 bool requiresClip() const {
82 return clipSideFlags != OpClipSideFlags::None
83 || CC_UNLIKELY(clipState->mode != ClipMode::Rectangle);
86 // returns the clip if it's needed to draw the operation, otherwise nullptr
87 const ClipBase* getClipIfNeeded() const {
88 return requiresClip() ? clipState : nullptr;
92 const ClipBase* clipState = nullptr;
94 int clipSideFlags = 0;
95 const SkPath* localProjectionPathMask = nullptr;
96 bool opaqueOverClippedBounds = false;
100 * Self-contained op wrapper, containing all resolved state required to draw the op.
102 * Stashed pointers within all point to longer lived objects, with no ownership implied.
106 static BakedOpState* tryConstruct(LinearAllocator& allocator,
107 Snapshot& snapshot, const RecordedOp& recordedOp);
109 static BakedOpState* tryConstructUnbounded(LinearAllocator& allocator,
110 Snapshot& snapshot, const RecordedOp& recordedOp);
112 enum class StrokeBehavior {
113 // stroking is forced, regardless of style on paint (such as for lines)
115 // stroking is defined by style on paint
119 static BakedOpState* tryStrokeableOpConstruct(LinearAllocator& allocator,
120 Snapshot& snapshot, const RecordedOp& recordedOp, StrokeBehavior strokeBehavior);
122 static BakedOpState* tryShadowOpConstruct(LinearAllocator& allocator,
123 Snapshot& snapshot, const ShadowOp* shadowOpPtr);
125 static BakedOpState* directConstruct(LinearAllocator& allocator,
126 const ClipRect* clip, const Rect& dstRect, const RecordedOp& recordedOp);
128 // Set opaqueOverClippedBounds. If this method isn't called, the op is assumed translucent.
129 void setupOpacity(const SkPaint* paint);
132 ResolvedRenderState computedState;
134 // simple state (straight pointer/value storage):
136 const RoundRectClipState* roundRectClipState;
137 const RecordedOp* op;
140 friend class LinearAllocator;
142 BakedOpState(LinearAllocator& allocator, Snapshot& snapshot,
143 const RecordedOp& recordedOp, bool expandForStroke)
144 : computedState(allocator, snapshot, recordedOp, expandForStroke)
145 , alpha(snapshot.alpha)
146 , roundRectClipState(snapshot.roundRectClipState)
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)
156 BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const ShadowOp* shadowOpPtr)
157 : computedState(allocator, snapshot)
158 , alpha(snapshot.alpha)
159 , roundRectClipState(snapshot.roundRectClipState)
162 BakedOpState(const ClipRect* clipRect, const Rect& dstRect, const RecordedOp& recordedOp)
163 : computedState(clipRect, dstRect)
165 , roundRectClipState(nullptr)
169 }; // namespace uirenderer
170 }; // namespace android
172 #endif // ANDROID_HWUI_BAKED_OP_STATE_H