blob: a542c26b41b843ffefe809ce5f9f1521c94f4b6d [file] [log] [blame]
Chris Craike4db79d2015-12-22 16:32:23 -08001/*
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#include "BakedOpState.h"
18
19#include "ClipArea.h"
20
21namespace android {
22namespace uirenderer {
23
24ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
25 const RecordedOp& recordedOp, bool expandForStroke) {
26 // resolvedMatrix = parentMatrix * localMatrix
27 transform.loadMultiply(*snapshot.transform, recordedOp.localMatrix);
28
29 // resolvedClippedBounds = intersect(resolvedMatrix * opBounds, resolvedClipRect)
30 clippedBounds = recordedOp.unmappedBounds;
31 if (CC_UNLIKELY(expandForStroke)) {
32 // account for non-hairline stroke
33 clippedBounds.outset(recordedOp.paint->getStrokeWidth() * 0.5f);
34 }
35 transform.mapRect(clippedBounds);
36 if (CC_UNLIKELY(expandForStroke
37 && (!transform.isPureTranslate() || recordedOp.paint->getStrokeWidth() < 1.0f))) {
38 // account for hairline stroke when stroke may be < 1 scaled pixel
39 // Non translate || strokeWidth < 1 is conservative, but will cover all cases
40 clippedBounds.outset(0.5f);
41 }
42
43 // resolvedClipRect = intersect(parentMatrix * localClip, parentClip)
44 clipState = snapshot.mutateClipArea().serializeIntersectedClip(allocator,
45 recordedOp.localClip, *(snapshot.transform));
46 LOG_ALWAYS_FATAL_IF(!clipState, "must clip!");
47
48 const Rect& clipRect = clipState->rect;
49 if (CC_UNLIKELY(clipRect.isEmpty() || !clippedBounds.intersects(clipRect))) {
50 // Rejected based on either empty clip, or bounds not intersecting with clip
Chris Craik15f04682016-01-11 17:50:08 -080051
52 // Note: we could rewind the clipState object in situations where the clipRect is empty,
53 // but *only* if the caching logic within ClipArea was aware of the rewind.
54 clipState = nullptr;
Chris Craike4db79d2015-12-22 16:32:23 -080055 clippedBounds.setEmpty();
56 } else {
57 // Not rejected! compute true clippedBounds and clipSideFlags
58 if (clipRect.left > clippedBounds.left) clipSideFlags |= OpClipSideFlags::Left;
59 if (clipRect.top > clippedBounds.top) clipSideFlags |= OpClipSideFlags::Top;
60 if (clipRect.right < clippedBounds.right) clipSideFlags |= OpClipSideFlags::Right;
61 if (clipRect.bottom < clippedBounds.bottom) clipSideFlags |= OpClipSideFlags::Bottom;
62 clippedBounds.doIntersect(clipRect);
63 }
64}
65
Chris Craik6e068c012016-01-15 16:15:30 -080066ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot)
67 : transform(*snapshot.transform)
68 , clipState(snapshot.mutateClipArea().serializeClip(allocator))
69 , clippedBounds(clipState->rect)
70 , clipSideFlags(OpClipSideFlags::Full) {}
Chris Craike4db79d2015-12-22 16:32:23 -080071
Chris Craik7435eb12016-01-07 17:41:40 -080072ResolvedRenderState::ResolvedRenderState(const ClipRect* viewportRect, const Rect& dstRect)
Chris Craikb87eadd2016-01-06 09:16:05 -080073 : transform(Matrix4::identity())
Chris Craik7435eb12016-01-07 17:41:40 -080074 , clipState(viewportRect)
Chris Craikb87eadd2016-01-06 09:16:05 -080075 , clippedBounds(dstRect)
76 , clipSideFlags(OpClipSideFlags::None) {}
77
Chris Craike4db79d2015-12-22 16:32:23 -080078} // namespace uirenderer
79} // namespace android