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