1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/base/android/ANPOpenGL.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include <dlfcn.h> 1.9 +#include <android/log.h> 1.10 +#include "AndroidBridge.h" 1.11 +#include "ANPBase.h" 1.12 +#include "GLContextProvider.h" 1.13 +#include "nsNPAPIPluginInstance.h" 1.14 +#include "nsPluginInstanceOwner.h" 1.15 +#include "GLContextProvider.h" 1.16 +#include "GLContextEGL.h" 1.17 + 1.18 +#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args) 1.19 +#define ASSIGN(obj, name) (obj)->name = anp_opengl_##name 1.20 + 1.21 +using namespace mozilla; 1.22 +using namespace mozilla::gl; 1.23 + 1.24 +typedef nsNPAPIPluginInstance::TextureInfo TextureInfo; 1.25 + 1.26 +static ANPEGLContext anp_opengl_acquireContext(NPP instance) { 1.27 + nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); 1.28 + 1.29 + GLContext* context = pinst->GLContext(); 1.30 + if (!context) 1.31 + return nullptr; 1.32 + 1.33 + context->MakeCurrent(); 1.34 + return GLContextEGL::Cast(context)->GetEGLContext(); 1.35 +} 1.36 + 1.37 +static ANPTextureInfo anp_opengl_lockTexture(NPP instance) { 1.38 + nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); 1.39 + 1.40 + TextureInfo pluginInfo = pinst->LockContentTexture(); 1.41 + 1.42 + ANPTextureInfo info; 1.43 + info.textureId = pluginInfo.mTexture; 1.44 + info.width = pluginInfo.mWidth; 1.45 + info.height = pluginInfo.mHeight; 1.46 + 1.47 + // It looks like we should be passing whatever 1.48 + // internal format Flash told us it used previously 1.49 + // (e.g., the value of pluginInfo.mInternalFormat), 1.50 + // but if we do that it doesn't upload to the texture 1.51 + // for some reason. 1.52 + info.internalFormat = 0; 1.53 + 1.54 + return info; 1.55 +} 1.56 + 1.57 +static void anp_opengl_releaseTexture(NPP instance, const ANPTextureInfo* info) { 1.58 + nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); 1.59 + 1.60 + TextureInfo pluginInfo(info->textureId, info->width, info->height, info->internalFormat); 1.61 + pinst->ReleaseContentTexture(pluginInfo); 1.62 + pinst->RedrawPlugin(); 1.63 +} 1.64 + 1.65 +static void anp_opengl_invertPluginContent(NPP instance, bool isContentInverted) { 1.66 + nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata); 1.67 + 1.68 + // Our definition of inverted is the opposite of the plugin's 1.69 + pinst->SetInverted(!isContentInverted); 1.70 + pinst->RedrawPlugin(); 1.71 +} 1.72 + 1.73 +/////////////////////////////////////////////////////////////////////////////// 1.74 + 1.75 +void InitOpenGLInterface(ANPOpenGLInterfaceV0* i) { 1.76 + ASSIGN(i, acquireContext); 1.77 + ASSIGN(i, lockTexture); 1.78 + ASSIGN(i, releaseTexture); 1.79 + ASSIGN(i, invertPluginContent); 1.80 +}