blob: a5d8dcb3fe0fb21c3a7fda0d05dda56544f28a99 [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
John Reck087bc0c2014-04-04 16:20:08 -070032DisplayListData::DisplayListData() : projectionReceiveIndex(-1), functorCount(0), hasDrawOps(false) {
33}
34
35DisplayListData::~DisplayListData() {
36 cleanupResources();
37}
38
John Reck44fd8d22014-02-26 11:00:11 -080039void DisplayListData::cleanupResources() {
40 Caches& caches = Caches::getInstance();
41 caches.unregisterFunctors(functorCount);
42 caches.resourceCache.lock();
43
44 for (size_t i = 0; i < bitmapResources.size(); i++) {
45 caches.resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
46 }
47
48 for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
49 const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
50 caches.resourceCache.decrementRefcountLocked(bitmap);
51 caches.resourceCache.destructorLocked(bitmap);
52 }
53
54 for (size_t i = 0; i < patchResources.size(); i++) {
55 caches.resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
56 }
57
58 for (size_t i = 0; i < shaders.size(); i++) {
59 caches.resourceCache.decrementRefcountLocked(shaders.itemAt(i));
60 caches.resourceCache.destructorLocked(shaders.itemAt(i));
61 }
62
63 for (size_t i = 0; i < sourcePaths.size(); i++) {
64 caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
65 }
66
67 for (size_t i = 0; i < layers.size(); i++) {
68 caches.resourceCache.decrementRefcountLocked(layers.itemAt(i));
69 }
70
71 caches.resourceCache.unlock();
72
73 for (size_t i = 0; i < paints.size(); i++) {
74 delete paints.itemAt(i);
75 }
76
77 for (size_t i = 0; i < regions.size(); i++) {
78 delete regions.itemAt(i);
79 }
80
81 for (size_t i = 0; i < paths.size(); i++) {
82 delete paths.itemAt(i);
83 }
84
85 for (size_t i = 0; i < matrices.size(); i++) {
86 delete matrices.itemAt(i);
87 }
88
89 bitmapResources.clear();
90 ownedBitmapResources.clear();
91 patchResources.clear();
92 shaders.clear();
93 sourcePaths.clear();
94 paints.clear();
95 regions.clear();
96 paths.clear();
97 matrices.clear();
98 layers.clear();
99}
100
John Reck087bc0c2014-04-04 16:20:08 -0700101void DisplayListData::addChild(DrawDisplayListOp* op) {
102 LOG_ALWAYS_FATAL_IF(!op->renderNode(), "DrawDisplayListOp with no render node!");
103
104 mChildren.push(op);
105 mReferenceHolders.push(op->renderNode());
106}
107
Chris Craik0776a602013-02-14 15:36:01 -0800108}; // namespace uirenderer
109}; // namespace android