gfx/skia/patches/0024-Bug-887318-fix-bgra-readback.patch

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 diff --git a/gfx/gl/GLContextSkia.cpp b/gfx/gl/GLContextSkia.cpp
michael@0 2 --- a/gfx/gl/GLContextSkia.cpp
michael@0 3 +++ b/gfx/gl/GLContextSkia.cpp
michael@0 4 @@ -303,39 +303,47 @@ const GLubyte* glGetString_mozilla(GrGLe
michael@0 5 if (name == LOCAL_GL_VERSION) {
michael@0 6 if (sGLContext.get()->IsGLES2()) {
michael@0 7 return reinterpret_cast<const GLubyte*>("OpenGL ES 2.0");
michael@0 8 } else {
michael@0 9 return reinterpret_cast<const GLubyte*>("2.0");
michael@0 10 }
michael@0 11 } else if (name == LOCAL_GL_EXTENSIONS) {
michael@0 12 // Only expose the bare minimum extensions we want to support to ensure a functional Ganesh
michael@0 13 // as GLContext only exposes certain extensions
michael@0 14 static bool extensionsStringBuilt = false;
michael@0 15 - static char extensionsString[120];
michael@0 16 + static char extensionsString[256];
michael@0 17
michael@0 18 if (!extensionsStringBuilt) {
michael@0 19 if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_texture_format_BGRA8888)) {
michael@0 20 strcpy(extensionsString, "GL_EXT_texture_format_BGRA8888 ");
michael@0 21 }
michael@0 22
michael@0 23 if (sGLContext.get()->IsExtensionSupported(GLContext::OES_packed_depth_stencil)) {
michael@0 24 strcat(extensionsString, "GL_OES_packed_depth_stencil ");
michael@0 25 }
michael@0 26
michael@0 27 if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_packed_depth_stencil)) {
michael@0 28 strcat(extensionsString, "GL_EXT_packed_depth_stencil ");
michael@0 29 }
michael@0 30
michael@0 31 if (sGLContext.get()->IsExtensionSupported(GLContext::OES_rgb8_rgba8)) {
michael@0 32 strcat(extensionsString, "GL_OES_rgb8_rgba8 ");
michael@0 33 }
michael@0 34
michael@0 35 + if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_bgra)) {
michael@0 36 + strcat(extensionsString, "GL_EXT_bgra ");
michael@0 37 + }
michael@0 38 +
michael@0 39 + if (sGLContext.get()->IsExtensionSupported(GLContext::EXT_read_format_bgra)) {
michael@0 40 + strcat(extensionsString, "GL_EXT_read_format_bgra ");
michael@0 41 + }
michael@0 42 +
michael@0 43 extensionsStringBuilt = true;
michael@0 44 }
michael@0 45
michael@0 46 return reinterpret_cast<const GLubyte*>(extensionsString);
michael@0 47
michael@0 48 } else if (name == LOCAL_GL_SHADING_LANGUAGE_VERSION) {
michael@0 49 if (sGLContext.get()->IsGLES2()) {
michael@0 50 return reinterpret_cast<const GLubyte*>("OpenGL ES GLSL ES 1.0");
michael@0 51 } else {
michael@0 52 return reinterpret_cast<const GLubyte*>("1.10");
michael@0 53 diff --git a/gfx/skia/src/gpu/gl/GrGpuGL.cpp b/gfx/skia/src/gpu/gl/GrGpuGL.cpp
michael@0 54 --- a/gfx/skia/src/gpu/gl/GrGpuGL.cpp
michael@0 55 +++ b/gfx/skia/src/gpu/gl/GrGpuGL.cpp
michael@0 56 @@ -1,18 +1,18 @@
michael@0 57 /*
michael@0 58 * Copyright 2011 Google Inc.
michael@0 59 *
michael@0 60 * Use of this source code is governed by a BSD-style license that can be
michael@0 61 * found in the LICENSE file.
michael@0 62 */
michael@0 63
michael@0 64 -
michael@0 65 +#include <algorithm>
michael@0 66 #include "GrGpuGL.h"
michael@0 67 #include "GrGLStencilBuffer.h"
michael@0 68 #include "GrGLPath.h"
michael@0 69 #include "GrGLShaderBuilder.h"
michael@0 70 #include "GrTemplates.h"
michael@0 71 #include "GrTypes.h"
michael@0 72 #include "SkTemplates.h"
michael@0 73
michael@0 74 static const GrGLuint GR_MAX_GLUINT = ~0U;
michael@0 75 static const GrGLint GR_INVAL_GLINT = ~0;
michael@0 76 @@ -1381,29 +1381,67 @@ bool GrGpuGL::readPixelsWillPayForYFlip(
michael@0 77 // Note the rowBytes might be tight to the passed in data, but if data
michael@0 78 // gets clipped in x to the target the rowBytes will no longer be tight.
michael@0 79 if (left >= 0 && (left + width) < renderTarget->width()) {
michael@0 80 return 0 == rowBytes ||
michael@0 81 GrBytesPerPixel(config) * width == rowBytes;
michael@0 82 } else {
michael@0 83 return false;
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 +static void swizzleRow(void* buffer, int byteLen) {
michael@0 88 + uint8_t* src = (uint8_t*)buffer;
michael@0 89 + uint8_t* end = src + byteLen;
michael@0 90 +
michael@0 91 + GrAssert((end - src) % 4 == 0);
michael@0 92 +
michael@0 93 + for (; src != end; src += 4) {
michael@0 94 + std::swap(src[0], src[2]);
michael@0 95 + }
michael@0 96 +}
michael@0 97 +
michael@0 98 +bool GrGpuGL::canReadBGRA() const
michael@0 99 +{
michael@0 100 + if (kDesktop_GrGLBinding == this->glBinding() ||
michael@0 101 + this->hasExtension("GL_EXT_bgra"))
michael@0 102 + return true;
michael@0 103 +
michael@0 104 + if (this->hasExtension("GL_EXT_read_format_bgra")) {
michael@0 105 + GrGLint readFormat = 0;
michael@0 106 + GrGLint readType = 0;
michael@0 107 +
michael@0 108 + GL_CALL(GetIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, &readFormat));
michael@0 109 + GL_CALL(GetIntegerv(GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, &readType));
michael@0 110 +
michael@0 111 + return readFormat == GR_GL_BGRA && readType == GR_GL_UNSIGNED_BYTE;
michael@0 112 + }
michael@0 113 +
michael@0 114 + return false;
michael@0 115 +}
michael@0 116 +
michael@0 117 bool GrGpuGL::onReadPixels(GrRenderTarget* target,
michael@0 118 int left, int top,
michael@0 119 int width, int height,
michael@0 120 GrPixelConfig config,
michael@0 121 void* buffer,
michael@0 122 size_t rowBytes) {
michael@0 123 GrGLenum format;
michael@0 124 GrGLenum type;
michael@0 125 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin();
michael@0 126 + bool needSwizzle = false;
michael@0 127 +
michael@0 128 + if (kBGRA_8888_GrPixelConfig == config && !this->canReadBGRA()) {
michael@0 129 + // Read RGBA and swizzle after
michael@0 130 + config = kRGBA_8888_GrPixelConfig;
michael@0 131 + needSwizzle = true;
michael@0 132 + }
michael@0 133 +
michael@0 134 if (!this->configToGLFormats(config, false, NULL, &format, &type)) {
michael@0 135 return false;
michael@0 136 }
michael@0 137 size_t bpp = GrBytesPerPixel(config);
michael@0 138 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp,
michael@0 139 &left, &top, &width, &height,
michael@0 140 const_cast<const void**>(&buffer),
michael@0 141 &rowBytes)) {
michael@0 142 return false;
michael@0 143 }
michael@0 144 @@ -1478,35 +1516,46 @@ bool GrGpuGL::onReadPixels(GrRenderTarge
michael@0 145 scratch.reset(tightRowBytes);
michael@0 146 void* tmpRow = scratch.get();
michael@0 147 // flip y in-place by rows
michael@0 148 const int halfY = height >> 1;
michael@0 149 char* top = reinterpret_cast<char*>(buffer);
michael@0 150 char* bottom = top + (height - 1) * rowBytes;
michael@0 151 for (int y = 0; y < halfY; y++) {
michael@0 152 memcpy(tmpRow, top, tightRowBytes);
michael@0 153 memcpy(top, bottom, tightRowBytes);
michael@0 154 memcpy(bottom, tmpRow, tightRowBytes);
michael@0 155 +
michael@0 156 + if (needSwizzle) {
michael@0 157 + swizzleRow(top, tightRowBytes);
michael@0 158 + swizzleRow(bottom, tightRowBytes);
michael@0 159 + }
michael@0 160 +
michael@0 161 top += rowBytes;
michael@0 162 bottom -= rowBytes;
michael@0 163 }
michael@0 164 }
michael@0 165 } else {
michael@0 166 - GrAssert(readDst != buffer); GrAssert(rowBytes != tightRowBytes);
michael@0 167 + GrAssert(readDst != buffer);
michael@0 168 + GrAssert(rowBytes != tightRowBytes);
michael@0 169 // copy from readDst to buffer while flipping y
michael@0 170 // const int halfY = height >> 1;
michael@0 171 const char* src = reinterpret_cast<const char*>(readDst);
michael@0 172 char* dst = reinterpret_cast<char*>(buffer);
michael@0 173 if (flipY) {
michael@0 174 dst += (height-1) * rowBytes;
michael@0 175 }
michael@0 176 for (int y = 0; y < height; y++) {
michael@0 177 memcpy(dst, src, tightRowBytes);
michael@0 178 + if (needSwizzle) {
michael@0 179 + swizzleRow(dst, tightRowBytes);
michael@0 180 + }
michael@0 181 +
michael@0 182 src += readDstRowBytes;
michael@0 183 if (!flipY) {
michael@0 184 dst += rowBytes;
michael@0 185 } else {
michael@0 186 dst -= rowBytes;
michael@0 187 }
michael@0 188 }
michael@0 189 }
michael@0 190 return true;
michael@0 191 }
michael@0 192 diff --git a/gfx/skia/src/gpu/gl/GrGpuGL.h b/gfx/skia/src/gpu/gl/GrGpuGL.h
michael@0 193 --- a/gfx/skia/src/gpu/gl/GrGpuGL.h
michael@0 194 +++ b/gfx/skia/src/gpu/gl/GrGpuGL.h
michael@0 195 @@ -243,20 +243,22 @@ private:
michael@0 196 GrPixelConfig dataConfig,
michael@0 197 const void* data,
michael@0 198 size_t rowBytes);
michael@0 199
michael@0 200 bool createRenderTargetObjects(int width, int height,
michael@0 201 GrGLuint texID,
michael@0 202 GrGLRenderTarget::Desc* desc);
michael@0 203
michael@0 204 void fillInConfigRenderableTable();
michael@0 205
michael@0 206 + bool canReadBGRA() const;
michael@0 207 +
michael@0 208 GrGLContext fGLContext;
michael@0 209
michael@0 210 // GL program-related state
michael@0 211 ProgramCache* fProgramCache;
michael@0 212 SkAutoTUnref<GrGLProgram> fCurrentProgram;
michael@0 213
michael@0 214 ///////////////////////////////////////////////////////////////////////////
michael@0 215 ///@name Caching of GL State
michael@0 216 ///@{
michael@0 217 int fHWActiveTextureUnitIdx;

mercurial