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 // must include config.h first for webkit to fiddle with new/delete
27 #include "config.h"
28 #include "ANPVideo_npapi.h"
29 #include "SkANP.h"
30
31 #include "PluginView.h"
32 #include "PluginWidgetAndroid.h"
33 #include "MediaLayer.h"
34
pluginViewForInstance(NPP instance)35 static WebCore::PluginView* pluginViewForInstance(NPP instance) {
36 if (instance && instance->ndata)
37 return static_cast<WebCore::PluginView*>(instance->ndata);
38 return WebCore::PluginView::currentPluginView();
39 }
40
mediaLayerForInstance(NPP instance)41 static WebCore::MediaLayer* mediaLayerForInstance(NPP instance) {
42 WebCore::PluginView* pluginView = pluginViewForInstance(instance);
43 PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
44 return pluginWidget->getLayer();
45 }
46
anp_acquireNativeWindow(NPP instance)47 static ANativeWindow* anp_acquireNativeWindow(NPP instance) {
48 WebCore::MediaLayer* mediaLayer = mediaLayerForInstance(instance);
49
50 return mediaLayer->acquireNativeWindowForVideo();
51 }
52
anp_setWindowDimensions(NPP instance,const ANativeWindow * window,const ANPRectF * dimensions)53 static void anp_setWindowDimensions(NPP instance, const ANativeWindow* window,
54 const ANPRectF* dimensions) {
55
56 WebCore::MediaLayer* mediaLayer = mediaLayerForInstance(instance);
57 if (!mediaLayer)
58 return;
59
60 SkRect rect;
61 mediaLayer->setWindowDimensionsForVideo(window, *SkANP::SetRect(&rect, *dimensions));
62 }
63
64
anp_releaseNativeWindow(NPP instance,ANativeWindow * window)65 static void anp_releaseNativeWindow(NPP instance, ANativeWindow* window) {
66 WebCore::MediaLayer* mediaLayer = mediaLayerForInstance(instance);
67 if (!mediaLayer)
68 return;
69
70 mediaLayer->releaseNativeWindowForVideo(window);
71 }
72
anp_setFramerateCallback(NPP instance,const ANativeWindow * window,ANPVideoFrameCallbackProc callback)73 static void anp_setFramerateCallback(NPP instance, const ANativeWindow* window, ANPVideoFrameCallbackProc callback) {
74 WebCore::MediaLayer* mediaLayer = mediaLayerForInstance(instance);
75 if (!mediaLayer)
76 return;
77
78 mediaLayer->setFramerateCallback(window, callback);
79 }
80
81 ///////////////////////////////////////////////////////////////////////////////
82
83 #define ASSIGN(obj, name) (obj)->name = anp_##name
84
ANPVideoInterfaceV0_Init(ANPInterface * value)85 void ANPVideoInterfaceV0_Init(ANPInterface* value) {
86 ANPVideoInterfaceV0* i = reinterpret_cast<ANPVideoInterfaceV0*>(value);
87
88 ASSIGN(i, acquireNativeWindow);
89 ASSIGN(i, setWindowDimensions);
90 ASSIGN(i, releaseNativeWindow);
91 }
92
ANPVideoInterfaceV1_Init(ANPInterface * value)93 void ANPVideoInterfaceV1_Init(ANPInterface* value) {
94 // initialize the functions from the previous interface
95 ANPVideoInterfaceV0_Init(value);
96 // add any new functions or override existing functions
97 ANPVideoInterfaceV1* i = reinterpret_cast<ANPVideoInterfaceV1*>(value);
98 ASSIGN(i, setFramerateCallback);
99 }
100