Bug 756601 - Use TextureImageCGL again, and used TiledTexturedImage for large textures. r=BenWa
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 10 May 2013 09:02:48 +1200
changeset 138209 b58dac401cebd48947be4fe2da5b24532cbad55c
parent 138208 751fedabab31487f8c2daca864b9beb428b2c2da
child 138210 fed9c75cd9fddf92f502584ac7e29062aac1486d
push id3752
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 17:21:10 +0000
treeherdermozilla-aurora@1580544aef0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa
bugs756601
milestone23.0a1
Bug 756601 - Use TextureImageCGL again, and used TiledTexturedImage for large textures. r=BenWa
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEGL.cpp
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -166,22 +166,25 @@ public:
       PROFILER_LABEL("GLContext", "SwapBuffers");
       [mContext flushBuffer];
       return true;
     }
 
     bool ResizeOffscreen(const gfxIntSize& aNewSize);
 
     virtual already_AddRefed<TextureImage>
-    CreateBasicTextureImage(GLuint aTexture,
-                            const nsIntSize& aSize,
-                            GLenum aWrapMode,
-                            TextureImage::ContentType aContentType,
-                            GLContext* aContext,
-                            TextureImage::Flags aFlags = TextureImage::NoFlags);
+    CreateTextureImage(const nsIntSize& aSize,
+                       TextureImage::ContentType aContentType,
+                       GLenum aWrapMode,
+                       TextureImage::Flags aFlags = TextureImage::NoFlags) MOZ_OVERRIDE;
+
+    virtual already_AddRefed<TextureImage>
+    TileGenFunc(const nsIntSize& aSize,
+                TextureImage::ContentType aContentType,
+                TextureImage::Flags aFlags = TextureImage::NoFlags) MOZ_OVERRIDE;
 
     virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType,
                                                    void* buffer,
                                                    SharedTextureBufferType bufferType)
     {
         return GLContextProviderCGL::CreateSharedHandle(shareType, buffer, bufferType);
     }
 
@@ -208,33 +211,38 @@ public:
         MacIOSurface* surf = reinterpret_cast<MacIOSurface*>(sharedHandle);
         surf->CGLTexImageIOSurface2D(mContext, LOCAL_GL_RGBA, LOCAL_GL_BGRA,
                                      LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV, 0);
         return true;
     }
 
     NSOpenGLContext *mContext;
     GLuint mTempTextureName;
+
+    already_AddRefed<TextureImage>
+    CreateTextureImageInternal(const nsIntSize& aSize,
+                               TextureImage::ContentType aContentType,
+                               GLenum aWrapMode,
+                               TextureImage::Flags aFlags);
+
 };
 
 bool
 GLContextCGL::ResizeOffscreen(const gfxIntSize& aNewSize)
 {
     return ResizeScreenBuffer(aNewSize);
 }
 
 class TextureImageCGL : public BasicTextureImage
 {
     friend already_AddRefed<TextureImage>
-    GLContextCGL::CreateBasicTextureImage(GLuint,
-                                          const nsIntSize&,
-                                          GLenum,
-                                          TextureImage::ContentType,
-                                          GLContext*,
-                                          TextureImage::Flags);
+    GLContextCGL::CreateTextureImageInternal(const nsIntSize& aSize,
+                                             TextureImage::ContentType aContentType,
+                                             GLenum aWrapMode,
+                                             TextureImage::Flags aFlags);
 public:
     ~TextureImageCGL()
     {
         if (mPixelBuffer) {
             mGLContext->MakeCurrent();
             mGLContext->fDeleteBuffers(1, &mPixelBuffer);
         }
     }
@@ -324,28 +332,67 @@ private:
     {}
     
     GLuint mPixelBuffer;
     int32_t mPixelBufferSize;
     bool mBoundPixelBuffer;
 };
 
 already_AddRefed<TextureImage>
