1 /*
2 * Copyright (C) 2010 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 #include "config.h"
17 #include "MediaLayer.h"
18 #include "MediaTexture.h"
19 #include "TilesManager.h"
20
21 #if USE(ACCELERATED_COMPOSITING)
22
23 #define LAYER_DEBUG
24 #undef LAYER_DEBUG
25
26 #ifdef DEBUG
27
28 #include <cutils/log.h>
29 #include <wtf/text/CString.h>
30
31 #undef XLOG
32 #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "MediaLayer", __VA_ARGS__)
33
34 #else
35
36 #undef XLOG
37 #define XLOG(...)
38
39 #endif // DEBUG
40
41 namespace WebCore {
42
MediaLayer(jobject webViewRef)43 MediaLayer::MediaLayer(jobject webViewRef) : LayerAndroid((RenderLayer*) NULL)
44 {
45 m_mediaTexture = new MediaTexture(webViewRef);
46 m_mediaTexture->incStrong(this);
47
48 m_isCopy = false;
49 m_outlineSize = 0;
50 XLOG("Creating Media Layer %p", this);
51 }
52
MediaLayer(const MediaLayer & layer)53 MediaLayer::MediaLayer(const MediaLayer& layer) : LayerAndroid(layer)
54 {
55 m_mediaTexture = layer.m_mediaTexture;
56 m_mediaTexture->incStrong(this);
57
58 m_isCopy = true;
59 m_outlineSize = layer.m_outlineSize;
60 XLOG("Creating Media Layer Copy %p -> %p", &layer, this);
61 }
62
~MediaLayer()63 MediaLayer::~MediaLayer()
64 {
65 XLOG("Deleting Media Layer");
66 m_mediaTexture->decStrong(this);
67 }
68
drawGL(GLWebViewState * glWebViewState,SkMatrix & matrix)69 bool MediaLayer::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix)
70 {
71 TilesManager::instance()->shader()->clip(drawClip());
72
73 // when the plugin gains focus webkit applies an outline to the
74 // widget, which causes the layer to expand to accommodate the
75 // outline. Therefore, we shrink the rect by the outline's dimensions
76 // to ensure the plugin does not draw outside of its bounds.
77 SkRect mediaBounds;
78 mediaBounds.set(0, 0, getSize().width(), getSize().height());
79 mediaBounds.inset(m_outlineSize, m_outlineSize);
80
81 // check to see if we need to create a content or video texture
82 m_mediaTexture->initNativeWindowIfNeeded();
83
84 // the layer's shader draws the content inverted so we must undo
85 // that change in the transformation matrix
86 TransformationMatrix m = m_drawTransform;
87 if (!m_mediaTexture->isContentInverted()) {
88 m.flipY();
89 m.translate(0, -getSize().height());
90 }
91
92 // draw any content or video if present
93 m_mediaTexture->draw(m, m_drawTransform, mediaBounds);
94
95 return drawChildrenGL(glWebViewState, matrix);
96 }
97
acquireNativeWindowForContent()98 ANativeWindow* MediaLayer::acquireNativeWindowForContent()
99 {
100 return m_mediaTexture->getNativeWindowForContent();
101 }
102
103
acquireNativeWindowForVideo()104 ANativeWindow* MediaLayer::acquireNativeWindowForVideo()
105 {
106 return m_mediaTexture->requestNativeWindowForVideo();
107 }
108
setWindowDimensionsForVideo(const ANativeWindow * window,const SkRect & dimensions)109 void MediaLayer::setWindowDimensionsForVideo(const ANativeWindow* window, const SkRect& dimensions)
110 {
111 //TODO validate that the dimensions do not exceed the plugin's bounds
112 m_mediaTexture->setDimensions(window, dimensions);
113 }
114
releaseNativeWindowForVideo(ANativeWindow * window)115 void MediaLayer::releaseNativeWindowForVideo(ANativeWindow* window)
116 {
117 m_mediaTexture->releaseNativeWindow(window);
118 }
119
setFramerateCallback(const ANativeWindow * window,FramerateCallbackProc callback)120 void MediaLayer::setFramerateCallback(const ANativeWindow* window, FramerateCallbackProc callback)
121 {
122 m_mediaTexture->setFramerateCallback(window, callback);
123 }
124
125 } // namespace WebCore
126
127 #endif // USE(ACCELERATED_COMPOSITING)
128