• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/opengles.h"
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 #include <list>
23 #include <map>
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 MediaTexturePool {
31 public:
32     // for now, there is only NV12
33     struct TextureFrame {
34         uint32_t Ytex;
35         uint32_t UVtex;
36     };
37 
38     // get a TextureFrame structure to hold decoded frame
39     TextureFrame getTextureFrame(int w, int h);
40 
41     void saveDecodedFrameToTexture(TextureFrame frame,
42                                    void* privData,
43                                    void* func);
44 
45     // put back a used TextureFrame so it can be reused again
46     // later
47     void putTextureFrame(TextureFrame frame);
48 
49     void cleanUpTextures();
50 
51 private:
52     using TexSizes = std::pair<int, int>;
53     using TexFrame = std::pair<uint32_t, uint32_t>;
54     using Pool = std::list<TextureFrame>;
55     using PoolHandle = std::list<TextureFrame>*;
56     std::map<TexSizes, PoolHandle> m_WH_to_PoolHandle;
57     std::map<TexFrame, TexSizes> m_Frame_to_WH;
58     std::map<TexFrame, PoolHandle> m_Frame_to_PoolHandle;
59 
60     void deleteTextures(TextureFrame frame);
61 
62     int m_id = 0;
63 
64 public:
65     MediaTexturePool();
66     ~MediaTexturePool();
67 
68 private:
69     AndroidVirtioGpuOps* mVirtioGpuOps = nullptr;
70 };
71 
72 }  // namespace emulation
73 }  // namespace android
74