blob: 181b3433381c636da7f5179a2d451502189eac90 [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
Chris Craikc3566d02013-02-04 16:16:33 -080022#include "Debug.h"
Chris Craik0776a602013-02-14 15:36:01 -080023#include "DisplayList.h"
Chris Craikb565df12015-10-05 13:00:52 -070024#include "RenderNode.h"
25
26#if HWUI_NEW_OPS
27#include "RecordedOp.h"
28#else
Chris Craik0776a602013-02-14 15:36:01 -080029#include "DisplayListOp.h"
Chris Craikb565df12015-10-05 13:00:52 -070030#endif
Chris Craik0776a602013-02-14 15:36:01 -080031
32namespace android {
33namespace uirenderer {
34
Chris Craik003cc3d2015-10-16 10:24:55 -070035DisplayList::DisplayList()
Chris Craik3f0854292014-04-15 16:18:08 -070036 : projectionReceiveIndex(-1)
Chris Craikb36af872015-10-16 14:23:12 -070037 , stdAllocator(allocator)
38 , chunks(stdAllocator)
39 , ops(stdAllocator)
40 , children(stdAllocator)
41 , bitmapResources(stdAllocator)
42 , pathResources(stdAllocator)
43 , patchResources(stdAllocator)
44 , paints(stdAllocator)
45 , regions(stdAllocator)
46 , referenceHolders(stdAllocator)
47 , functors(stdAllocator)
Doris Liu1d8e1942016-03-02 15:16:28 -080048 , pushStagingFunctors(stdAllocator)
Chris Craik3f0854292014-04-15 16:18:08 -070049 , hasDrawOps(false) {
John Reck087bc0c2014-04-04 16:20:08 -070050}
51
Chris Craik003cc3d2015-10-16 10:24:55 -070052DisplayList::~DisplayList() {
John Reck087bc0c2014-04-04 16:20:08 -070053 cleanupResources();
54}
55
Chris Craik003cc3d2015-10-16 10:24:55 -070056void DisplayList::cleanupResources() {
John Reck4a4bc892015-10-12 07:38:22 -070057 if (CC_UNLIKELY(patchResources.size())) {
58 ResourceCache& resourceCache = ResourceCache::getInstance();
59 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080060
John Reck4a4bc892015-10-12 07:38:22 -070061 for (size_t i = 0; i < patchResources.size(); i++) {
62 resourceCache.decrementRefcountLocked(patchResources[i]);
63 }
64
65 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080066 }
67
Derek Sollenbergeree248592015-02-12 14:10:21 -050068 for (size_t i = 0; i < pathResources.size(); i++) {
John Reck272a6852015-07-29 16:48:58 -070069 const SkPath* path = pathResources[i];
Derek Sollenbergeree248592015-02-12 14:10:21 -050070 if (path->unique() && Caches::hasInstance()) {
71 Caches::getInstance().pathCache.removeDeferred(path);
72 }
73 delete path;
74 }
75
John Reck44fd8d22014-02-26 11:00:11 -080076 patchResources.clear();
Derek Sollenbergeree248592015-02-12 14:10:21 -050077 pathResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080078 paints.clear();
79 regions.clear();
John Reck44fd8d22014-02-26 11:00:11 -080080}
81
Chris Craik003cc3d2015-10-16 10:24:55 -070082size_t DisplayList::addChild(NodeOpType* op) {
Chris Craikb36af872015-10-16 14:23:12 -070083 referenceHolders.push_back(op->renderNode);
84 size_t index = children.size();
85 children.push_back(op);
John Reck272a6852015-07-29 16:48:58 -070086 return index;
John Reck087bc0c2014-04-04 16:20:08 -070087}
88
Chris Craik0776a602013-02-14 15:36:01 -080089}; // namespace uirenderer
90}; // namespace android