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