blob: 0af9420533ebaf14c0c89ec2da11f4b11985bd15 [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"
24#include "DisplayListOp.h"
Chris Craik0776a602013-02-14 15:36:01 -080025
26namespace android {
27namespace uirenderer {
28
Chris Craik3f0854292014-04-15 16:18:08 -070029DisplayListData::DisplayListData()
30 : projectionReceiveIndex(-1)
Chris Craik3f0854292014-04-15 16:18:08 -070031 , hasDrawOps(false) {
John Reck087bc0c2014-04-04 16:20:08 -070032}
33
34DisplayListData::~DisplayListData() {
35 cleanupResources();
36}
37
John Reck44fd8d22014-02-26 11:00:11 -080038void DisplayListData::cleanupResources() {
John Recka35778c72014-11-06 09:45:10 -080039 ResourceCache& resourceCache = ResourceCache::getInstance();
40 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080041
John Reck44fd8d22014-02-26 11:00:11 -080042 for (size_t i = 0; i < patchResources.size(); i++) {
John Reck272a6852015-07-29 16:48:58 -070043 resourceCache.decrementRefcountLocked(patchResources[i]);
John Reck44fd8d22014-02-26 11:00:11 -080044 }
45
John Recka35778c72014-11-06 09:45:10 -080046 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080047
Derek Sollenbergeree248592015-02-12 14:10:21 -050048 for (size_t i = 0; i < pathResources.size(); i++) {
John Reck272a6852015-07-29 16:48:58 -070049 const SkPath* path = pathResources[i];
Derek Sollenbergeree248592015-02-12 14:10:21 -050050 if (path->unique() && Caches::hasInstance()) {
51 Caches::getInstance().pathCache.removeDeferred(path);
52 }
53 delete path;
54 }
55
John Reck44fd8d22014-02-26 11:00:11 -080056 patchResources.clear();
Derek Sollenbergeree248592015-02-12 14:10:21 -050057 pathResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080058 paints.clear();
59 regions.clear();
John Reck44fd8d22014-02-26 11:00:11 -080060}
61
Chris Craik8afd0f22014-08-21 17:41:57 -070062size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
John Reck272a6852015-07-29 16:48:58 -070063 mReferenceHolders.push_back(op->renderNode());
64 size_t index = mChildren.size();
65 mChildren.push_back(op);
66 return index;
John Reck087bc0c2014-04-04 16:20:08 -070067}
68
Chris Craik0776a602013-02-14 15:36:01 -080069}; // namespace uirenderer
70}; // namespace android