blob: 895316696ef7f8375d85f93d52b220e61fb2f5b3 [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
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
Chris Craikf57776b2013-10-25 18:30:17 -070017#define ATRACE_TAG ATRACE_TAG_VIEW
18
Romain Guyc46d07a2013-03-15 19:06:39 -070019#include <SkCanvas.h>
Chris Craik9f68c092014-01-10 10:30:57 -080020#include <algorithm>
Romain Guyc46d07a2013-03-15 19:06:39 -070021
Chris Craikf57776b2013-10-25 18:30:17 -070022#include <utils/Trace.h>
23
Chris Craikc3566d02013-02-04 16:16:33 -080024#include "Debug.h"
Chris Craik0776a602013-02-14 15:36:01 -080025#include "DisplayList.h"
26#include "DisplayListOp.h"
27#include "DisplayListLogBuffer.h"
28
29namespace android {
30namespace uirenderer {
31
Chris Craik3f0854292014-04-15 16:18:08 -070032DisplayListData::DisplayListData()
33 : projectionReceiveIndex(-1)
Chris Craik3f0854292014-04-15 16:18:08 -070034 , hasDrawOps(false) {
John Reck087bc0c2014-04-04 16:20:08 -070035}
36
37DisplayListData::~DisplayListData() {
38 cleanupResources();
39}
40
John Reck44fd8d22014-02-26 11:00:11 -080041void DisplayListData::cleanupResources() {
John Recka35778c72014-11-06 09:45:10 -080042 ResourceCache& resourceCache = ResourceCache::getInstance();
43 resourceCache.lock();
John Reck44fd8d22014-02-26 11:00:11 -080044
45 for (size_t i = 0; i < bitmapResources.size(); i++) {
John Recka35778c72014-11-06 09:45:10 -080046 resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
John Reck44fd8d22014-02-26 11:00:11 -080047 }
48
49 for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
50 const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
John Recka35778c72014-11-06 09:45:10 -080051 resourceCache.decrementRefcountLocked(bitmap);
52 resourceCache.destructorLocked(bitmap);
John Reck44fd8d22014-02-26 11:00:11 -080053 }
54
55 for (size_t i = 0; i < patchResources.size(); i++) {
John Recka35778c72014-11-06 09:45:10 -080056 resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
John Reck44fd8d22014-02-26 11:00:11 -080057 }
58
John Reck44fd8d22014-02-26 11:00:11 -080059 for (size_t i = 0; i < sourcePaths.size(); i++) {
John Recka35778c72014-11-06 09:45:10 -080060 resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
John Reck44fd8d22014-02-26 11:00:11 -080061 }
62
John Recka35778c72014-11-06 09:45:10 -080063 resourceCache.unlock();
John Reck44fd8d22014-02-26 11:00:11 -080064
65 for (size_t i = 0; i < paints.size(); i++) {
66 delete paints.itemAt(i);
67 }
68
69 for (size_t i = 0; i < regions.size(); i++) {
70 delete regions.itemAt(i);
71 }
72
73 for (size_t i = 0; i < paths.size(); i++) {
74 delete paths.itemAt(i);
75 }
76
John Reck44fd8d22014-02-26 11:00:11 -080077 bitmapResources.clear();
78 ownedBitmapResources.clear();
79 patchResources.clear();
John Reck44fd8d22014-02-26 11:00:11 -080080 sourcePaths.clear();
81 paints.clear();
82 regions.clear();
83 paths.clear();
John Reck44fd8d22014-02-26 11:00:11 -080084}
85
Chris Craik8afd0f22014-08-21 17:41:57 -070086size_t DisplayListData::addChild(DrawRenderNodeOp* op) {
John Reck087bc0c2014-04-04 16:20:08 -070087 mReferenceHolders.push(op->renderNode());
Chris Craik8afd0f22014-08-21 17:41:57 -070088 return mChildren.add(op);
John Reck087bc0c2014-04-04 16:20:08 -070089}
90
Chris Craik0776a602013-02-14 15:36:01 -080091}; // namespace uirenderer
92}; // namespace android