1 // Copyright (C) 2015 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. 14 15 #pragma once 16 17 #include <cstdint> 18 19 class Looper; 20 namespace android { 21 22 namespace base { 23 class Looper; 24 } // namespace base 25 26 namespace opengl { 27 28 // GpuFrameBridge is a helper class to forward Gpu frame to its clients. 29 // Usage is the following: 30 // 1) Create a new GpuFrameBridge instance. 31 // 2) Register the FrameAvailableCallback if needed. 32 // 3) Call getRecordFrame or getRecordFrameAsync to receive frame. 33 class GpuFrameBridge { 34 public: 35 // Create a new GpuFrameBridge instance. 36 static GpuFrameBridge* create(); 37 38 // Destructor ~GpuFrameBridge()39 virtual ~GpuFrameBridge() {} 40 41 // Post callback (synchronous) specifically for recording purposes. 42 virtual void postRecordFrame(int width, int height, const void* pixels) = 0; 43 44 // Async version of postRecordFrame for use with async readback. 45 // Does not read the frame immediately. 46 virtual void postRecordFrameAsync(int width, 47 int height, 48 const void* pixels) = 0; 49 50 // Returns the currently displayed frame. This method is designed only for 51 // recording. Returns null if there is no frame available. Make sure to 52 // attach the postFrameRecording() as the callback or you will not get a 53 // valid frame. 54 virtual void* getRecordFrame() = 0; 55 56 // Async version of getRecordFrame. 57 virtual void* getRecordFrameAsync() = 0; 58 59 // Invalidates the recording buffers. Once called, getRecordFrame() and it's 60 // async version will return null until new data has been posted. 61 virtual void invalidateRecordingBuffers() = 0; 62 63 typedef void (*FrameAvailableCallback)(void* opaque); 64 65 virtual void setFrameReceiver(FrameAvailableCallback receiver, void* opaque) = 0; 66 67 virtual void setDisplayId(uint32_t displayId) = 0; 68 69 // virtual void setLooper(android::base::Looper* aLooper) = 0; 70 71 protected: GpuFrameBridge()72 GpuFrameBridge() {} 73 GpuFrameBridge(const GpuFrameBridge& other); 74 }; 75 76 } // namespace opengl 77 } // namespace android 78