blob: d8932ce4631ecb01e43870b2a4140d44e8831e9c [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"
27#include "DisplayListLogBuffer.h"
28
29namespace android {
30namespace uirenderer {
31
Chris Craik3f0854292014-04-15 16:18:08 -070032DisplayListData::DisplayListData()
33 : projectionReceiveIndex(-1)
Chris Craik3f0854292014-04-15 16:18:08 -070034 , hasDrawOps(false) {
John Reck087bc0c2014-04-04 16:20:08 -070035}
36
37DisplayListData::~DisplayListData() {
38 cleanupResources();
39}
40
John Reck44fd8d22014-02-26 11:00:11 -080041void DisplayListData::cleanupResources() {
42 Caches& caches = Caches::getInstance();
John Reck09d5cdd2014-07-24 10:36:08 -070043 caches.unregisterFunctors(functors.size());
John Reck44fd8d22014-02-26 11:00:11 -080044 caches.resourceCache.lock();
45
46 for (size_t i = 0; i < bitmapResources.size(); i++) {
47 caches.resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
48 }
49
50 for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
51 const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
52 caches.resourceCache.decrementRefcountLocked(bitmap);
53 caches.resourceCache.destructorLocked(bitmap);
54 }
55
56 for (size_t i = 0; i < patchResources.size(); i++) {
57 caches.resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
58 }
59
John Reck44fd8d22014-02-26 11:00:11 -080060 for (size_t i = 0; i < sourcePaths.size(); i++) {
61 caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
62 }
63
64 for (size_t i = 0; i < layers.size(); i++) {
65 caches.resourceCache.decrementRefcountLocked(layers.itemAt(i));
66 }
67
68 caches.resourceCache.unlock();
69
70 for (size_t i = 0; i < paints.size(); i++) {
71 delete paints.itemAt(i);
72 }
73
74 for (size_t i = 0; i < regions.size(); i++) {
75 delete regions.itemAt(i);
76 }
77
78 for (size_t i = 0; i < paths.size(); i++) {
79 delete paths.itemAt(i);
80 }
81
John Reck44fd8d22014-02-26 11:00:11 -080082 bitmapResources.clear();
83 ownedBitmapResources.clear();
84 patchResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080085 sourcePaths.clear();
86 paints.clear();
87 regions.clear();
88 paths.clear();
John Reck44fd8d22014-02-26 11:00:11 -080089 layers.clear();
90}
91
Chris Craik8afd0f22014-08-21 17:41:57 -070092size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
John Reck087bc0c2014-04-04 16:20:08 -070093 mReferenceHolders.push(op->renderNode());
Chris Craik8afd0f22014-08-21 17:41:57 -070094 return mChildren.add(op);
John Reck087bc0c2014-04-04 16:20:08 -070095}
96
Chris Craik0776a602013-02-14 15:36:01 -080097}; // namespace uirenderer
98}; // namespace android