Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [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 | #include "BakedOpState.h" |
| 18 | |
| 19 | #include "ClipArea.h" |
| 20 | |
| 21 | namespace android { |
| 22 | namespace uirenderer { |
| 23 | |
| 24 | ResolvedRenderState::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 |
| 51 | if (clipState) { |
| 52 | allocator.rewindIfLastAlloc(clipState); |
| 53 | clipState = nullptr; |
| 54 | } |
| 55 | 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 | |
| 66 | ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot) { |
| 67 | transform = *snapshot.transform; |
| 68 | |
| 69 | // Since the op doesn't have known bounds, we conservatively set the mapped bounds |
| 70 | // to the current clipRect, and clipSideFlags to Full. |
| 71 | clipState = snapshot.mutateClipArea().serializeClip(allocator); |
| 72 | LOG_ALWAYS_FATAL_IF(!clipState, "clipState required"); |
| 73 | clippedBounds = clipState->rect; |
| 74 | transform.mapRect(clippedBounds); |
| 75 | clipSideFlags = OpClipSideFlags::Full; |
| 76 | } |
| 77 | |
Chris Craik | b87eadd | 2016-01-06 09:16:05 -0800 | [diff] [blame^] | 78 | ResolvedRenderState::ResolvedRenderState(const Rect& dstRect) |
| 79 | : transform(Matrix4::identity()) |
| 80 | , clipState(nullptr) |
| 81 | , clippedBounds(dstRect) |
| 82 | , clipSideFlags(OpClipSideFlags::None) {} |
| 83 | |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 84 | } // namespace uirenderer |
| 85 | } // namespace android |