Sat, 03 Jan 2015 20:18:00 +0100
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++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 "TextureImageCGL.h" |
michael@0 | 7 | #include "GLContext.h" |
michael@0 | 8 | #include "gfx2DGlue.h" |
michael@0 | 9 | #include "gfxQuartzSurface.h" |
michael@0 | 10 | #include "gfxPlatform.h" |
michael@0 | 11 | #include "gfxFailure.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | |
michael@0 | 15 | using namespace gfx; |
michael@0 | 16 | |
michael@0 | 17 | namespace gl { |
michael@0 | 18 | |
michael@0 | 19 | TextureImageCGL::TextureImageCGL(GLuint aTexture, |
michael@0 | 20 | const nsIntSize& aSize, |
michael@0 | 21 | GLenum aWrapMode, |
michael@0 | 22 | ContentType aContentType, |
michael@0 | 23 | GLContext* aContext, |
michael@0 | 24 | TextureImage::Flags aFlags, |
michael@0 | 25 | TextureImage::ImageFormat aImageFormat) |
michael@0 | 26 | : BasicTextureImage(aTexture, aSize, aWrapMode, aContentType, |
michael@0 | 27 | aContext, aFlags, aImageFormat) |
michael@0 | 28 | , mPixelBuffer(0) |
michael@0 | 29 | , mPixelBufferSize(0) |
michael@0 | 30 | , mBoundPixelBuffer(false) |
michael@0 | 31 | {} |
michael@0 | 32 | |
michael@0 | 33 | TextureImageCGL::~TextureImageCGL() |
michael@0 | 34 | { |
michael@0 | 35 | if (mPixelBuffer) { |
michael@0 | 36 | mGLContext->MakeCurrent(); |
michael@0 | 37 | mGLContext->fDeleteBuffers(1, &mPixelBuffer); |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | already_AddRefed<gfxASurface> |
michael@0 | 42 | TextureImageCGL::GetSurfaceForUpdate(const gfxIntSize& aSize, ImageFormat aFmt) |
michael@0 | 43 | { |
michael@0 | 44 | IntSize size(aSize.width + 1, aSize.height + 1); |
michael@0 | 45 | mGLContext->MakeCurrent(); |
michael@0 | 46 | if (!mGLContext-> |
michael@0 | 47 | IsExtensionSupported(GLContext::ARB_pixel_buffer_object)) |
michael@0 | 48 | { |
michael@0 | 49 | return gfxPlatform::GetPlatform()-> |
michael@0 | 50 | CreateOffscreenSurface(size, |
michael@0 | 51 | gfxASurface::ContentFromFormat(aFmt)); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | if (!mPixelBuffer) { |
michael@0 | 55 | mGLContext->fGenBuffers(1, &mPixelBuffer); |
michael@0 | 56 | } |
michael@0 | 57 | mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, mPixelBuffer); |
michael@0 | 58 | int32_t length = size.width * 4 * size.height; |
michael@0 | 59 | |
michael@0 | 60 | if (length > mPixelBufferSize) { |
michael@0 | 61 | mGLContext->fBufferData(LOCAL_GL_PIXEL_UNPACK_BUFFER, length, |
michael@0 | 62 | NULL, LOCAL_GL_STREAM_DRAW); |
michael@0 | 63 | mPixelBufferSize = length; |
michael@0 | 64 | } |
michael@0 | 65 | unsigned char* data = |
michael@0 | 66 | (unsigned char*)mGLContext-> |
michael@0 | 67 | fMapBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, |
michael@0 | 68 | LOCAL_GL_WRITE_ONLY); |
michael@0 | 69 | |
michael@0 | 70 | mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0); |
michael@0 | 71 | |
michael@0 | 72 | if (!data) { |
michael@0 | 73 | nsAutoCString failure; |
michael@0 | 74 | failure += "Pixel buffer binding failed: "; |
michael@0 | 75 | failure.AppendPrintf("%dx%d\n", size.width, size.height); |
michael@0 | 76 | gfx::LogFailure(failure); |
michael@0 | 77 | |
michael@0 | 78 | mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0); |
michael@0 | 79 | return gfxPlatform::GetPlatform()-> |
michael@0 | 80 | CreateOffscreenSurface(size, |
michael@0 | 81 | gfxASurface::ContentFromFormat(aFmt)); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | nsRefPtr<gfxQuartzSurface> surf = |
michael@0 | 85 | new gfxQuartzSurface(data, ThebesIntSize(size), size.width * 4, aFmt); |
michael@0 | 86 | |
michael@0 | 87 | mBoundPixelBuffer = true; |
michael@0 | 88 | return surf.forget(); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | bool |
michael@0 | 92 | TextureImageCGL::FinishedSurfaceUpdate() |
michael@0 | 93 | { |
michael@0 | 94 | if (mBoundPixelBuffer) { |
michael@0 | 95 | mGLContext->MakeCurrent(); |
michael@0 | 96 | mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, mPixelBuffer); |
michael@0 | 97 | mGLContext->fUnmapBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER); |
michael@0 | 98 | return true; |
michael@0 | 99 | } |
michael@0 | 100 | return false; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | void |
michael@0 | 104 | TextureImageCGL::FinishedSurfaceUpload() |
michael@0 | 105 | { |
michael@0 | 106 | if (mBoundPixelBuffer) { |
michael@0 | 107 | mGLContext->MakeCurrent(); |
michael@0 | 108 | mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0); |
michael@0 | 109 | mBoundPixelBuffer = false; |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | already_AddRefed<TextureImage> |
michael@0 | 114 | CreateTextureImageCGL(GLContext* gl, |
michael@0 | 115 | const gfx::IntSize& aSize, |
michael@0 | 116 | TextureImage::ContentType aContentType, |
michael@0 | 117 | GLenum aWrapMode, |
michael@0 | 118 | TextureImage::Flags aFlags, |
michael@0 | 119 | TextureImage::ImageFormat aImageFormat) |
michael@0 | 120 | { |
michael@0 | 121 | if (!gl->IsOffscreenSizeAllowed(aSize) && |
michael@0 | 122 | gfxPlatform::OffMainThreadCompositingEnabled()) { |
michael@0 | 123 | NS_ASSERTION(aWrapMode == LOCAL_GL_CLAMP_TO_EDGE, "Can't support wrapping with tiles!"); |
michael@0 | 124 | nsRefPtr<TextureImage> t = new gl::TiledTextureImage(gl, aSize, aContentType, |
michael@0 | 125 | aFlags, aImageFormat); |
michael@0 | 126 | return t.forget(); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | return CreateBasicTextureImage(gl, aSize, aContentType, aWrapMode, |
michael@0 | 130 | aFlags, aImageFormat); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | already_AddRefed<TextureImage> |
michael@0 | 134 | TileGenFuncCGL(GLContext *gl, |
michael@0 | 135 | const nsIntSize& aSize, |
michael@0 | 136 | TextureImage::ContentType aContentType, |
michael@0 | 137 | TextureImage::Flags aFlags, |
michael@0 | 138 | TextureImage::ImageFormat aImageFormat) |
michael@0 | 139 | { |
michael@0 | 140 | bool useNearestFilter = aFlags & TextureImage::UseNearestFilter; |
michael@0 | 141 | gl->MakeCurrent(); |
michael@0 | 142 | |
michael@0 | 143 | GLuint texture; |
michael@0 | 144 | gl->fGenTextures(1, &texture); |
michael@0 | 145 | |
michael@0 | 146 | gl->fActiveTexture(LOCAL_GL_TEXTURE0); |
michael@0 | 147 | gl->fBindTexture(LOCAL_GL_TEXTURE_2D, texture); |
michael@0 | 148 | |
michael@0 | 149 | GLint texfilter = useNearestFilter ? LOCAL_GL_NEAREST : LOCAL_GL_LINEAR; |
michael@0 | 150 | gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, texfilter); |
michael@0 | 151 | gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter); |
michael@0 | 152 | gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); |
michael@0 | 153 | gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); |
michael@0 | 154 | |
michael@0 | 155 | nsRefPtr<TextureImageCGL> teximage |
michael@0 | 156 | (new TextureImageCGL(texture, aSize, LOCAL_GL_CLAMP_TO_EDGE, aContentType, |
michael@0 | 157 | gl, aFlags, aImageFormat)); |
michael@0 | 158 | return teximage.forget(); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | } |
michael@0 | 162 | } |