gfx/gl/SharedSurfaceIO.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "SharedSurfaceIO.h"
michael@0 7 #include "GLContextCGL.h"
michael@0 8 #include "mozilla/gfx/MacIOSurface.h"
michael@0 9 #include "mozilla/DebugOnly.h"
michael@0 10 #include "ScopedGLHelpers.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace gl {
michael@0 14
michael@0 15 using namespace gfx;
michael@0 16
michael@0 17 /* static */ SharedSurface_IOSurface*
michael@0 18 SharedSurface_IOSurface::Create(MacIOSurface* surface, GLContext *gl, bool hasAlpha)
michael@0 19 {
michael@0 20 MOZ_ASSERT(surface);
michael@0 21 MOZ_ASSERT(gl);
michael@0 22
michael@0 23 gfx::IntSize size(surface->GetWidth(), surface->GetHeight());
michael@0 24 return new SharedSurface_IOSurface(surface, gl, size, hasAlpha);
michael@0 25 }
michael@0 26
michael@0 27 void
michael@0 28 SharedSurface_IOSurface::Fence()
michael@0 29 {
michael@0 30 mGL->MakeCurrent();
michael@0 31 mGL->fFlush();
michael@0 32 }
michael@0 33
michael@0 34 bool
michael@0 35 SharedSurface_IOSurface::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
michael@0 36 GLenum format, GLenum type, GLvoid *pixels)
michael@0 37 {
michael@0 38 // Calling glReadPixels when an IOSurface is bound to the current framebuffer
michael@0 39 // can cause corruption in following glReadPixel calls (even if they aren't
michael@0 40 // reading from an IOSurface).
michael@0 41 // We workaround this by copying to a temporary texture, and doing the readback
michael@0 42 // from that.
michael@0 43 MOZ_ASSERT(mGL->IsCurrent());
michael@0 44
michael@0 45
michael@0 46 ScopedTexture destTex(mGL);
michael@0 47 {
michael@0 48 ScopedFramebufferForTexture srcFB(mGL, ProdTexture(), ProdTextureTarget());
michael@0 49
michael@0 50 ScopedBindFramebuffer bindFB(mGL, srcFB.FB());
michael@0 51 ScopedBindTexture bindTex(mGL, destTex.Texture());
michael@0 52 mGL->fCopyTexImage2D(LOCAL_GL_TEXTURE_2D, 0,
michael@0 53 HasAlpha() ? LOCAL_GL_RGBA : LOCAL_GL_RGB,
michael@0 54 x, y,
michael@0 55 width, height, 0);
michael@0 56 }
michael@0 57
michael@0 58 ScopedFramebufferForTexture destFB(mGL, destTex.Texture());
michael@0 59
michael@0 60 ScopedBindFramebuffer bindFB(mGL, destFB.FB());
michael@0 61 mGL->fReadPixels(0, 0, width, height, format, type, pixels);
michael@0 62 return true;
michael@0 63 }
michael@0 64
michael@0 65 static void
michael@0 66 BackTextureWithIOSurf(GLContext* gl, GLuint tex, MacIOSurface* ioSurf)
michael@0 67 {
michael@0 68 MOZ_ASSERT(gl->IsCurrent());
michael@0 69
michael@0 70 ScopedBindTexture texture(gl, tex, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
michael@0 71
michael@0 72 gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
michael@0 73 LOCAL_GL_TEXTURE_MIN_FILTER,
michael@0 74 LOCAL_GL_LINEAR);
michael@0 75 gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
michael@0 76 LOCAL_GL_TEXTURE_MAG_FILTER,
michael@0 77 LOCAL_GL_LINEAR);
michael@0 78 gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
michael@0 79 LOCAL_GL_TEXTURE_WRAP_S,
michael@0 80 LOCAL_GL_CLAMP_TO_EDGE);
michael@0 81 gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB,
michael@0 82 LOCAL_GL_TEXTURE_WRAP_T,
michael@0 83 LOCAL_GL_CLAMP_TO_EDGE);
michael@0 84
michael@0 85 CGLContextObj cgl = GLContextCGL::Cast(gl)->GetCGLContext();
michael@0 86 MOZ_ASSERT(cgl);
michael@0 87
michael@0 88 ioSurf->CGLTexImageIOSurface2D(cgl);
michael@0 89 }
michael@0 90
michael@0 91 SharedSurface_IOSurface::SharedSurface_IOSurface(MacIOSurface* surface,
michael@0 92 GLContext* gl,
michael@0 93 const gfx::IntSize& size,
michael@0 94 bool hasAlpha)
michael@0 95 : SharedSurface_GL(SharedSurfaceType::IOSurface, AttachmentType::GLTexture, gl, size, hasAlpha)
michael@0 96 , mSurface(surface)
michael@0 97 , mCurConsGL(nullptr)
michael@0 98 , mConsTex(0)
michael@0 99 {
michael@0 100 gl->MakeCurrent();
michael@0 101 mProdTex = 0;
michael@0 102 gl->fGenTextures(1, &mProdTex);
michael@0 103 BackTextureWithIOSurf(gl, mProdTex, surface);
michael@0 104 }
michael@0 105
michael@0 106 GLuint
michael@0 107 SharedSurface_IOSurface::ConsTexture(GLContext* consGL)
michael@0 108 {
michael@0 109 if (!mCurConsGL) {
michael@0 110 mCurConsGL = consGL;
michael@0 111 }
michael@0 112 MOZ_ASSERT(consGL == mCurConsGL);
michael@0 113
michael@0 114 if (!mConsTex) {
michael@0 115 consGL->MakeCurrent();
michael@0 116 mConsTex = 0;
michael@0 117 consGL->fGenTextures(1, &mConsTex);
michael@0 118 BackTextureWithIOSurf(consGL, mConsTex, mSurface);
michael@0 119 }
michael@0 120
michael@0 121 return mConsTex;
michael@0 122 }
michael@0 123
michael@0 124 SharedSurface_IOSurface::~SharedSurface_IOSurface()
michael@0 125 {
michael@0 126 if (mProdTex) {
michael@0 127 DebugOnly<bool> success = mGL->MakeCurrent();
michael@0 128 MOZ_ASSERT(success);
michael@0 129 mGL->fDeleteTextures(1, &mProdTex);
michael@0 130 mGL->fDeleteTextures(1, &mConsTex); // This will work if we're shared.
michael@0 131 }
michael@0 132 }
michael@0 133
michael@0 134 SharedSurface*
michael@0 135 SurfaceFactory_IOSurface::CreateShared(const gfx::IntSize& size)
michael@0 136 {
michael@0 137 bool hasAlpha = mReadCaps.alpha;
michael@0 138 RefPtr<MacIOSurface> surf =
michael@0 139 MacIOSurface::CreateIOSurface(size.width, size.height, 1.0, hasAlpha);
michael@0 140
michael@0 141 if (!surf) {
michael@0 142 NS_WARNING("Failed to create MacIOSurface.");
michael@0 143 return nullptr;
michael@0 144 }
michael@0 145
michael@0 146 return SharedSurface_IOSurface::Create(surf, mGL, hasAlpha);
michael@0 147 }
michael@0 148
michael@0 149 }
michael@0 150 }

mercurial