1 // Copyright (C) 2020 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 "host-common/GoldfishMediaDefs.h" 18 #include "host-common/MediaTexturePool.h" 19 #include "android/opengles.h" 20 21 #include <stddef.h> 22 #include <stdint.h> 23 #include <list> 24 25 namespace android { 26 namespace emulation { 27 28 // This is a helper class to render decoded frames 29 // to host color buffer 30 class MediaHostRenderer { 31 public: 32 using TextureFrame = MediaTexturePool::TextureFrame; 33 // get a TextureFrame structure to hold decoded frame 34 MediaTexturePool::TextureFrame getTextureFrame(int w, int h); 35 36 void saveDecodedFrameToTexture(MediaTexturePool::TextureFrame frame, 37 void* privData, 38 void* func); 39 40 // put back a used TextureFrame so it can be reused again 41 // later putTextureFrame(MediaTexturePool::TextureFrame frame)42 void putTextureFrame(MediaTexturePool::TextureFrame frame) { 43 mTexturePool.putTextureFrame(frame); 44 } 45 46 void cleanUpTextures(); 47 getTexturePool()48 MediaTexturePool* getTexturePool() { return &mTexturePool; } 49 50 private: 51 MediaTexturePool mTexturePool; 52 53 public: 54 // render decoded frame stored in CPU memory 55 void renderToHostColorBuffer(int hostColorBufferId, 56 unsigned int outputWidth, 57 unsigned int outputHeight, 58 uint8_t* decodedFrame); 59 60 // render decoded frame stored in GPU texture; recycle the swapped 61 // out texture from colorbuffer into framepool 62 void renderToHostColorBufferWithTextures( 63 int hostColorBufferId, 64 unsigned int outputWidth, 65 unsigned int outputHeight, 66 MediaTexturePool::TextureFrame frame); 67 68 MediaHostRenderer(); 69 ~MediaHostRenderer(); 70 71 private: 72 AndroidVirtioGpuOps* mVirtioGpuOps = nullptr; 73 }; 74 75 } // namespace emulation 76 } // namespace android 77