-GLContextCGL::CreateBasicTextureImage(GLuint aTexture,
-                                      const nsIntSize& aSize,
-                                      GLenum aWrapMode,
-                                      TextureImage::ContentType aContentType,
-                                      GLContext* aContext,
-                                      TextureImage::Flags aFlags)
+GLContextCGL::CreateTextureImageInternal(const nsIntSize& aSize,
+                                         TextureImage::ContentType aContentType,
+                                         GLenum aWrapMode,
+                                         TextureImage::Flags aFlags)
 {
+    bool useNearestFilter = aFlags & TextureImage::UseNearestFilter;
+    MakeCurrent();
+
+    GLuint texture;
+    fGenTextures(1, &texture);
+
+    fActiveTexture(LOCAL_GL_TEXTURE0);
+    fBindTexture(LOCAL_GL_TEXTURE_2D, texture);
+
+    GLint texfilter = useNearestFilter ? LOCAL_GL_NEAREST : LOCAL_GL_LINEAR;
+    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, texfilter);
+    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
+    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, aWrapMode);
+    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, aWrapMode);
+
     nsRefPtr<TextureImageCGL> teximage
-        (new TextureImageCGL(aTexture, aSize, aWrapMode, aContentType, aContext, aFlags));
+        (new TextureImageCGL(texture, aSize, aWrapMode, aContentType, this, aFlags));
     return teximage.forget();
 }
 
+already_AddRefed<TextureImage>
+GLContextCGL::CreateTextureImage(const nsIntSize& aSize,
+                                 TextureImage::ContentType aContentType,
+                                 GLenum aWrapMode,
+                                 TextureImage::Flags aFlags)
+{
+    if (!IsOffscreenSizeAllowed(gfxIntSize(aSize.width, aSize.height)) &&
+        gfxPlatform::OffMainThreadCompositingEnabled()) {
+      NS_ASSERTION(aWrapMode == LOCAL_GL_CLAMP_TO_EDGE, "Can't support wrapping with tiles!");
+      nsRefPtr<TextureImage> t = new gl::TiledTextureImage(this, aSize, aContentType, aFlags);
+      return t.forget();
+    }
+
+    return CreateTextureImageInternal(aSize, aContentType,
+                                      aWrapMode, aFlags);
+}
+
+already_AddRefed<TextureImage>
+GLContextCGL::TileGenFunc(const nsIntSize& aSize,
+                          TextureImage::ContentType aContentType,
+                          TextureImage::Flags aFlags)
+{
+    return CreateTextureImageInternal(aSize, aContentType,
+                                      LOCAL_GL_CLAMP_TO_EDGE, aFlags);
+}
+
 static GLContextCGL *
 GetGlobalContextCGL()
 {
     return static_cast<GLContextCGL*>(GLContextProviderCGL::GetGlobalContext());
 }
 
 already_AddRefed<GLContext>
 GLContextProviderCGL::CreateForWindow(nsIWidget *aWidget)
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -609,17 +609,17 @@ public:
                        TextureImage::ContentType aContentType,
                        GLenum aWrapMode,
                        TextureImage::Flags aFlags = TextureImage::NoFlags);
 
     // a function to generate Tiles for Tiled Texture Image
     virtual already_AddRefed<TextureImage>
     TileGenFunc(const nsIntSize& aSize,
                 TextureImage::ContentType aContentType,
-                TextureImage::Flags aFlags = TextureImage::NoFlags);
+                TextureImage::Flags aFlags = TextureImage::NoFlags) MOZ_OVERRIDE;
     // hold a reference to the given surface
     // for the lifetime of this context.
     void HoldSurface(gfxASurface *aSurf) {
         mThebesSurface = aSurf;
     }
 
     void SetPlatformContext(void *context) {
         mPlatformContext = context;
@@ -1531,18 +1531,18 @@ GLContextEGL::CreateTextureImage(const n
                                  TextureImage::Flags aFlags)
 {
     nsRefPtr<TextureImage> t = new gl::TiledTextureImage(this, aSize, aContentType, aFlags);
     return t.forget();
 }
 
 already_AddRefed<TextureImage>
 GLContextEGL::TileGenFunc(const nsIntSize& aSize,
-                                 TextureImage::ContentType aContentType,
-                                 TextureImage::Flags aFlags)
+                          TextureImage::ContentType aContentType,
+                          TextureImage::Flags aFlags)
 {
   MakeCurrent();
 
   GLuint texture;
   fGenTextures(1, &texture);
 
   nsRefPtr<TextureImageEGL> teximage =
       new TextureImageEGL(texture, aSize, LOCAL_GL_CLAMP_TO_EDGE, aContentType, this, aFlags);