DisplayList.cpp revision 0e89e2b7bcb2c035e8cee77f93120e7c5617f8d2
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        , hasDrawOps(false) {
35}
36
37DisplayListData::~DisplayListData() {
38    cleanupResources();
39}
40
41void DisplayListData::cleanupResources() {
42    Caches& caches = Caches::getInstance();
43    caches.unregisterFunctors(functors.size());
44    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
60    for (size_t i = 0; i < sourcePaths.size(); i++) {
61        caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
62    }
63
64    caches.resourceCache.unlock();
65
66    for (size_t i = 0; i < paints.size(); i++) {
67        delete paints.itemAt(i);
68    }
69
70    for (size_t i = 0; i < regions.size(); i++) {
71        delete regions.itemAt(i);
72    }
73
74    for (size_t i = 0; i < paths.size(); i++) {
75        delete paths.itemAt(i);
76    }
77
78    bitmapResources.clear();
79    ownedBitmapResources.clear();
80    patchResources.clear();
81    sourcePaths.clear();
82    paints.clear();
83    regions.clear();
84    paths.clear();
85}
86
87size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
88    mReferenceHolders.push(op->renderNode());
89    return mChildren.add(op);
90}
91
92}; // namespace uirenderer
93}; // namespace android
94