1 /* 2 * Copyright (C) 2023 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 #define FAILURE_DEBUG_PREFIX "StreamBufferCache" 18 19 #include "StreamBufferCache.h" 20 #include "debug.h" 21 22 namespace android { 23 namespace hardware { 24 namespace camera { 25 namespace provider { 26 namespace implementation { 27 28 CachedStreamBuffer* update(const StreamBuffer & sb)29StreamBufferCache::update(const StreamBuffer& sb) { 30 const auto bi = mCache.find(sb.bufferId); 31 if (bi == mCache.end()) { 32 const auto r = mCache.insert({sb.bufferId, CachedStreamBuffer(sb)}); 33 LOG_ALWAYS_FATAL_IF(!r.second); 34 return &(r.first->second); 35 } else { 36 CachedStreamBuffer* csb = &bi->second; 37 csb->importAcquireFence(sb.acquireFence); 38 return csb; 39 } 40 } 41 remove(const int64_t bufferId)42void StreamBufferCache::remove(const int64_t bufferId) { 43 mCache.erase(bufferId); 44 } 45 clearStreamInfo()46void StreamBufferCache::clearStreamInfo() { 47 for (auto& kv : mCache) { 48 kv.second.setStreamInfo(nullptr); 49 } 50 } 51 52 } // namespace implementation 53 } // namespace provider 54 } // namespace camera 55 } // namespace hardware 56 } // namespace android 57