DisplayList.cpp revision 5a4690bf26932c0d6940e4af8516d920e09ae81a
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#include <SkCanvas.h>
18#include <algorithm>
19
20#include <utils/Trace.h>
21
22#include "Debug.h"
23#include "DisplayList.h"
24#include "DisplayListOp.h"
25
26namespace android {
27namespace uirenderer {
28
29DisplayListData::DisplayListData()
30        : projectionReceiveIndex(-1)
31        , hasDrawOps(false) {
32}
33
34DisplayListData::~DisplayListData() {
35    cleanupResources();
36}
37
38void DisplayListData::cleanupResources() {
39    ResourceCache& resourceCache = ResourceCache::getInstance();
40    resourceCache.lock();
41
42    for (size_t i = 0; i < patchResources.size(); i++) {
43        resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
44    }
45
46    resourceCache.unlock();
47
48    for (size_t i = 0; i < pathResources.size(); i++) {
49        const SkPath* path = pathResources.itemAt(i);
50        if (path->unique() && Caches::hasInstance()) {
51            Caches::getInstance().pathCache.removeDeferred(path);
52        }
53        delete path;
54    }
55
56    patchResources.clear();
57    pathResources.clear();
58    paints.clear();
59    regions.clear();
60}
61
62size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
63    mReferenceHolders.push(op->renderNode());
64    return mChildren.add(op);
65}
66
67}; // namespace uirenderer
68}; // namespace android
69