Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
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"
15 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
16 #define ASSIGN(obj, name) (obj)->name = anp_opengl_##name
18 using namespace mozilla;
19 using namespace mozilla::gl;
21 typedef nsNPAPIPluginInstance::TextureInfo TextureInfo;
23 static ANPEGLContext anp_opengl_acquireContext(NPP instance) {
24 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
26 GLContext* context = pinst->GLContext();
27 if (!context)
28 return nullptr;
30 context->MakeCurrent();
31 return GLContextEGL::Cast(context)->GetEGLContext();
32 }
34 static ANPTextureInfo anp_opengl_lockTexture(NPP instance) {
35 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
37 TextureInfo pluginInfo = pinst->LockContentTexture();
39 ANPTextureInfo info;
40 info.textureId = pluginInfo.mTexture;
41 info.width = pluginInfo.mWidth;
42 info.height = pluginInfo.mHeight;
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;
51 return info;
52 }
54 static void anp_opengl_releaseTexture(NPP instance, const ANPTextureInfo* info) {
55 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
57 TextureInfo pluginInfo(info->textureId, info->width, info->height, info->internalFormat);
58 pinst->ReleaseContentTexture(pluginInfo);
59 pinst->RedrawPlugin();
60 }
62 static void anp_opengl_invertPluginContent(NPP instance, bool isContentInverted) {
63 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
65 // Our definition of inverted is the opposite of the plugin's
66 pinst->SetInverted(!isContentInverted);
67 pinst->RedrawPlugin();
68 }
70 ///////////////////////////////////////////////////////////////////////////////
72 void InitOpenGLInterface(ANPOpenGLInterfaceV0* i) {
73 ASSIGN(i, acquireContext);
74 ASSIGN(i, lockTexture);
75 ASSIGN(i, releaseTexture);
76 ASSIGN(i, invertPluginContent);
77 }