blob: aa87aea8b374286cb0bf695ae4f379e97e682a1b [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
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 Guyc46d07a2013-03-15 19:06:39 -070017#include <SkCanvas.h>
Chris Craik9f68c092014-01-10 10:30:57 -080018#include <algorithm>
Romain Guyc46d07a2013-03-15 19:06:39 -070019
Chris Craikf57776b2013-10-25 18:30:17 -070020#include <utils/Trace.h>
21
Derek Sollenberger0df62092016-09-27 16:04:42 -040022#include "DamageAccumulator.h"
Chris Craikc3566d02013-02-04 16:16:33 -080023#include "Debug.h"
Chris Craik0776a602013-02-14 15:36:01 -080024#include "DisplayList.h"
Stan Ilievd2172372017-02-09 16:59:27 -050025#include "OpDumper.h"
Chris Craikb565df12015-10-05 13:00:52 -070026#include "RecordedOp.h"
Chris Craik5e00c7c2016-07-06 16:10:09 -070027#include "RenderNode.h"
Derek Sollenberger0df62092016-09-27 16:04:42 -040028#include "VectorDrawable.h"
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -040029#include "renderthread/CanvasContext.h"
Chris Craik0776a602013-02-14 15:36:01 -080030
31namespace android {
32namespace uirenderer {
33
Chris Craik003cc3d2015-10-16 10:24:55 -070034DisplayList::DisplayList()
Chris Craik3f0854292014-04-15 16:18:08 -070035 : projectionReceiveIndex(-1)
Chris Craikb36af872015-10-16 14:23:12 -070036 , 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 Reck1bcacfd2017-11-03 10:12:19 -070047 , vectorDrawables(stdAllocator) {}
John Reck087bc0c2014-04-04 16:20:08 -070048
Chris Craik003cc3d2015-10-16 10:24:55 -070049DisplayList::~DisplayList() {
John Reck087bc0c2014-04-04 16:20:08 -070050 cleanupResources();
51}
52
Chris Craik003cc3d2015-10-16 10:24:55 -070053void DisplayList::cleanupResources() {
John Reck4a4bc892015-10-12 07:38:22 -070054 if (CC_UNLIKELY(patchResources.size())) {
55 ResourceCache& resourceCache = ResourceCache::getInstance();
56 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080057
John Reck4a4bc892015-10-12 07:38:22 -070058 for (size_t i = 0; i < patchResources.size(); i++) {
59 resourceCache.decrementRefcountLocked(patchResources[i]);
60 }
61
62 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080063 }
64
Derek Sollenbergeree248592015-02-12 14:10:21 -050065 for (size_t i = 0; i < pathResources.size(); i++) {
John Reck272a6852015-07-29 16:48:58 -070066 const SkPath* path = pathResources[i];
Derek Sollenbergeree248592015-02-12 14:10:21 -050067 if (path->unique() && Caches::hasInstance()) {
68 Caches::getInstance().pathCache.removeDeferred(path);
69 }
70 delete path;
71 }
72
John Reckcd1c3eb2016-04-14 10:38:54 -070073 for (auto& iter : functors) {
74 if (iter.listener) {
75 iter.listener->onGlFunctorReleased(iter.functor);
76 }
77 }
78
John Reck44fd8d22014-02-26 11:00:11 -080079 patchResources.clear();
Derek Sollenbergeree248592015-02-12 14:10:21 -050080 pathResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080081 paints.clear();
82 regions.clear();
John Reck44fd8d22014-02-26 11:00:11 -080083}
84
Chris Craik003cc3d2015-10-16 10:24:55 -070085size_t DisplayList::addChild(NodeOpType* op) {
Chris Craikb36af872015-10-16 14:23:12 -070086 referenceHolders.push_back(op->renderNode);
87 size_t index = children.size();
88 children.push_back(op);
John Reck272a6852015-07-29 16:48:58 -070089 return index;
John Reck087bc0c2014-04-04 16:20:08 -070090}
91
Derek Sollenberger0df62092016-09-27 16:04:42 -040092void 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
101void DisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) {
102 for (auto&& child : children) {
103 updateFn(child->renderNode);
104 }
105}
106
John Reck1bcacfd2017-11-03 10:12:19 -0700107bool DisplayList::prepareListAndChildren(
108 TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
John Reck2de950d2017-01-25 10:58:30 -0800109 std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) {
Derek Sollenbergerb7d34b62016-11-04 10:46:18 -0400110 info.prepareTextures = info.canvasContext.pinImages(bitmapResources);
111
Derek Sollenberger0df62092016-09-27 16:04:42 -0400112 for (auto&& op : children) {
113 RenderNode* childNode = op->renderNode;
114 info.damageAccumulator->pushTransform(&op->localMatrix);
John Reck1bcacfd2017-11-03 10:12:19 -0700115 bool childFunctorsNeedLayer =
116 functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip;
John Reck2de950d2017-01-25 10:58:30 -0800117 childFn(childNode, observer, info, childFunctorsNeedLayer);
Derek Sollenberger0df62092016-09-27 16:04:42 -0400118 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 Ilievd2172372017-02-09 16:59:27 -0500132void 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 Reck1bcacfd2017-11-03 10:12:19 -0700144}; // namespace uirenderer
145}; // namespace android