DisplayList.cpp revision 3f085429fd47ebd32ac2463b3eae2a5a6c17be25
1/*
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
17#define ATRACE_TAG ATRACE_TAG_VIEW
18
19#include <SkCanvas.h>
20#include <algorithm>
21
22#include <utils/Trace.h>
23
24#include "Debug.h"
25#include "DisplayList.h"
26#include "DisplayListOp.h"
27#include "DisplayListLogBuffer.h"
28
29namespace android {
30namespace uirenderer {
31
32DisplayListData::DisplayListData()
33        : projectionReceiveIndex(-1)
34        , functorCount(0)
35        , hasDrawOps(false) {
36}
37
38DisplayListData::~DisplayListData() {
39    cleanupResources();
40}
41
42void DisplayListData::cleanupResources() {
43    Caches& caches = Caches::getInstance();
44    caches.unregisterFunctors(functorCount);
45    caches.resourceCache.lock();
46
47    for (size_t i = 0; i < bitmapResources.size(); i++) {
48        caches.resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
49    }
50
51    for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
52        const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
53        caches.resourceCache.decrementRefcountLocked(bitmap);
54        caches.resourceCache.destructorLocked(bitmap);
55    }
56
57    for (size_t i = 0; i < patchResources.size(); i++) {
58        caches.resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
59    }
60
61    for (size_t i = 0; i < shaders.size(); i++) {
62        caches.resourceCache.decrementRefcountLocked(shaders.itemAt(i));
63        caches.resourceCache.destructorLocked(shaders.itemAt(i));
64    }
65
66    for (size_t i = 0; i < sourcePaths.size(); i++) {
67        caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
68    }
69
70    for (size_t i = 0; i < layers.size(); i++) {
71        caches.resourceCache.decrementRefcountLocked(layers.itemAt(i));
72    }
73
74    caches.resourceCache.unlock();
75
76    for (size_t i = 0; i < paints.size(); i++) {
77        delete paints.itemAt(i);
78    }
79
80    for (size_t i = 0; i < regions.size(); i++) {
81        delete regions.itemAt(i);
82    }
83
84    for (size_t i = 0; i < paths.size(); i++) {
85        delete paths.itemAt(i);
86    }
87
88    for (size_t i = 0; i < matrices.size(); i++) {
89        delete matrices.itemAt(i);
90    }
91
92    bitmapResources.clear();
93    ownedBitmapResources.clear();
94    patchResources.clear();
95    shaders.clear();
96    sourcePaths.clear();
97    paints.clear();
98    regions.clear();
99    paths.clear();
100    matrices.clear();
101    layers.clear();
102}
103
104void DisplayListData::addChild(DrawDisplayListOp* op) {
105    LOG_ALWAYS_FATAL_IF(!op->renderNode(), "DrawDisplayListOp with no render node!");
106
107    mChildren.push(op);
108    mReferenceHolders.push(op->renderNode());
109}
110
111}; // namespace uirenderer
112}; // namespace android
113