DisplayList.cpp revision 139088228faa7f3c446af7387e017933998a5570
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 < sourcePaths.size(); i++) {
62        caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
63    }
64
65    for (size_t i = 0; i < layers.size(); i++) {
66        caches.resourceCache.decrementRefcountLocked(layers.itemAt(i));
67    }
68
69    caches.resourceCache.unlock();
70
71    for (size_t i = 0; i < paints.size(); i++) {
72        delete paints.itemAt(i);
73    }
74
75    for (size_t i = 0; i < regions.size(); i++) {
76        delete regions.itemAt(i);
77    }
78
79    for (size_t i = 0; i < paths.size(); i++) {
80        delete paths.itemAt(i);
81    }
82
83    bitmapResources.clear();
84    ownedBitmapResources.clear();
85    patchResources.clear();
86    sourcePaths.clear();
87    paints.clear();
88    regions.clear();
89    paths.clear();
90    layers.clear();
91}
92
93void DisplayListData::addChild(DrawDisplayListOp* op) {
94    LOG_ALWAYS_FATAL_IF(!op->renderNode(), "DrawDisplayListOp with no render node!");
95
96    mChildren.push(op);
97    mReferenceHolders.push(op->renderNode());
98}
99
100}; // namespace uirenderer
101}; // namespace android
102