DisplayList.cpp revision 5e00c7ce063116c11315639f0035aca8ad73e8cc
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 "RecordedOp.h"
25#include "RenderNode.h"
26
27namespace android {
28namespace uirenderer {
29
30DisplayList::DisplayList()
31        : projectionReceiveIndex(-1)
32        , stdAllocator(allocator)
33        , chunks(stdAllocator)
34        , ops(stdAllocator)
35        , children(stdAllocator)
36        , bitmapResources(stdAllocator)
37        , pathResources(stdAllocator)
38        , patchResources(stdAllocator)
39        , paints(stdAllocator)
40        , regions(stdAllocator)
41        , referenceHolders(stdAllocator)
42        , functors(stdAllocator)
43        , vectorDrawables(stdAllocator) {
44}
45
46DisplayList::~DisplayList() {
47    cleanupResources();
48}
49
50void DisplayList::cleanupResources() {
51    if (CC_UNLIKELY(patchResources.size())) {
52        ResourceCache& resourceCache = ResourceCache::getInstance();
53        resourceCache.lock();
54
55        for (size_t i = 0; i < patchResources.size(); i++) {
56            resourceCache.decrementRefcountLocked(patchResources[i]);
57        }
58
59        resourceCache.unlock();
60    }
61
62    for (size_t i = 0; i < pathResources.size(); i++) {
63        const SkPath* path = pathResources[i];
64        if (path->unique() && Caches::hasInstance()) {
65            Caches::getInstance().pathCache.removeDeferred(path);
66        }
67        delete path;
68    }
69
70    for (auto& iter : functors) {
71        if (iter.listener) {
72            iter.listener->onGlFunctorReleased(iter.functor);
73        }
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