• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2017 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 #pragma once
17 
18 namespace gfxstream {
19 
20 class ColorBuffer;
21 
22 // This class implements async readback of ColorBuffers on both the FrameBuffer
23 // posting thread and a separate worker thread.
24 class ReadbackWorker {
25   public:
26     virtual ~ReadbackWorker() = default;
27 
28     virtual void init() = 0;
29 
30     // Enables readback of the given display.
31     virtual void initReadbackForDisplay(uint32_t displayId, uint32_t w, uint32_t h) = 0;
32 
33     // Enables readback of the given display.
34     virtual void deinitReadbackForDisplay(uint32_t displayId) = 0;
35 
36     enum class DoNextReadbackResult {
37       OK_NOT_READY_FOR_READ,
38 
39       OK_READY_FOR_READ,
40     };
41 
42     // doNextReadback(): Call this from the emugl FrameBuffer::post thread
43     // or similar rendering thread.
44     // This will trigger an async glReadPixels of the current framebuffer.
45     // The post callback of Framebuffer will also be triggered, but
46     // in async mode it should do minimal work that involves |fbImage|.
47     // |repaint|: flag to prime async readback with multiple iterations
48     // so that the consumer of readback doesn't lag behind.
49     // |readbackBgra|: Whether to force the readback format as GL_BGRA_EXT,
50     // so that we get (depending on driver quality, heh) a gpu conversion of the
51     // readback image that is suitable for webrtc, which expects formats like that.
52     virtual DoNextReadbackResult doNextReadback(uint32_t displayId,
53                                                 ColorBuffer* cb,
54                                                 void* fbImage,
55                                                 bool repaint,
56                                                 bool readbackBgra) = 0;
57 
58     // Retrieves the latest framebuffer that has been posted and read with
59     // doNextReadback.  This is meant for apps like video encoding to use as
60     // input; they will need to do synchronized communication with the thread
61     // ReadbackWorker is running on.
62     virtual void getPixels(uint32_t displayId, void* out, uint32_t bytes) = 0;
63 
64     // Duplicates the last frame and generates a post events if
65     // there are no read events active.
66     // This is usually called when there was no doNextReadback activity
67     // for a few ms, to guarantee that end users see the final frame.
68     enum class FlushResult {
69       FAIL,
70 
71       OK_NOT_READY_FOR_READ,
72 
73       OK_READY_FOR_READ,
74     };
75 
76     virtual FlushResult flushPipeline(uint32_t displayId) = 0;
77 };
78 
79 }  // namespace gfxstream
80