DisplayList.cpp revision 003cc3dec8e2a92e51086fbcd5ee1bb236efa701
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 "RenderNode.h"
25
26#if HWUI_NEW_OPS
27#include "RecordedOp.h"
28#else
29#include "DisplayListOp.h"
30#endif
31
32namespace android {
33namespace uirenderer {
34
35DisplayList::DisplayList()
36        : projectionReceiveIndex(-1)
37        , hasDrawOps(false) {
38}
39
40DisplayList::~DisplayList() {
41    cleanupResources();
42}
43
44void DisplayList::cleanupResources() {
45    if (CC_UNLIKELY(patchResources.size())) {
46        ResourceCache& resourceCache = ResourceCache::getInstance();
47        resourceCache.lock();
48
49        for (size_t i = 0; i < patchResources.size(); i++) {
50            resourceCache.decrementRefcountLocked(patchResources[i]);
51        }
52
53        resourceCache.unlock();
54    }
55
56    for (size_t i = 0; i < pathResources.size(); i++) {
57        const SkPath* path = pathResources[i];
58        if (path->unique() && Caches::hasInstance()) {
59            Caches::getInstance().pathCache.removeDeferred(path);
60        }
61        delete path;
62    }
63
64    patchResources.clear();
65    pathResources.clear();
66    paints.clear();
67    regions.clear();
68}
69
70size_t DisplayList::addChild(NodeOpType* op) {
71    mReferenceHolders.push_back(op->renderNode);
72    size_t index = mChildren.size();
73    mChildren.push_back(op);
74    return index;
75}
76
77}; // namespace uirenderer
78}; // namespace android
79