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" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 31 | DisplayListData::DisplayListData() |
| 32 | : projectionReceiveIndex(-1) |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 33 | , hasDrawOps(false) { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | DisplayListData::~DisplayListData() { |
| 37 | cleanupResources(); |
| 38 | } |
| 39 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 40 | void DisplayListData::cleanupResources() { |
John Reck | a35778c7 | 2014-11-06 09:45:10 -0800 | [diff] [blame] | 41 | ResourceCache& resourceCache = ResourceCache::getInstance(); |
| 42 | resourceCache.lock(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 43 | |
| 44 | for (size_t i = 0; i < bitmapResources.size(); i++) { |
John Reck | a35778c7 | 2014-11-06 09:45:10 -0800 | [diff] [blame] | 45 | resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i)); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 46 | } |
| 47 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 48 | for (size_t i = 0; i < patchResources.size(); i++) { |
John Reck | a35778c7 | 2014-11-06 09:45:10 -0800 | [diff] [blame] | 49 | resourceCache.decrementRefcountLocked(patchResources.itemAt(i)); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 50 | } |
| 51 | |
John Reck | a35778c7 | 2014-11-06 09:45:10 -0800 | [diff] [blame] | 52 | resourceCache.unlock(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 53 | |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame^] | 54 | for (size_t i = 0; i < pathResources.size(); i++) { |
| 55 | const SkPath* path = pathResources.itemAt(i); |
| 56 | if (path->unique() && Caches::hasInstance()) { |
| 57 | Caches::getInstance().pathCache.removeDeferred(path); |
| 58 | } |
| 59 | delete path; |
| 60 | } |
| 61 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 62 | bitmapResources.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 63 | patchResources.clear(); |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame^] | 64 | pathResources.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 65 | paints.clear(); |
| 66 | regions.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 69 | size_t DisplayListData::addChild(DrawRenderNodeOp* op) { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 70 | mReferenceHolders.push(op->renderNode()); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 71 | return mChildren.add(op); |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 74 | }; // namespace uirenderer |
| 75 | }; // namespace android |