DisplayList.cpp revision 1d8e194661085f9a18ab1b3cd12f9e19d3a86be5
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        , stdAllocator(allocator)
38        , chunks(stdAllocator)
39        , ops(stdAllocator)
40        , children(stdAllocator)
41        , bitmapResources(stdAllocator)
42        , pathResources(stdAllocator)
43        , patchResources(stdAllocator)
44        , paints(stdAllocator)
45        , regions(stdAllocator)
46        , referenceHolders(stdAllocator)
47        , functors(stdAllocator)
48        , pushStagingFunctors(stdAllocator)
49        , hasDrawOps(false) {
50}
51
52DisplayList::~DisplayList() {
53    cleanupResources();
54}
55
56void DisplayList::cleanupResources() {
57    if (CC_UNLIKELY(patchResources.size())) {
58        ResourceCache& resourceCache = ResourceCache::getInstance();
59        resourceCache.lock();
60
61        for (size_t i = 0; i < patchResources.size(); i++) {
62            resourceCache.decrementRefcountLocked(patchResources[i]);
63        }
64
65        resourceCache.unlock();
66    }
67
68    for (size_t i = 0; i < pathResources.size(); i++) {
69        const SkPath* path = pathResources[i];
70        if (path->unique() && Caches::hasInstance()) {
71            Caches::getInstance().pathCache.removeDeferred(path);
72        }
73        delete path;
74    }
75
76    patchResources.clear();
77    pathResources.clear();
78    paints.clear();
79    regions.clear();
80}
81
82size_t DisplayList::addChild(NodeOpType* op) {
83    referenceHolders.push_back(op->renderNode);
84    size_t index = children.size();
85    children.push_back(op);
86    return index;
87}
88
89}; // namespace uirenderer
90}; // namespace android
91