michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include "AndroidBridge.h" michael@0: #include "ANPBase.h" michael@0: #include "GLContextProvider.h" michael@0: #include "nsNPAPIPluginInstance.h" michael@0: #include "nsPluginInstanceOwner.h" michael@0: #include "GLContextProvider.h" michael@0: #include "GLContextEGL.h" michael@0: michael@0: #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args) michael@0: #define ASSIGN(obj, name) (obj)->name = anp_opengl_##name michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::gl; michael@0: michael@0: typedef nsNPAPIPluginInstance::TextureInfo TextureInfo; michael@0: michael@0: static ANPEGLContext anp_opengl_acquireContext(NPP instance) { michael@0: nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); michael@0: michael@0: GLContext* context = pinst->GLContext(); michael@0: if (!context) michael@0: return nullptr; michael@0: michael@0: context->MakeCurrent(); michael@0: return GLContextEGL::Cast(context)->GetEGLContext(); michael@0: } michael@0: michael@0: static ANPTextureInfo anp_opengl_lockTexture(NPP instance) { michael@0: nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); michael@0: michael@0: TextureInfo pluginInfo = pinst->LockContentTexture(); michael@0: michael@0: ANPTextureInfo info; michael@0: info.textureId = pluginInfo.mTexture; michael@0: info.width = pluginInfo.mWidth; michael@0: info.height = pluginInfo.mHeight; michael@0: michael@0: // It looks like we should be passing whatever michael@0: // internal format Flash told us it used previously michael@0: // (e.g., the value of pluginInfo.mInternalFormat), michael@0: // but if we do that it doesn't upload to the texture michael@0: // for some reason. michael@0: info.internalFormat = 0; michael@0: michael@0: return info; michael@0: } michael@0: michael@0: static void anp_opengl_releaseTexture(NPP instance, const ANPTextureInfo* info) { michael@0: nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); michael@0: michael@0: TextureInfo pluginInfo(info->textureId, info->width, info->height, info->internalFormat); michael@0: pinst->ReleaseContentTexture(pluginInfo); michael@0: pinst->RedrawPlugin(); michael@0: } michael@0: michael@0: static void anp_opengl_invertPluginContent(NPP instance, bool isContentInverted) { michael@0: nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); michael@0: michael@0: // Our definition of inverted is the opposite of the plugin's michael@0: pinst->SetInverted(!isContentInverted); michael@0: pinst->RedrawPlugin(); michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: void InitOpenGLInterface(ANPOpenGLInterfaceV0* i) { michael@0: ASSIGN(i, acquireContext); michael@0: ASSIGN(i, lockTexture); michael@0: ASSIGN(i, releaseTexture); michael@0: ASSIGN(i, invertPluginContent); michael@0: }