|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include <dlfcn.h> |
|
6 #include <android/log.h> |
|
7 #include "AndroidBridge.h" |
|
8 #include "ANPBase.h" |
|
9 #include "GLContextProvider.h" |
|
10 #include "nsNPAPIPluginInstance.h" |
|
11 #include "nsPluginInstanceOwner.h" |
|
12 #include "GLContextProvider.h" |
|
13 #include "GLContextEGL.h" |
|
14 |
|
15 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args) |
|
16 #define ASSIGN(obj, name) (obj)->name = anp_opengl_##name |
|
17 |
|
18 using namespace mozilla; |
|
19 using namespace mozilla::gl; |
|
20 |
|
21 typedef nsNPAPIPluginInstance::TextureInfo TextureInfo; |
|
22 |
|
23 static ANPEGLContext anp_opengl_acquireContext(NPP instance) { |
|
24 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); |
|
25 |
|
26 GLContext* context = pinst->GLContext(); |
|
27 if (!context) |
|
28 return nullptr; |
|
29 |
|
30 context->MakeCurrent(); |
|
31 return GLContextEGL::Cast(context)->GetEGLContext(); |
|
32 } |
|
33 |
|
34 static ANPTextureInfo anp_opengl_lockTexture(NPP instance) { |
|
35 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); |
|
36 |
|
37 TextureInfo pluginInfo = pinst->LockContentTexture(); |
|
38 |
|
39 ANPTextureInfo info; |
|
40 info.textureId = pluginInfo.mTexture; |
|
41 info.width = pluginInfo.mWidth; |
|
42 info.height = pluginInfo.mHeight; |
|
43 |
|
44 // It looks like we should be passing whatever |
|
45 // internal format Flash told us it used previously |
|
46 // (e.g., the value of pluginInfo.mInternalFormat), |
|
47 // but if we do that it doesn't upload to the texture |
|
48 // for some reason. |
|
49 info.internalFormat = 0; |
|
50 |
|
51 return info; |
|
52 } |
|
53 |
|
54 static void anp_opengl_releaseTexture(NPP instance, const ANPTextureInfo* info) { |
|
55 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); |
|
56 |
|
57 TextureInfo pluginInfo(info->textureId, info->width, info->height, info->internalFormat); |
|
58 pinst->ReleaseContentTexture(pluginInfo); |
|
59 pinst->RedrawPlugin(); |
|
60 } |
|
61 |
|
62 static void anp_opengl_invertPluginContent(NPP instance, bool isContentInverted) { |
|
63 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); |
|
64 |
|
65 // Our definition of inverted is the opposite of the plugin's |
|
66 pinst->SetInverted(!isContentInverted); |
|
67 pinst->RedrawPlugin(); |
|
68 } |
|
69 |
|
70 /////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
72 void InitOpenGLInterface(ANPOpenGLInterfaceV0* i) { |
|
73 ASSIGN(i, acquireContext); |
|
74 ASSIGN(i, lockTexture); |
|
75 ASSIGN(i, releaseTexture); |
|
76 ASSIGN(i, invertPluginContent); |
|
77 } |