Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "SkiaDisplayList.h" |
| 18 | |
| 19 | #include "renderthread/CanvasContext.h" |
| 20 | #include "VectorDrawable.h" |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 21 | #include "DumpOpsCanvas.h" |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 22 | #include "SkiaPipeline.h" |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 23 | |
| 24 | #include <SkImagePriv.h> |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 25 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 29 | namespace skiapipeline { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 30 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 31 | void SkiaDisplayList::syncContents() { |
| 32 | for (auto& functor : mChildFunctors) { |
| 33 | functor.syncFunctor(); |
| 34 | } |
| 35 | for (auto& vectorDrawable : mVectorDrawables) { |
| 36 | vectorDrawable->syncProperties(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | bool SkiaDisplayList::reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) { |
Derek Sollenberger | ea1fe9b | 2017-03-01 13:02:43 -0500 | [diff] [blame] | 41 | reset(); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 42 | node->attachAvailableList(this); |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | void SkiaDisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) { |
| 47 | for (auto& child : mChildNodes) { |
| 48 | updateFn(child.getRenderNode()); |
| 49 | } |
| 50 | } |
| 51 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 52 | bool SkiaDisplayList::prepareListAndChildren(TreeObserver& observer, TreeInfo& info, |
| 53 | bool functorsNeedLayer, |
| 54 | std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) { |
Derek Sollenberger | 189e874 | 2016-11-16 16:00:17 -0500 | [diff] [blame] | 55 | // If the prepare tree is triggered by the UI thread and no previous call to |
| 56 | // pinImages has failed then we must pin all mutable images in the GPU cache |
| 57 | // until the next UI thread draw. |
| 58 | if (info.prepareTextures && !info.canvasContext.pinImages(mMutableImages)) { |
| 59 | // In the event that pinning failed we prevent future pinImage calls for the |
| 60 | // remainder of this tree traversal and also unpin any currently pinned images |
| 61 | // to free up GPU resources. |
| 62 | info.prepareTextures = false; |
| 63 | info.canvasContext.unpinImages(); |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 64 | } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 65 | |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 66 | bool hasBackwardProjectedNodesHere = false; |
| 67 | bool hasBackwardProjectedNodesSubtree= false; |
| 68 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 69 | for (auto& child : mChildNodes) { |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 70 | hasBackwardProjectedNodesHere |= child.getNodeProperties().getProjectBackwards(); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 71 | RenderNode* childNode = child.getRenderNode(); |
| 72 | Matrix4 mat4(child.getRecordedMatrix()); |
| 73 | info.damageAccumulator->pushTransform(&mat4); |
| 74 | // TODO: a layer is needed if the canvas is rotated or has a non-rect clip |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 75 | info.hasBackwardProjectedNodes = false; |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 76 | childFn(childNode, observer, info, functorsNeedLayer); |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 77 | hasBackwardProjectedNodesSubtree |= info.hasBackwardProjectedNodes; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 78 | info.damageAccumulator->popTransform(); |
| 79 | } |
| 80 | |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 81 | //The purpose of next block of code is to reset projected display list if there are no |
| 82 | //backward projected nodes. This speeds up drawing, by avoiding an extra walk of the tree |
| 83 | if (mProjectionReceiver) { |
| 84 | mProjectionReceiver->setProjectedDisplayList(hasBackwardProjectedNodesSubtree ? this : nullptr); |
| 85 | info.hasBackwardProjectedNodes = hasBackwardProjectedNodesHere; |
| 86 | } else { |
| 87 | info.hasBackwardProjectedNodes = hasBackwardProjectedNodesSubtree |
| 88 | || hasBackwardProjectedNodesHere; |
| 89 | } |
| 90 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 91 | bool isDirty = false; |
| 92 | for (auto& vectorDrawable : mVectorDrawables) { |
| 93 | // If any vector drawable in the display list needs update, damage the node. |
| 94 | if (vectorDrawable->isDirty()) { |
| 95 | isDirty = true; |
Stan Iliev | 23c38a9 | 2017-03-23 00:12:50 -0400 | [diff] [blame] | 96 | static_cast<SkiaPipeline*>(info.canvasContext.getRenderPipeline()) |
| 97 | ->getVectorDrawables()->push_back(vectorDrawable); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 98 | } |
| 99 | vectorDrawable->setPropertyChangeWillBeConsumed(true); |
| 100 | } |
| 101 | return isDirty; |
| 102 | } |
| 103 | |
Derek Sollenberger | ea1fe9b | 2017-03-01 13:02:43 -0500 | [diff] [blame] | 104 | void SkiaDisplayList::reset() { |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 105 | mProjectionReceiver = nullptr; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 106 | |
Derek Sollenberger | ea1fe9b | 2017-03-01 13:02:43 -0500 | [diff] [blame] | 107 | mDisplayList.reset(); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 108 | |
| 109 | mMutableImages.clear(); |
| 110 | mVectorDrawables.clear(); |
| 111 | mChildFunctors.clear(); |
| 112 | mChildNodes.clear(); |
| 113 | |
| 114 | projectionReceiveIndex = -1; |
| 115 | allocator.~LinearAllocator(); |
| 116 | new (&allocator) LinearAllocator(); |
| 117 | } |
| 118 | |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 119 | void SkiaDisplayList::output(std::ostream& output, uint32_t level) { |
| 120 | DumpOpsCanvas canvas(output, level, *this); |
Derek Sollenberger | ea1fe9b | 2017-03-01 13:02:43 -0500 | [diff] [blame] | 121 | mDisplayList.draw(&canvas); |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 124 | }; // namespace skiapipeline |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 125 | }; // namespace uirenderer |
| 126 | }; // namespace android |