blob: 0ff101c6b2b40ac987511bac0c14b5c65b83fd27 [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)
Chris Craik5e00c7c2016-07-06 16:10:09 -070047 , vectorDrawables(stdAllocator) {
John Reck087bc0c2014-04-04 16:20:08 -070048}
49
Chris Craik003cc3d2015-10-16 10:24:55 -070050DisplayList::~DisplayList() {
John Reck087bc0c2014-04-04 16:20:08 -070051 cleanupResources();
52}
53
Chris Craik003cc3d2015-10-16 10:24:55 -070054void DisplayList::cleanupResources() {
John Reck4a4bc892015-10-12 07:38:22 -070055 if (CC_UNLIKELY(patchResources.size())) {
56 ResourceCache& resourceCache = ResourceCache::getInstance();
57 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080058
John Reck4a4bc892015-10-12 07:38:22 -070059 for (size_t i = 0; i < patchResources.size(); i++) {
60 resourceCache.decrementRefcountLocked(patchResources[i]);
61 }
62
63 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080064 }
65
Derek Sollenbergeree248592015-02-12 14:10:21 -050066 for (size_t i = 0; i < pathResources.size(); i++) {
John Reck272a6852015-07-29 16:48:58 -070067 const SkPath* path = pathResources[i];
Derek Sollenbergeree248592015-02-12 14:10:21 -050068 if (path->unique() && Caches::hasInstance()) {
69 Caches::getInstance().pathCache.removeDeferred(path);
70 }
71 delete path;
72 }
73
John Reckcd1c3eb2016-04-14 10:38:54 -070074 for (auto& iter : functors) {
75 if (iter.listener) {
76 iter.listener->onGlFunctorReleased(iter.functor);
77 }
78 }
79
John Reck44fd8d22014-02-26 11:00:11 -080080 patchResources.clear();
Derek Sollenbergeree248592015-02-12 14:10:21 -050081 pathResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080082 paints.clear();
83 regions.clear();
John Reck44fd8d22014-02-26 11:00:11 -080084}
85
Chris Craik003cc3d2015-10-16 10:24:55 -070086size_t DisplayList::addChild(NodeOpType* op) {
Chris Craikb36af872015-10-16 14:23:12 -070087 referenceHolders.push_back(op->renderNode);
88 size_t index = children.size();
89 children.push_back(op);
John Reck272a6852015-07-29 16:48:58 -070090 return index;
John Reck087bc0c2014-04-04 16:20:08 -070091}
92
Derek Sollenberger0df62092016-09-27 16:04:42 -040093void DisplayList::syncContents() {
94 for (auto& iter : functors) {
95 (*iter.functor)(DrawGlInfo::kModeSync, nullptr);
96 }
97 for (auto& vectorDrawable : vectorDrawables) {
98 vectorDrawable->syncProperties();
99 }
100}
101
102void DisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) {
103 for (auto&& child : children) {
104 updateFn(child->renderNode);
105 }
106}
107
John Reck2de950d2017-01-25 10:58:30 -0800108bool DisplayList::prepareListAndChildren(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
109 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);
115 bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip;
John Reck2de950d2017-01-25 10:58:30 -0800116 childFn(childNode, observer, info, childFunctorsNeedLayer);
Derek Sollenberger0df62092016-09-27 16:04:42 -0400117 info.damageAccumulator->popTransform();
118 }
119
120 bool isDirty = false;
121 for (auto& vectorDrawable : vectorDrawables) {
122 // If any vector drawable in the display list needs update, damage the node.
123 if (vectorDrawable->isDirty()) {
124 isDirty = true;
125 }
126 vectorDrawable->setPropertyChangeWillBeConsumed(true);
127 }
128 return isDirty;
129}
130
Stan Ilievd2172372017-02-09 16:59:27 -0500131void DisplayList::output(std::ostream& output, uint32_t level) {
132 for (auto&& op : getOps()) {
133 OpDumper::dump(*op, output, level + 1);
134 if (op->opId == RecordedOpId::RenderNodeOp) {
135 auto rnOp = reinterpret_cast<const RenderNodeOp*>(op);
136 rnOp->renderNode->output(output, level + 1);
137 } else {
138 output << std::endl;
139 }
140 }
141}
142
Chris Craik0776a602013-02-14 15:36:01 -0800143}; // namespace uirenderer
144}; // namespace android