Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 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 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_VIEW |
| 18 | |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 19 | #include <SkCanvas.h> |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 20 | #include <algorithm> |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 21 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 22 | #include <utils/Trace.h> |
| 23 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 24 | #include "Debug.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 25 | #include "DisplayList.h" |
| 26 | #include "DisplayListOp.h" |
| 27 | #include "DisplayListLogBuffer.h" |
| 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame^] | 32 | DisplayListData::DisplayListData() : projectionReceiveIndex(-1), functorCount(0), hasDrawOps(false) { |
| 33 | } |
| 34 | |
| 35 | DisplayListData::~DisplayListData() { |
| 36 | cleanupResources(); |
| 37 | } |
| 38 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 39 | void DisplayListData::cleanupResources() { |
| 40 | Caches& caches = Caches::getInstance(); |
| 41 | caches.unregisterFunctors(functorCount); |
| 42 | caches.resourceCache.lock(); |
| 43 | |
| 44 | for (size_t i = 0; i < bitmapResources.size(); i++) { |
| 45 | caches.resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i)); |
| 46 | } |
| 47 | |
| 48 | for (size_t i = 0; i < ownedBitmapResources.size(); i++) { |
| 49 | const SkBitmap* bitmap = ownedBitmapResources.itemAt(i); |
| 50 | caches.resourceCache.decrementRefcountLocked(bitmap); |
| 51 | caches.resourceCache.destructorLocked(bitmap); |
| 52 | } |
| 53 | |
| 54 | for (size_t i = 0; i < patchResources.size(); i++) { |
| 55 | caches.resourceCache.decrementRefcountLocked(patchResources.itemAt(i)); |
| 56 | } |
| 57 | |
| 58 | for (size_t i = 0; i < shaders.size(); i++) { |
| 59 | caches.resourceCache.decrementRefcountLocked(shaders.itemAt(i)); |
| 60 | caches.resourceCache.destructorLocked(shaders.itemAt(i)); |
| 61 | } |
| 62 | |
| 63 | for (size_t i = 0; i < sourcePaths.size(); i++) { |
| 64 | caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i)); |
| 65 | } |
| 66 | |
| 67 | for (size_t i = 0; i < layers.size(); i++) { |
| 68 | caches.resourceCache.decrementRefcountLocked(layers.itemAt(i)); |
| 69 | } |
| 70 | |
| 71 | caches.resourceCache.unlock(); |
| 72 | |
| 73 | for (size_t i = 0; i < paints.size(); i++) { |
| 74 | delete paints.itemAt(i); |
| 75 | } |
| 76 | |
| 77 | for (size_t i = 0; i < regions.size(); i++) { |
| 78 | delete regions.itemAt(i); |
| 79 | } |
| 80 | |
| 81 | for (size_t i = 0; i < paths.size(); i++) { |
| 82 | delete paths.itemAt(i); |
| 83 | } |
| 84 | |
| 85 | for (size_t i = 0; i < matrices.size(); i++) { |
| 86 | delete matrices.itemAt(i); |
| 87 | } |
| 88 | |
| 89 | bitmapResources.clear(); |
| 90 | ownedBitmapResources.clear(); |
| 91 | patchResources.clear(); |
| 92 | shaders.clear(); |
| 93 | sourcePaths.clear(); |
| 94 | paints.clear(); |
| 95 | regions.clear(); |
| 96 | paths.clear(); |
| 97 | matrices.clear(); |
| 98 | layers.clear(); |
| 99 | } |
| 100 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame^] | 101 | void DisplayListData::addChild(DrawDisplayListOp* op) { |
| 102 | LOG_ALWAYS_FATAL_IF(!op->renderNode(), "DrawDisplayListOp with no render node!"); |
| 103 | |
| 104 | mChildren.push(op); |
| 105 | mReferenceHolders.push(op->renderNode()); |
| 106 | } |
| 107 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 108 | }; // namespace uirenderer |
| 109 | }; // namespace android |