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 "RenderNode.h" 25 26#if HWUI_NEW_OPS 27#include "RecordedOp.h" 28#else 29#include "DisplayListOp.h" 30#endif 31 32namespace android { 33namespace uirenderer { 34 35DisplayList::DisplayList() 36 : projectionReceiveIndex(-1) 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) 48 , pushStagingFunctors(stdAllocator) 49 , hasDrawOps(false) { 50} 51 52DisplayList::~DisplayList() { 53 cleanupResources(); 54} 55 56void DisplayList::cleanupResources() { 57 if (CC_UNLIKELY(patchResources.size())) { 58 ResourceCache& resourceCache = ResourceCache::getInstance(); 59 resourceCache.lock(); 60 61 for (size_t i = 0; i < patchResources.size(); i++) { 62 resourceCache.decrementRefcountLocked(patchResources[i]); 63 } 64 65 resourceCache.unlock(); 66 } 67 68 for (size_t i = 0; i < pathResources.size(); i++) { 69 const SkPath* path = pathResources[i]; 70 if (path->unique() && Caches::hasInstance()) { 71 Caches::getInstance().pathCache.removeDeferred(path); 72 } 73 delete path; 74 } 75 76 for (auto& iter : functors) { 77 if (iter.listener) { 78 iter.listener->onGlFunctorReleased(iter.functor); 79 } 80 } 81 82 patchResources.clear(); 83 pathResources.clear(); 84 paints.clear(); 85 regions.clear(); 86} 87 88size_t DisplayList::addChild(NodeOpType* op) { 89 referenceHolders.push_back(op->renderNode); 90 size_t index = children.size(); 91 children.push_back(op); 92 return index; 93} 94 95}; // namespace uirenderer 96}; // namespace android 97