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 | |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 17 | #include <SkCanvas.h> |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 18 | #include <algorithm> |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 19 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 20 | #include <utils/Trace.h> |
| 21 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 22 | #include "Debug.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 23 | #include "DisplayList.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 24 | #include "RenderNode.h" |
| 25 | |
| 26 | #if HWUI_NEW_OPS |
| 27 | #include "RecordedOp.h" |
| 28 | #else |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 29 | #include "DisplayListOp.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 30 | #endif |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | namespace uirenderer { |
| 34 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 35 | DisplayList::DisplayList() |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 36 | : projectionReceiveIndex(-1) |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 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) |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 48 | , vectorDrawables(stdAllocator) |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 49 | , hasDrawOps(false) { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 52 | DisplayList::~DisplayList() { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 53 | cleanupResources(); |
| 54 | } |
| 55 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 56 | void DisplayList::cleanupResources() { |
John Reck | 4a4bc89 | 2015-10-12 07:38:22 -0700 | [diff] [blame] | 57 | if (CC_UNLIKELY(patchResources.size())) { |
| 58 | ResourceCache& resourceCache = ResourceCache::getInstance(); |
| 59 | resourceCache.lock(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 60 | |
John Reck | 4a4bc89 | 2015-10-12 07:38:22 -0700 | [diff] [blame] | 61 | for (size_t i = 0; i < patchResources.size(); i++) { |
| 62 | resourceCache.decrementRefcountLocked(patchResources[i]); |
| 63 | } |
| 64 | |
| 65 | resourceCache.unlock(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 68 | for (size_t i = 0; i < pathResources.size(); i++) { |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 69 | const SkPath* path = pathResources[i]; |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 70 | if (path->unique() && Caches::hasInstance()) { |
| 71 | Caches::getInstance().pathCache.removeDeferred(path); |
| 72 | } |
| 73 | delete path; |
| 74 | } |
| 75 | |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 76 | for (auto& iter : functors) { |
| 77 | if (iter.listener) { |
| 78 | iter.listener->onGlFunctorReleased(iter.functor); |
| 79 | } |
| 80 | } |
| 81 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 82 | patchResources.clear(); |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 83 | pathResources.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 84 | paints.clear(); |
| 85 | regions.clear(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 88 | size_t DisplayList::addChild(NodeOpType* op) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 89 | referenceHolders.push_back(op->renderNode); |
| 90 | size_t index = children.size(); |
| 91 | children.push_back(op); |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 92 | return index; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 95 | }; // namespace uirenderer |
| 96 | }; // namespace android |