blob: 4540bec77a9e4ff01d4fbf51489f15f77806c2b2 [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
Chris Craikf57776b2013-10-25 18:30:17 -070017#define ATRACE_TAG ATRACE_TAG_VIEW
18
Romain Guyc46d07a2013-03-15 19:06:39 -070019#include <SkCanvas.h>
Chris Craik9f68c092014-01-10 10:30:57 -080020#include <algorithm>
Romain Guyc46d07a2013-03-15 19:06:39 -070021
Chris Craikf57776b2013-10-25 18:30:17 -070022#include <utils/Trace.h>
23
Chris Craikc3566d02013-02-04 16:16:33 -080024#include "Debug.h"
Chris Craik0776a602013-02-14 15:36:01 -080025#include "DisplayList.h"
26#include "DisplayListOp.h"
Chris Craik0776a602013-02-14 15:36:01 -080027
28namespace android {
29namespace uirenderer {
30
Chris Craik3f0854292014-04-15 16:18:08 -070031DisplayListData::DisplayListData()
32 : projectionReceiveIndex(-1)
Chris Craik3f0854292014-04-15 16:18:08 -070033 , hasDrawOps(false) {
John Reck087bc0c2014-04-04 16:20:08 -070034}
35
36DisplayListData::~DisplayListData() {
37 cleanupResources();
38}
39
John Reck44fd8d22014-02-26 11:00:11 -080040void DisplayListData::cleanupResources() {
John Recka35778c72014-11-06 09:45:10 -080041 ResourceCache& resourceCache = ResourceCache::getInstance();
42 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080043
44 for (size_t i = 0; i < bitmapResources.size(); i++) {
John Recka35778c72014-11-06 09:45:10 -080045 resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
John Reck44fd8d22014-02-26 11:00:11 -080046 }
47
John Reck44fd8d22014-02-26 11:00:11 -080048 for (size_t i = 0; i < patchResources.size(); i++) {
John Recka35778c72014-11-06 09:45:10 -080049 resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
John Reck44fd8d22014-02-26 11:00:11 -080050 }
51
John Recka35778c72014-11-06 09:45:10 -080052 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080053
Derek Sollenbergeree248592015-02-12 14:10:21 -050054 for (size_t i = 0; i < pathResources.size(); i++) {
55 const SkPath* path = pathResources.itemAt(i);
56 if (path->unique() && Caches::hasInstance()) {
57 Caches::getInstance().pathCache.removeDeferred(path);
58 }
59 delete path;
60 }
61
John Reck44fd8d22014-02-26 11:00:11 -080062 bitmapResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080063 patchResources.clear();
Derek Sollenbergeree248592015-02-12 14:10:21 -050064 pathResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080065 paints.clear();
66 regions.clear();
John Reck44fd8d22014-02-26 11:00:11 -080067}
68
Chris Craik8afd0f22014-08-21 17:41:57 -070069size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
John Reck087bc0c2014-04-04 16:20:08 -070070 mReferenceHolders.push(op->renderNode());
Chris Craik8afd0f22014-08-21 17:41:57 -070071 return mChildren.add(op);
John Reck087bc0c2014-04-04 16:20:08 -070072}
73
Chris Craik0776a602013-02-14 15:36:01 -080074}; // namespace uirenderer
75}; // namespace android