• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef VideoLayerManager_h
27 #define VideoLayerManager_h
28 
29 #include "GLUtils.h"
30 #include <wtf/HashMap.h>
31 #include <wtf/Vector.h>
32 
33 #if USE(ACCELERATED_COMPOSITING)
34 
35 namespace WebCore {
36 
37 // Every video layer can use its uniqueId to query VideoLayerManager about such
38 // info globally.
39 struct VideoLayerInfo {
40     GLuint textureId; // GL texture bound with the surface texture.
41     int videoSize; // The size of the video.
42     int timeStamp; // Used to decide which VideoLayerInfo is the oldest one.
43     GLfloat surfaceMatrix[16];
44 };
45 
46 
47 class VideoLayerManager {
48 
49 public:
50     typedef HashMap<int, VideoLayerInfo*>::const_iterator InfoIterator;
51 
52     VideoLayerManager();
53 
54     // Register the texture when we got setSurfaceTexture call.
55     void registerTexture(const int layerId, const GLuint textureId);
56     // Update the size when the video is prepared.
57     void updateVideoLayerSize(const int layerId, const int size);
58     // At draw time, update the matrix for every video frame update.
59     void updateMatrix(const int layerId, const GLfloat* matrix);
60     // Remove the layer info from the mapping.
61     void removeLayer(const int layerId);
62 
63     // Return the texture name corresponding to the layerId
64     GLuint getTextureId(const int layerId);
65     // Return the matrix for surface texture corresponding to the layerId
66     GLfloat* getMatrix(const int layerId);
67 
68     // Delete the GL textures
69     void deleteUnusedTextures();
70 
71 private:
72     // Get the sum of all the video size stored in m_videoLayerInfoMap.
73     int getTotalMemUsage();
74     // If the memory consumption is out of bound, recycle some textures.
75     bool recycleTextureMem();
76     // The private function to remove layer.
77     void removeLayerInternal(const int layerId);
78 
79     // Indexed by each layer's uniqueId, this map contains the important info
80     // used for showing the video when playing or the screenshot when paused.
81     HashMap<int, VideoLayerInfo*> m_videoLayerInfoMap;
82     android::Mutex m_videoLayerInfoMapLock;
83 
84     // Everytime we add one item to the map, we update the timestamp.
85     int m_currentTimeStamp;
86 
87     // The retiredTextures is used to communicate between UI thread and webcore
88     // thread. Basically, GL textures are determined to retire in the webcore
89     // thread, and really get deleted in the UI thread.
90     Vector<GLuint> m_retiredTextures;
91     android::Mutex m_retiredTexturesLock;
92 };
93 
94 } // namespace WebCore
95 
96 #endif // USE(ACCELERATED_COMPOSITING)
97        //
98 #endif // VideoLayerManager_h
99