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 #include "PostWorkerVk.h"
17
18 #include "FrameBuffer.h"
19 #include "host-common/GfxstreamFatalError.h"
20 #include "host-common/logging.h"
21 #include "vulkan/DisplayVk.h"
22
23 namespace gfxstream {
24
25 namespace {
26
27 using emugl::ABORT_REASON_OTHER;
28 using emugl::FatalError;
29
30 } // namespace
31
PostWorkerVk(FrameBuffer * fb,Compositor * compositor,vk::DisplayVk * displayVk)32 PostWorkerVk::PostWorkerVk(FrameBuffer* fb, Compositor* compositor, vk::DisplayVk* displayVk)
33 : PostWorker(false, fb, compositor), m_displayVk(displayVk) {}
34
postImpl(ColorBuffer * cb)35 std::shared_future<void> PostWorkerVk::postImpl(ColorBuffer* cb) {
36 std::shared_future<void> completedFuture = std::async(std::launch::deferred, [] {}).share();
37 completedFuture.wait();
38
39 if (!m_displayVk) {
40 GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) << "PostWorker missing DisplayVk.";
41 }
42
43 constexpr const int kMaxPostRetries = 2;
44 for (int i = 0; i < kMaxPostRetries; i++) {
45 const auto imageInfo = mFb->borrowColorBufferForDisplay(cb->getHndl());
46 auto result = m_displayVk->post(imageInfo.get());
47 if (result.success) {
48 return result.postCompletedWaitable;
49 }
50 }
51
52 ERR("Failed to post ColorBuffer after %d retries.", kMaxPostRetries);
53 return completedFuture;
54 }
55
screenshot(ColorBuffer * cb,int width,int height,GLenum format,GLenum type,int rotation,void * pixels,Rect rect)56 void PostWorkerVk::screenshot(ColorBuffer* cb, int width, int height, GLenum format, GLenum type,
57 int rotation, void* pixels, Rect rect) {
58 GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
59 << "Screenshot not supported with native Vulkan swapchain enabled.";
60 }
61
viewportImpl(int width,int height)62 void PostWorkerVk::viewportImpl(int width, int height) {}
63
clearImpl()64 void PostWorkerVk::clearImpl() {
65 GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
66 << "PostWorker with Vulkan doesn't support clear";
67 }
68
exitImpl()69 void PostWorkerVk::exitImpl() {}
70
71 } // namespace gfxstream