blob: e12dfbb18ea03e29813c48fe0ee6d126950df0cf [file] [log] [blame]
Chris Craikb565df12015-10-05 13:00:52 -07001/*
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
25namespace android {
26namespace uirenderer {
27
Mike Reedebf9ffc2018-05-02 11:20:38 -040028class BakedOpState;
29
Chris Craikb565df12015-10-05 13:00:52 -070030namespace OpClipSideFlags {
John Reck1bcacfd2017-11-03 10:12:19 -070031enum {
32 None = 0x0,
33 Left = 0x1,
34 Top = 0x2,
35 Right = 0x4,
36 Bottom = 0x8,
37 Full = 0xF,
38 // ConservativeFull = 0x1F needed?
39};
Chris Craikb565df12015-10-05 13:00:52 -070040}
41
42/**
Chris Craik15c3f192015-12-03 12:16:56 -080043 * Holds a list of BakedOpStates of ops that can be drawn together
44 */
45struct MergedBakedOpList {
John Reck1bcacfd2017-11-03 10:12:19 -070046 const BakedOpState* const* states;
Chris Craik15c3f192015-12-03 12:16:56 -080047 size_t count;
48 int clipSideFlags;
49 Rect clip;
50};
51
52/**
Chris Craikb565df12015-10-05 13:00:52 -070053 * Holds the resolved clip, transform, and bounds of a recordedOp, when replayed with a snapshot
54 */
55class ResolvedRenderState {
56public:
Chris Craike4db79d2015-12-22 16:32:23 -080057 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
John Reck1bcacfd2017-11-03 10:12:19 -070058 const RecordedOp& recordedOp, bool expandForStroke,
59 bool expandForPathTexture);
Chris Craikb565df12015-10-05 13:00:52 -070060
Chris Craik4c3980b2016-03-15 14:20:18 -070061 // Constructor for unbounded ops *with* transform/clip
62 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
John Reck1bcacfd2017-11-03 10:12:19 -070063 const Matrix4& localTransform, const ClipBase* localClip);
Chris Craik4c3980b2016-03-15 14:20:18 -070064
Chris Craike4db79d2015-12-22 16:32:23 -080065 // Constructor for unbounded ops without transform/clip (namely shadows)
66 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot);
Chris Craikd3daa312015-11-06 10:59:56 -080067
Chris Craik7435eb12016-01-07 17:41:40 -080068 // Constructor for primitive ops provided clip, and no transform
69 ResolvedRenderState(const ClipRect* viewportRect, const Rect& dstRect);
Chris Craikb87eadd2016-01-06 09:16:05 -080070
Chris Craikd7448e62015-12-15 10:34:36 -080071 Rect computeLocalSpaceClip() const {
72 Matrix4 inverse;
73 inverse.loadInverse(transform);
74
Chris Craike4db79d2015-12-22 16:32:23 -080075 Rect outClip(clipRect());
Chris Craikd7448e62015-12-15 10:34:36 -080076 inverse.mapRect(outClip);
77 return outClip;
78 }
79
John Reck1bcacfd2017-11-03 10:12:19 -070080 const Rect& clipRect() const { return clipState->rect; }
Chris Craikb87eadd2016-01-06 09:16:05 -080081
Chris Craike4db79d2015-12-22 16:32:23 -080082 bool requiresClip() const {
John Reck1bcacfd2017-11-03 10:12:19 -070083 return clipSideFlags != OpClipSideFlags::None ||
84 CC_UNLIKELY(clipState->mode != ClipMode::Rectangle);
Chris Craike4db79d2015-12-22 16:32:23 -080085 }
86
87 // returns the clip if it's needed to draw the operation, otherwise nullptr
John Reck1bcacfd2017-11-03 10:12:19 -070088 const ClipBase* getClipIfNeeded() const { return requiresClip() ? clipState : nullptr; }
Chris Craikb87eadd2016-01-06 09:16:05 -080089
90 Matrix4 transform;
Chris Craike4db79d2015-12-22 16:32:23 -080091 const ClipBase* clipState = nullptr;
Chris Craikb565df12015-10-05 13:00:52 -070092 Rect clippedBounds;
Chris Craikb87eadd2016-01-06 09:16:05 -080093 int clipSideFlags = 0;
Chris Craik678ff812016-03-01 13:27:54 -080094 const SkPath* localProjectionPathMask = nullptr;
Chris Craik80d2ade2016-03-28 12:54:07 -070095 bool opaqueOverClippedBounds = false;
Chris Craikb565df12015-10-05 13:00:52 -070096};
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 */
103class BakedOpState {
104public:
John Reck1bcacfd2017-11-03 10:12:19 -0700105 static BakedOpState* tryConstruct(LinearAllocator& allocator, Snapshot& snapshot,
106 const RecordedOp& recordedOp);
Chris Craik386aa032015-12-07 17:08:25 -0800107
John Reck1bcacfd2017-11-03 10:12:19 -0700108 static BakedOpState* tryConstructUnbounded(LinearAllocator& allocator, Snapshot& snapshot,
109 const RecordedOp& recordedOp);
Chris Craik4c3980b2016-03-15 14:20:18 -0700110
Chris Craik386aa032015-12-07 17:08:25 -0800111 enum class StrokeBehavior {
Chris Craik4c3980b2016-03-15 14:20:18 -0700112 // stroking is forced, regardless of style on paint (such as for lines)
Chris Craik386aa032015-12-07 17:08:25 -0800113 Forced,
114 // stroking is defined by style on paint
115 StyleDefined,
116 };
117
John Reck1bcacfd2017-11-03 10:12:19 -0700118 static BakedOpState* tryStrokeableOpConstruct(LinearAllocator& allocator, Snapshot& snapshot,
119 const RecordedOp& recordedOp,
120 StrokeBehavior strokeBehavior,
121 bool expandForPathTexture);
Chris Craikb565df12015-10-05 13:00:52 -0700122
John Reck1bcacfd2017-11-03 10:12:19 -0700123 static BakedOpState* tryShadowOpConstruct(LinearAllocator& allocator, Snapshot& snapshot,
124 const ShadowOp* shadowOpPtr);
Chris Craikd3daa312015-11-06 10:59:56 -0800125
John Reck1bcacfd2017-11-03 10:12:19 -0700126 static BakedOpState* directConstruct(LinearAllocator& allocator, const ClipRect* clip,
127 const Rect& dstRect, const RecordedOp& recordedOp);
Chris Craik80d2ade2016-03-28 12:54:07 -0700128
129 // Set opaqueOverClippedBounds. If this method isn't called, the op is assumed translucent.
130 void setupOpacity(const SkPaint* paint);
Chris Craikb565df12015-10-05 13:00:52 -0700131
132 // computed state:
Chris Craikb87eadd2016-01-06 09:16:05 -0800133 ResolvedRenderState computedState;
Chris Craikb565df12015-10-05 13:00:52 -0700134
135 // simple state (straight pointer/value storage):
136 const float alpha;
137 const RoundRectClipState* roundRectClipState;
Chris Craikb565df12015-10-05 13:00:52 -0700138 const RecordedOp* op;
139
140private:
John Reck7df9ff22016-02-10 16:08:08 -0800141 friend class LinearAllocator;
142
John Reck1bcacfd2017-11-03 10:12:19 -0700143 BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const RecordedOp& recordedOp,
144 bool expandForStroke, bool expandForPathTexture)
Chris Craik49b403d2017-03-06 13:51:43 -0800145 : computedState(allocator, snapshot, recordedOp, expandForStroke, expandForPathTexture)
Chris Craikb565df12015-10-05 13:00:52 -0700146 , alpha(snapshot.alpha)
147 , roundRectClipState(snapshot.roundRectClipState)
Chris Craikb565df12015-10-05 13:00:52 -0700148 , op(&recordedOp) {}
Chris Craikd3daa312015-11-06 10:59:56 -0800149
Chris Craik4c3980b2016-03-15 14:20:18 -0700150 // 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 Craike4db79d2015-12-22 16:32:23 -0800157 BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const ShadowOp* shadowOpPtr)
158 : computedState(allocator, snapshot)
Chris Craikd3daa312015-11-06 10:59:56 -0800159 , alpha(snapshot.alpha)
160 , roundRectClipState(snapshot.roundRectClipState)
Chris Craikd3daa312015-11-06 10:59:56 -0800161 , op(shadowOpPtr) {}
Chris Craikb87eadd2016-01-06 09:16:05 -0800162
Chris Craik4876de12016-02-25 16:54:08 -0800163 BakedOpState(const ClipRect* clipRect, const Rect& dstRect, const RecordedOp& recordedOp)
164 : computedState(clipRect, dstRect)
Chris Craikb87eadd2016-01-06 09:16:05 -0800165 , alpha(1.0f)
166 , roundRectClipState(nullptr)
Chris Craikb87eadd2016-01-06 09:16:05 -0800167 , op(&recordedOp) {}
Chris Craikb565df12015-10-05 13:00:52 -0700168};
169
John Reck1bcacfd2017-11-03 10:12:19 -0700170}; // namespace uirenderer
171}; // namespace android
Chris Craikb565df12015-10-05 13:00:52 -0700172
John Reck1bcacfd2017-11-03 10:12:19 -0700173#endif // ANDROID_HWUI_BAKED_OP_STATE_H