Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 17 | #include <SkCanvas.h> |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 18 | #include <algorithm> |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 19 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 20 | #include <utils/Trace.h> |
| 21 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 22 | #include "DamageAccumulator.h" |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 23 | #include "Debug.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 24 | #include "DisplayList.h" |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 25 | #include "OpDumper.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 26 | #include "RecordedOp.h" |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 27 | #include "RenderNode.h" |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 28 | #include "VectorDrawable.h" |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 29 | #include "renderthread/CanvasContext.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | namespace uirenderer { |
| 33 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 34 | DisplayList::DisplayList() |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 35 | : projectionReceiveIndex(-1) |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 36 | , stdAllocator(allocator) |
| 37 | , chunks(stdAllocator) |
| 38 | , ops(stdAllocator) |
| 39 | , children(stdAllocator) |
| 40 | , bitmapResources(stdAllocator) |
| 41 | , pathResources(stdAllocator) |
| 42 | , patchResources(stdAllocator) |
| 43 | , paints(stdAllocator) |
| 44 | , regions(stdAllocator) |
| 45 | , referenceHolders(stdAllocator) |
| 46 | , functors(stdAllocator) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 47 | , vectorDrawables(stdAllocator) {} |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 48 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 49 | DisplayList::~DisplayList() { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 50 | cleanupResources(); |
| 51 | } |
| 52 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 53 | void DisplayList::cleanupResources() { |
John Reck | 4a4bc89 | 2015-10-12 07:38:22 -0700 | [diff] [blame] | 54 | if (CC_UNLIKELY(patchResources.size())) { |
| 55 | ResourceCache& resourceCache = ResourceCache::getInstance(); |
| 56 | resourceCache.lock(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 57 | |
John Reck | 4a4bc89 | 2015-10-12 07:38:22 -0700 | [diff] [blame] | 58 | for (size_t i = 0; i < patchResources.size(); i++) { |
| 59 | resourceCache.decrementRefcountLocked(patchResources[i]); |
| 60 | } |
| 61 | |
| 62 | resourceCache.unlock(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 65 | for (size_t i = 0; i < pathResources.size(); i++) { |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 66 | const SkPath* path = pathResources[i]; |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 67 | if (path->unique() && Caches::hasInstance()) { |
| 68 | Caches::getInstance().pathCache.removeDeferred(path); |
| 69 | } |
| 70 | delete path; |
| 71 | } |
| 72 | |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 73 | for (auto& iter : functors) { |
| 74 | if (iter.listener) { |
| 75 | iter.listener->onGlFunctorReleased(iter.functor); |
| 76 | } |
| 77 | } |
| 78 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 79 | patchResources.clear(); |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 80 | pathResources.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 81 | paints.clear(); |
| 82 | regions.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 85 | size_t DisplayList::addChild(NodeOpType* op) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 86 | referenceHolders.push_back(op->renderNode); |
| 87 | size_t index = children.size(); |
| 88 | children.push_back(op); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 89 | return index; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 92 | void DisplayList::syncContents() { |
| 93 | for (auto& iter : functors) { |
| 94 | (*iter.functor)(DrawGlInfo::kModeSync, nullptr); |
| 95 | } |
| 96 | for (auto& vectorDrawable : vectorDrawables) { |
| 97 | vectorDrawable->syncProperties(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | void DisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) { |
| 102 | for (auto&& child : children) { |
| 103 | updateFn(child->renderNode); |
| 104 | } |
| 105 | } |
| 106 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 107 | bool DisplayList::prepareListAndChildren( |
| 108 | TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer, |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 109 | std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) { |
Derek Sollenberger | b7d34b6 | 2016-11-04 10:46:18 -0400 | [diff] [blame] | 110 | info.prepareTextures = info.canvasContext.pinImages(bitmapResources); |
| 111 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 112 | for (auto&& op : children) { |
| 113 | RenderNode* childNode = op->renderNode; |
| 114 | info.damageAccumulator->pushTransform(&op->localMatrix); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 115 | bool childFunctorsNeedLayer = |
| 116 | functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip; |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 117 | childFn(childNode, observer, info, childFunctorsNeedLayer); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 118 | info.damageAccumulator->popTransform(); |
| 119 | } |
| 120 | |
| 121 | bool isDirty = false; |
| 122 | for (auto& vectorDrawable : vectorDrawables) { |
| 123 | // If any vector drawable in the display list needs update, damage the node. |
| 124 | if (vectorDrawable->isDirty()) { |
| 125 | isDirty = true; |
| 126 | } |
| 127 | vectorDrawable->setPropertyChangeWillBeConsumed(true); |
| 128 | } |
| 129 | return isDirty; |
| 130 | } |
| 131 | |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 132 | void DisplayList::output(std::ostream& output, uint32_t level) { |
| 133 | for (auto&& op : getOps()) { |
| 134 | OpDumper::dump(*op, output, level + 1); |
| 135 | if (op->opId == RecordedOpId::RenderNodeOp) { |
| 136 | auto rnOp = reinterpret_cast<const RenderNodeOp*>(op); |
| 137 | rnOp->renderNode->output(output, level + 1); |
| 138 | } else { |
| 139 | output << std::endl; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 144 | }; // namespace uirenderer |
| 145 | }; // namespace android |