• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 #ifndef MediaTexture_h
18 #define MediaTexture_h
19 
20 #if USE(ACCELERATED_COMPOSITING)
21 
22 #include "RefPtr.h"
23 #include "LayerAndroid.h"
24 #include "Vector.h"
25 #include <GLES2/gl2.h>
26 #include <ui/GraphicBuffer.h>
27 #include <utils/RefBase.h>
28 #include <jni.h>
29 
30 namespace android {
31     class GLConsumer;
32 }
33 
34 namespace WebCore {
35 
36 typedef void (*FramerateCallbackProc)(ANativeWindow* window, int64_t timestamp);
37 
38 class MediaListener;
39 
40 class MediaTexture : public android::LightRefBase<MediaTexture> {
41 
42 public:
43     MediaTexture(jobject webViewRef, jobject webViewCoreRef);
44     ~MediaTexture();
45 
46     bool isContentInverted();
47     void invertContents(bool invertContent);
48 
49     void initNativeWindowIfNeeded();
50     void draw(const TransformationMatrix& contentMatrix,
51               const TransformationMatrix& videoMatrix,
52               const SkRect& mediaBounds);
53 
54     ANativeWindow* getNativeWindowForContent();
55     ANativeWindow* requestNativeWindowForVideo();
56 
57     void releaseNativeWindow(const ANativeWindow* window);
58     void setDimensions(const ANativeWindow* window, const SkRect& dimensions);
59     void setFramerateCallback(const ANativeWindow* window,
60                               FramerateCallbackProc callback);
61 
62 private:
63     struct TextureWrapper {
64         GLuint textureId;
65         sp<android::GLConsumer> surfaceTexture;
66         sp<ANativeWindow> nativeWindow;
67         sp<MediaListener> mediaListener;
68         SkRect dimensions; // only used by the video layer
69     };
70 
71     TextureWrapper* createTexture();
72     void deleteTexture(TextureWrapper* item, bool force = false);
73 
74     TextureWrapper* m_contentTexture;
75     Vector<TextureWrapper*> m_videoTextures;
76     Vector<GLuint> m_unusedTextures;
77 
78     // used to track if the content is to be drawn inverted
79     bool m_isContentInverted;
80 
81     // used to generate new video textures
82     bool m_newWindowRequest;
83     sp<ANativeWindow> m_newWindow;
84 
85     jobject m_weakWebViewRef;
86     jobject m_weakWebViewCoreRef;
87 
88     android::Mutex m_mediaLock;
89     android::Condition m_newMediaRequestCond;
90 };
91 
92 
93 } // namespace WebCore
94 
95 #endif // USE(ACCELERATED_COMPOSITING)
96 
97 #endif  // MediaTexture_h
98