blob: c74475516cdcff23017de9b4139806b6f72b3f9a [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
28namespace OpClipSideFlags {
John Reck1bcacfd2017-11-03 10:12:19 -070029enum {
30 None = 0x0,
31 Left = 0x1,
32 Top = 0x2,
33 Right = 0x4,
34 Bottom = 0x8,
35 Full = 0xF,
36 // ConservativeFull = 0x1F needed?
37};
Chris Craikb565df12015-10-05 13:00:52 -070038}
39
40/**
Chris Craik15c3f192015-12-03 12:16:56 -080041 * Holds a list of BakedOpStates of ops that can be drawn together
42 */
43struct MergedBakedOpList {
John Reck1bcacfd2017-11-03 10:12:19 -070044 const BakedOpState* const* states;
Chris Craik15c3f192015-12-03 12:16:56 -080045 size_t count;
46 int clipSideFlags;
47 Rect clip;
48};
49
50/**
Chris Craikb565df12015-10-05 13:00:52 -070051 * Holds the resolved clip, transform, and bounds of a recordedOp, when replayed with a snapshot
52 */
53class ResolvedRenderState {
54public:
Chris Craike4db79d2015-12-22 16:32:23 -080055 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
John Reck1bcacfd2017-11-03 10:12:19 -070056 const RecordedOp& recordedOp, bool expandForStroke,
57 bool expandForPathTexture);
Chris Craikb565df12015-10-05 13:00:52 -070058
Chris Craik4c3980b2016-03-15 14:20:18 -070059 // Constructor for unbounded ops *with* transform/clip
60 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
John Reck1bcacfd2017-11-03 10:12:19 -070061 const Matrix4& localTransform, const ClipBase* localClip);
Chris Craik4c3980b2016-03-15 14:20:18 -070062
Chris Craike4db79d2015-12-22 16:32:23 -080063 // Constructor for unbounded ops without transform/clip (namely shadows)
64 ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot);
Chris Craikd3daa312015-11-06 10:59:56 -080065
Chris Craik7435eb12016-01-07 17:41:40 -080066 // Constructor for primitive ops provided clip, and no transform
67 ResolvedRenderState(const ClipRect* viewportRect, const Rect& dstRect);
Chris Craikb87eadd2016-01-06 09:16:05 -080068
Chris Craikd7448e62015-12-15 10:34:36 -080069 Rect computeLocalSpaceClip() const {
70 Matrix4 inverse;
71 inverse.loadInverse(transform);
72
Chris Craike4db79d2015-12-22 16:32:23 -080073 Rect outClip(clipRect());
Chris Craikd7448e62015-12-15 10:34:36 -080074 inverse.mapRect(outClip);
75 return outClip;
76 }
77
John Reck1bcacfd2017-11-03 10:12:19 -070078 const Rect& clipRect() const { return clipState->rect; }
Chris Craikb87eadd2016-01-06 09:16:05 -080079
Chris Craike4db79d2015-12-22 16:32:23 -080080 bool requiresClip() const {
John Reck1bcacfd2017-11-03 10:12:19 -070081 return clipSideFlags != OpClipSideFlags::None ||
82 CC_UNLIKELY(clipState->mode != ClipMode::Rectangle);
Chris Craike4db79d2015-12-22 16:32:23 -080083 }
84
85 // returns the clip if it's needed to draw the operation, otherwise nullptr
John Reck1bcacfd2017-11-03 10:12:19 -070086 const ClipBase* getClipIfNeeded() const { return requiresClip() ? clipState : nullptr; }
Chris Craikb87eadd2016-01-06 09:16:05 -080087
88 Matrix4 transform;
Chris Craike4db79d2015-12-22 16:32:23 -080089 const ClipBase* clipState = nullptr;
Chris Craikb565df12015-10-05 13:00:52 -070090 Rect clippedBounds;
Chris Craikb87eadd2016-01-06 09:16:05 -080091 int clipSideFlags = 0;
Chris Craik678ff812016-03-01 13:27:54 -080092 const SkPath* localProjectionPathMask = nullptr;
Chris Craik80d2ade2016-03-28 12:54:07 -070093 bool opaqueOverClippedBounds = false;
Chris Craikb565df12015-10-05 13:00:52 -070094};
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 */
101class BakedOpState {
102public:
John Reck1bcacfd2017-11-03 10:12:19 -0700103 static BakedOpState* tryConstruct(LinearAllocator& allocator, Snapshot& snapshot,
104 const RecordedOp& recordedOp);
Chris Craik386aa032015-12-07 17:08:25 -0800105
John Reck1bcacfd2017-11-03 10:12:19 -0700106 static BakedOpState* tryConstructUnbounded(LinearAllocator& allocator, Snapshot& snapshot,
107 const RecordedOp& recordedOp);
Chris Craik4c3980b2016-03-15 14:20:18 -0700108
Chris Craik386aa032015-12-07 17:08:25 -0800109 enum class StrokeBehavior {
Chris Craik4c3980b2016-03-15 14:20:18 -0700110 // stroking is forced, regardless of style on paint (such as for lines)
Chris Craik386aa032015-12-07 17:08:25 -0800111 Forced,
112 // stroking is defined by style on paint
113 StyleDefined,
114 };
115
John Reck1bcacfd2017-11-03 10:12:19 -0700116 static BakedOpState* tryStrokeableOpConstruct(LinearAllocator& allocator, Snapshot& snapshot,
117 const RecordedOp& recordedOp,
118 StrokeBehavior strokeBehavior,
119 bool expandForPathTexture);
Chris Craikb565df12015-10-05 13:00:52 -0700120
John Reck1bcacfd2017-11-03 10:12:19 -0700121 static BakedOpState* tryShadowOpConstruct(LinearAllocator& allocator, Snapshot& snapshot,
122 const ShadowOp* shadowOpPtr);
Chris Craikd3daa312015-11-06 10:59:56 -0800123
John Reck1bcacfd2017-11-03 10:12:19 -0700124 static BakedOpState* directConstruct(LinearAllocator& allocator, const ClipRect* clip,
125 const Rect& dstRect, const RecordedOp& recordedOp);
Chris Craik80d2ade2016-03-28 12:54:07 -0700126
127 // Set opaqueOverClippedBounds. If this method isn't called, the op is assumed translucent.
128 void setupOpacity(const SkPaint* paint);
Chris Craikb565df12015-10-05 13:00:52 -0700129
130 // computed state:
Chris Craikb87eadd2016-01-06 09:16:05 -0800131 ResolvedRenderState computedState;
Chris Craikb565df12015-10-05 13:00:52 -0700132
133 // simple state (straight pointer/value storage):
134 const float alpha;
135 const RoundRectClipState* roundRectClipState;
Chris Craikb565df12015-10-05 13:00:52 -0700136 const RecordedOp* op;
137
138private:
John Reck7df9ff22016-02-10 16:08:08 -0800139 friend class LinearAllocator;
140
John Reck1bcacfd2017-11-03 10:12:19 -0700141 BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const RecordedOp& recordedOp,
142 bool expandForStroke, bool expandForPathTexture)
Chris Craik49b403d2017-03-06 13:51:43 -0800143 : computedState(allocator, snapshot, recordedOp, expandForStroke, expandForPathTexture)
Chris Craikb565df12015-10-05 13:00:52 -0700144 , alpha(snapshot.alpha)
145 , roundRectClipState(snapshot.roundRectClipState)
Chris Craikb565df12015-10-05 13:00:52 -0700146 , op(&recordedOp) {}
Chris Craikd3daa312015-11-06 10:59:56 -0800147
Chris Craik4c3980b2016-03-15 14:20:18 -0700148 // 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 Craike4db79d2015-12-22 16:32:23 -0800155 BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const ShadowOp* shadowOpPtr)
156 : computedState(allocator, snapshot)
Chris Craikd3daa312015-11-06 10:59:56 -0800157 , alpha(snapshot.alpha)
158 , roundRectClipState(snapshot.roundRectClipState)
Chris Craikd3daa312015-11-06 10:59:56 -0800159 , op(shadowOpPtr) {}
Chris Craikb87eadd2016-01-06 09:16:05 -0800160
Chris Craik4876de12016-02-25 16:54:08 -0800161 BakedOpState(const ClipRect* clipRect, const Rect& dstRect, const RecordedOp& recordedOp)
162 : computedState(clipRect, dstRect)
Chris Craikb87eadd2016-01-06 09:16:05 -0800163 , alpha(1.0f)
164 , roundRectClipState(nullptr)
Chris Craikb87eadd2016-01-06 09:16:05 -0800165 , op(&recordedOp) {}
Chris Craikb565df12015-10-05 13:00:52 -0700166};
167
John Reck1bcacfd2017-11-03 10:12:19 -0700168}; // namespace uirenderer
169}; // namespace android
Chris Craikb565df12015-10-05 13:00:52 -0700170
John Reck1bcacfd2017-11-03 10:12:19 -0700171#endif // ANDROID_HWUI_BAKED_OP_STATE_H