DisplayList.cpp revision ee248599d49a15fc207c5aeb0b90ec263cc1d600
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
28namespace android {
29namespace uirenderer {
30
31DisplayListData::DisplayListData()
32        : projectionReceiveIndex(-1)
33        , hasDrawOps(false) {
34}
35
36DisplayListData::~DisplayListData() {
37    cleanupResources();
38}
39
40void DisplayListData::cleanupResources() {
41    ResourceCache& resourceCache = ResourceCache::getInstance();
42    resourceCache.lock();
43
44    for (size_t i = 0; i < bitmapResources.size(); i++) {
45        resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
46    }
47
48    for (size_t i = 0; i < patchResources.size(); i++) {
49        resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
50    }
51
52    resourceCache.unlock();
53
54    for (size_t i = 0; i < pathResources.size(); i++) {
55        const SkPath* path = pathResources.itemAt(i);
56        if (path->unique() && Caches::hasInstance()) {
57            Caches::getInstance().pathCache.removeDeferred(path);
58        }
59        delete path;
60    }
61
62    bitmapResources.clear();
63    patchResources.clear();
64    pathResources.clear();
65    paints.clear();
66    regions.clear();
67}
68
69size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
70    mReferenceHolders.push(op->renderNode());
71    return mChildren.add(op);
72}
73
74}; // namespace uirenderer
75}; // namespace android
76