blob: 59f0d7cc7346519645a1dc650ef96e6273578708 [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)
Chris Craik3f0854292014-04-15 16:18:08 -070048 , hasDrawOps(false) {
John Reck087bc0c2014-04-04 16:20:08 -070049}
50
Chris Craik003cc3d2015-10-16 10:24:55 -070051DisplayList::~DisplayList() {
John Reck087bc0c2014-04-04 16:20:08 -070052 cleanupResources();
53}
54
Chris Craik003cc3d2015-10-16 10:24:55 -070055void DisplayList::cleanupResources() {
John Reck4a4bc892015-10-12 07:38:22 -070056 if (CC_UNLIKELY(patchResources.size())) {
57 ResourceCache& resourceCache = ResourceCache::getInstance();
58 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080059
John Reck4a4bc892015-10-12 07:38:22 -070060 for (size_t i = 0; i < patchResources.size(); i++) {
61 resourceCache.decrementRefcountLocked(patchResources[i]);
62 }
63
64 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080065 }
66
Derek Sollenbergeree248592015-02-12 14:10:21 -050067 for (size_t i = 0; i < pathResources.size(); i++) {
John Reck272a6852015-07-29 16:48:58 -070068 const SkPath* path = pathResources[i];
Derek Sollenbergeree248592015-02-12 14:10:21 -050069 if (path->unique() && Caches::hasInstance()) {
70 Caches::getInstance().pathCache.removeDeferred(path);
71 }
72 delete path;
73 }
74
John Reck44fd8d22014-02-26 11:00:11 -080075 patchResources.clear();
Derek Sollenbergeree248592015-02-12 14:10:21 -050076 pathResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080077 paints.clear();
78 regions.clear();
John Reck44fd8d22014-02-26 11:00:11 -080079}
80
Chris Craik003cc3d2015-10-16 10:24:55 -070081size_t DisplayList::addChild(NodeOpType* op) {
Chris Craikb36af872015-10-16 14:23:12 -070082 referenceHolders.push_back(op->renderNode);
83 size_t index = children.size();
84 children.push_back(op);
John Reck272a6852015-07-29 16:48:58 -070085 return index;
John Reck087bc0c2014-04-04 16:20:08 -070086}
87
Chris Craik0776a602013-02-14 15:36:01 -080088}; // namespace uirenderer
89}; // namespace android