1 // Copyright 2018 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License.#pragma once 14 #include "AndroidBufferQueue.h" 15 16 #include "base/MessageChannel.h" 17 18 using android::base::MessageChannel; 19 20 namespace aemu { 21 22 class AndroidBufferQueue::Impl { 23 public: 24 Impl() = default; 25 ~Impl() = default; 26 MessageChannel<AndroidBufferQueue::Item, 27 AndroidBufferQueue::kCapacity> queue; 28 MessageChannel<AndroidBufferQueue::Item, 29 AndroidBufferQueue::kCapacity> canceled; 30 }; 31 AndroidBufferQueue()32AndroidBufferQueue::AndroidBufferQueue() { 33 mImpl.reset(new AndroidBufferQueue::Impl()); 34 } 35 36 AndroidBufferQueue::~AndroidBufferQueue() = default; 37 cancelBuffer(const AndroidBufferQueue::Item & item)38void AndroidBufferQueue::cancelBuffer( 39 const AndroidBufferQueue::Item& item) { 40 mImpl->canceled.send(item); 41 } 42 queueBuffer(const AndroidBufferQueue::Item & item)43void AndroidBufferQueue::queueBuffer( 44 const AndroidBufferQueue::Item& item) { 45 mImpl->queue.send(item); 46 } 47 dequeueBuffer(AndroidBufferQueue::Item * outItem)48void AndroidBufferQueue::dequeueBuffer( 49 AndroidBufferQueue::Item* outItem) { 50 if (mImpl->canceled.tryReceive(outItem)) { 51 return; 52 } 53 mImpl->queue.receive(outItem); 54 } 55 try_dequeueBuffer(AndroidBufferQueue::Item * outItem)56bool AndroidBufferQueue::try_dequeueBuffer( 57 AndroidBufferQueue::Item* outItem) { 58 if (mImpl->canceled.tryReceive(outItem)) return true; 59 return mImpl->queue.tryReceive(outItem); 60 } 61 62 } // namespace aemu 63