dom/plugins/base/android/ANPOpenGL.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial