DisplayList.cpp revision 087bc0c14bdccf7c258dce0cdef46a69a839b427
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() : projectionReceiveIndex(-1), functorCount(0), hasDrawOps(false) {
33}
34
35DisplayListData::~DisplayListData() {
36    cleanupResources();
37}
38
39void 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
101void 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
108}; // namespace uirenderer
109}; // namespace android
110