Bug 929471. Make CGLTexImageIOSurface2D take a CGLContextObj instead of a NSOpenGLContext. r=bgirard
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 07 Nov 2013 22:53:54 -0500
changeset 154452 ca7e5bb285500c3afc0739de7c5511528f768000
parent 154451 e1d5e14f82d824e088bc454ccadc8bbd86ac768a
child 154453 82bc6c4f7e5ba80529e144659f21146e757981cf
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbgirard
bugs929471
milestone28.0a1
Bug 929471. Make CGLTexImageIOSurface2D take a CGLContextObj instead of a NSOpenGLContext. r=bgirard
gfx/2d/MacIOSurface.h
gfx/2d/QuartzSupport.mm
gfx/gl/GLContext.h
gfx/gl/GLContextProviderCGL.mm
gfx/gl/SharedSurfaceIO.cpp
gfx/layers/opengl/CanvasLayerOGL.cpp
gfx/layers/opengl/TextureHostOGL.cpp
--- a/gfx/2d/MacIOSurface.h
+++ b/gfx/2d/MacIOSurface.h
@@ -47,17 +47,17 @@ public:
   size_t GetDevicePixelWidth();
   size_t GetDevicePixelHeight();
   size_t GetBytesPerRow();
   void Lock();
   void Unlock();
   bool HasAlpha() { return mHasAlpha; }
   // We would like to forward declare NSOpenGLContext, but it is an @interface
   // and this file is also used from c++, so we use a void *.
-  CGLError CGLTexImageIOSurface2D(void *ctxt);
+  CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt);
   mozilla::TemporaryRef<SourceSurface> GetAsSurface();
   CGContextRef CreateIOSurfaceContext();
 
   // FIXME This doesn't really belong here
   static CGImageRef CreateImageFromIOSurfaceContext(CGContextRef aContext);
   static mozilla::TemporaryRef<MacIOSurface> IOSurfaceContextGetSurface(CGContextRef aContext,
                                                                         double aContentsScaleFactor = 1.0,
                                                                         bool aHasAlpha = true);
--- a/gfx/2d/QuartzSupport.mm
+++ b/gfx/2d/QuartzSupport.mm
@@ -439,20 +439,19 @@ MacIOSurface::GetAsSurface() {
 
   RefPtr<SourceSurfaceRawData> surf = new SourceSurfaceRawData();
   surf->InitWrappingData(dataCpy, IntSize(ioWidth, ioHeight), bytesPerRow, format, true);
 
   return surf.forget();
 }
 
 CGLError 
-MacIOSurface::CGLTexImageIOSurface2D(void *c)
+MacIOSurface::CGLTexImageIOSurface2D(CGLContextObj ctxt)
 {
-  NSOpenGLContext *ctxt = static_cast<NSOpenGLContext*>(c);
-  return MacIOSurfaceLib::CGLTexImageIOSurface2D((CGLContextObj)[ctxt CGLContextObj],
+  return MacIOSurfaceLib::CGLTexImageIOSurface2D(ctxt,
                                                 GL_TEXTURE_RECTANGLE_ARB,
                                                 HasAlpha() ? LOCAL_GL_RGBA : LOCAL_GL_RGB,
                                                 GetDevicePixelWidth(),
                                                 GetDevicePixelHeight(),
                                                 LOCAL_GL_BGRA,
                                                 LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV,
                                                 mIOSurfacePtr, 0);
 }
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -2424,16 +2424,17 @@ public:
         // MarkDestroyed will mark all these as null.
         return mSymbols.fUseProgram == nullptr;
     }
 
     enum NativeDataType {
       NativeGLContext,
       NativeImageSurface,
       NativeThebesSurface,
+      NativeCGLContext,
       NativeDataTypeMax
     };
 
     virtual void *GetNativeData(NativeDataType aType) { return nullptr; }
     GLContext *GetSharedContext() { return mSharedContext; }
 
     bool IsGlobalSharedContext() { return mIsGlobalSharedContext; }
     void SetIsGlobalSharedContext(bool aIsOne) { mIsGlobalSharedContext = aIsOne; }
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -128,17 +128,18 @@ public:
         return true;
     }
 
     void *GetNativeData(NativeDataType aType)
     { 
         switch (aType) {
         case NativeGLContext:
             return mContext;
-
+        case NativeCGLContext:
+            return [mContext CGLContextObj];
         default:
             return nullptr;
         }
     }
 
     bool MakeCurrentImpl(bool aForce = false)
     {
         if (!aForce && [NSOpenGLContext currentContext] == mContext) {
--- a/gfx/gl/SharedSurfaceIO.cpp
+++ b/gfx/gl/SharedSurfaceIO.cpp
@@ -71,20 +71,20 @@ SharedSurface_IOSurface::SharedSurface_I
                         LOCAL_GL_LINEAR);
     mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
                         LOCAL_GL_TEXTURE_WRAP_S,
                         LOCAL_GL_CLAMP_TO_EDGE);
     mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
                         LOCAL_GL_TEXTURE_WRAP_T,
                         LOCAL_GL_CLAMP_TO_EDGE);
 
-    void *nativeCtx = mGL->GetNativeData(GLContext::NativeGLContext);
-    MOZ_ASSERT(nativeCtx);
+    CGLContextObj ctx = static_cast<CGLContextObj>(mGL->GetNativeData(GLContext::NativeCGLContext));
+    MOZ_ASSERT(ctx);
 
-    surface->CGLTexImageIOSurface2D(nativeCtx);
+    surface->CGLTexImageIOSurface2D(ctx);
 }
 
 SharedSurface_IOSurface::~SharedSurface_IOSurface()
 {
     if (mTexture) {
         DebugOnly<bool> success = mGL->MakeCurrent();
         MOZ_ASSERT(success);
         mGL->fDeleteTextures(1, &mTexture);
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -98,19 +98,18 @@ MakeIOSurfaceTexture(void* aCGIOSurfaceC
   aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, ioSurfaceTexture);
 
   aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
   aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
   aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
   aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
 
   RefPtr<MacIOSurface> ioSurface = MacIOSurface::IOSurfaceContextGetSurface((CGContextRef)aCGIOSurfaceContext);
-  void *nativeCtx = aGL->GetNativeData(GLContext::NativeGLContext);
 
-  ioSurface->CGLTexImageIOSurface2D(nativeCtx);
+  ioSurface->CGLTexImageIOSurface2D(static_cast<CGLContextObj>(aGL->GetNativeData(GLContext::NativeCGLContext)));
 
   aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, 0);
 
   return ioSurfaceTexture;
 }
 #endif
 
 void
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -477,18 +477,17 @@ MacIOSurfaceTextureSourceOGL::BindTextur
   if (!gl()) {
     NS_WARNING("Trying to bind a texture without a GLContext");
     return;
   }
   GLuint tex = mCompositor->GetTemporaryTexture(aTextureUnit);
 
   gl()->fActiveTexture(aTextureUnit);
   gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
-  void *nativeGL = gl()->GetNativeData(gl::GLContext::NativeGLContext);
-  mSurface->CGLTexImageIOSurface2D(nativeGL);
+  mSurface->CGLTexImageIOSurface2D(static_cast<CGLContextObj>(gl()->GetNativeData(GLContext::NativeCGLContext)));
   gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
 }
 
 gl::GLContext*
 MacIOSurfaceTextureSourceOGL::gl() const
 {
   return mCompositor ? mCompositor->gl() : nullptr;
 }