summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
diff options
context:
space:
mode:
authorTeng-Hui Zhu <ztenghui@google.com>2010-11-10 15:31:59 -0800
committerTeng-Hui Zhu <ztenghui@google.com>2010-11-17 13:35:59 -0800
commit28040489d744e0c5d475a88663056c9040ed5320 (patch)
treec463676791e4a63e452a95f0a12b2a8519730693 /WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
parenteff9be92c41913c92fb1d3b7983c071f3e718678 (diff)
downloadexternal_webkit-28040489d744e0c5d475a88663056c9040ed5320.zip
external_webkit-28040489d744e0c5d475a88663056c9040ed5320.tar.gz
external_webkit-28040489d744e0c5d475a88663056c9040ed5320.tar.bz2
Merge WebKit at r71558: Initial merge by git.
Change-Id: Ib345578fa29df7e4bc72b4f00e4a6fddcb754c4c
Diffstat (limited to 'WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp')
-rw-r--r--WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp71
1 files changed, 43 insertions, 28 deletions
diff --git a/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp b/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
index a1cc805..0c6acf9 100644
--- a/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
+++ b/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
@@ -59,7 +59,7 @@ enum AlphaFormat {
AlphaFormatNumFormats
};
-// This returns kSourceFormatNumFormats if the combination of input parameters is unsupported.
+// This returns SourceFormatNumFormats if the combination of input parameters is unsupported.
static GraphicsContext3D::SourceDataFormat getSourceDataFormat(unsigned int componentsPerPixel, AlphaFormat alphaFormat, bool is16BitFormat, bool bigEndian)
{
const static SourceDataFormatBase formatTableBase[4][AlphaFormatNumFormats] = { // componentsPerPixel x AlphaFormat
@@ -69,26 +69,22 @@ static GraphicsContext3D::SourceDataFormat getSourceDataFormat(unsigned int comp
{ SourceFormatBaseRGB, SourceFormatBaseNumFormats, SourceFormatBaseNumFormats }, // 3 componentsPerPixel
{ SourceFormatBaseNumFormats, SourceFormatBaseARGB, SourceFormatBaseRGBA } // 4 componentsPerPixel
};
- const static GraphicsContext3D::SourceDataFormat formatTable[SourceFormatBaseNumFormats][3] = { // SourceDataFormatBase x bitsPerComponentAndEndian
- // 8bits 16bits, little endian 16bits, big endian
- { GraphicsContext3D::kSourceFormatR8, GraphicsContext3D::kSourceFormatR16Little, GraphicsContext3D::kSourceFormatR16Big },
- { GraphicsContext3D::kSourceFormatA8, GraphicsContext3D::kSourceFormatA16Little, GraphicsContext3D::kSourceFormatA16Big },
- { GraphicsContext3D::kSourceFormatRA8, GraphicsContext3D::kSourceFormatRA16Little, GraphicsContext3D::kSourceFormatRA16Big },
- { GraphicsContext3D::kSourceFormatAR8, GraphicsContext3D::kSourceFormatAR16Little, GraphicsContext3D::kSourceFormatAR16Big },
- { GraphicsContext3D::kSourceFormatRGB8, GraphicsContext3D::kSourceFormatRGB16Little, GraphicsContext3D::kSourceFormatRGB16Big },
- { GraphicsContext3D::kSourceFormatRGBA8, GraphicsContext3D::kSourceFormatRGBA16Little, GraphicsContext3D::kSourceFormatRGBA16Big },
- { GraphicsContext3D::kSourceFormatARGB8, GraphicsContext3D::kSourceFormatARGB16Little, GraphicsContext3D::kSourceFormatARGB16Big }
+ const static GraphicsContext3D::SourceDataFormat formatTable[SourceFormatBaseNumFormats][4] = { // SourceDataFormatBase x bitsPerComponent x endian
+ // 8bits, little endian 8bits, big endian 16bits, little endian 16bits, big endian
+ { GraphicsContext3D::SourceFormatR8, GraphicsContext3D::SourceFormatR8, GraphicsContext3D::SourceFormatR16Little, GraphicsContext3D::SourceFormatR16Big },
+ { GraphicsContext3D::SourceFormatA8, GraphicsContext3D::SourceFormatA8, GraphicsContext3D::SourceFormatA16Little, GraphicsContext3D::SourceFormatA16Big },
+ { GraphicsContext3D::SourceFormatAR8, GraphicsContext3D::SourceFormatRA8, GraphicsContext3D::SourceFormatRA16Little, GraphicsContext3D::SourceFormatRA16Big },
+ { GraphicsContext3D::SourceFormatRA8, GraphicsContext3D::SourceFormatAR8, GraphicsContext3D::SourceFormatAR16Little, GraphicsContext3D::SourceFormatAR16Big },
+ { GraphicsContext3D::SourceFormatBGR8, GraphicsContext3D::SourceFormatRGB8, GraphicsContext3D::SourceFormatRGB16Little, GraphicsContext3D::SourceFormatRGB16Big },
+ { GraphicsContext3D::SourceFormatABGR8, GraphicsContext3D::SourceFormatRGBA8, GraphicsContext3D::SourceFormatRGBA16Little, GraphicsContext3D::SourceFormatRGBA16Big },
+ { GraphicsContext3D::SourceFormatBGRA8, GraphicsContext3D::SourceFormatARGB8, GraphicsContext3D::SourceFormatARGB16Little, GraphicsContext3D::SourceFormatARGB16Big }
};
ASSERT(componentsPerPixel <= 4 && componentsPerPixel > 0);
SourceDataFormatBase formatBase = formatTableBase[componentsPerPixel - 1][alphaFormat];
if (formatBase == SourceFormatBaseNumFormats)
- return GraphicsContext3D::kSourceFormatNumFormats;
- if (!is16BitFormat)
- return formatTable[formatBase][0];
- if (!bigEndian)
- return formatTable[formatBase][1];
- return formatTable[formatBase][2];
+ return GraphicsContext3D::SourceFormatNumFormats;
+ return formatTable[formatBase][(is16BitFormat ? 2 : 0) + (bigEndian ? 1 : 0)];
}
bool GraphicsContext3D::getImageData(Image* image,
@@ -125,28 +121,47 @@ bool GraphicsContext3D::getImageData(Image* image,
return false;
size_t componentsPerPixel = bitsPerPixel / bitsPerComponent;
- bool srcByteOrder16Big = false;
+ CGBitmapInfo bitInfo = CGImageGetBitmapInfo(cgImage);
+ bool bigEndianSource = false;
+ // These could technically be combined into one large switch
+ // statement, but we prefer not to so that we fail fast if we
+ // encounter an unexpected image configuration.
if (bitsPerComponent == 16) {
- CGBitmapInfo bitInfo = CGImageGetBitmapInfo(cgImage);
switch (bitInfo & kCGBitmapByteOrderMask) {
case kCGBitmapByteOrder16Big:
- srcByteOrder16Big = true;
+ bigEndianSource = true;
break;
case kCGBitmapByteOrder16Little:
- srcByteOrder16Big = false;
+ bigEndianSource = false;
break;
case kCGBitmapByteOrderDefault:
// This is a bug in earlier version of cg where the default endian
// is little whereas the decoded 16-bit png image data is actually
// Big. Later version (10.6.4) no longer returns ByteOrderDefault.
- srcByteOrder16Big = true;
+ bigEndianSource = true;
+ break;
+ default:
+ return false;
+ }
+ } else {
+ switch (bitInfo & kCGBitmapByteOrderMask) {
+ case kCGBitmapByteOrder32Big:
+ bigEndianSource = true;
+ break;
+ case kCGBitmapByteOrder32Little:
+ bigEndianSource = false;
+ break;
+ case kCGBitmapByteOrderDefault:
+ // It appears that the default byte order is actually big
+ // endian even on little endian architectures.
+ bigEndianSource = true;
break;
default:
return false;
}
}
- AlphaOp neededAlphaOp = kAlphaDoNothing;
+ AlphaOp neededAlphaOp = AlphaDoNothing;
AlphaFormat alphaFormat = AlphaFormatNone;
switch (CGImageGetAlphaInfo(cgImage)) {
case kCGImageAlphaPremultipliedFirst:
@@ -155,13 +170,13 @@ bool GraphicsContext3D::getImageData(Image* image,
// in which case image->data() should be null.
ASSERT(!image->data());
if (!premultiplyAlpha)
- neededAlphaOp = kAlphaDoUnmultiply;
+ neededAlphaOp = AlphaDoUnmultiply;
alphaFormat = AlphaFormatFirst;
break;
case kCGImageAlphaFirst:
// This path is only accessible for MacOS earlier than 10.6.4.
if (premultiplyAlpha)
- neededAlphaOp = kAlphaDoPremultiply;
+ neededAlphaOp = AlphaDoPremultiply;
alphaFormat = AlphaFormatFirst;
break;
case kCGImageAlphaNoneSkipFirst:
@@ -173,12 +188,12 @@ bool GraphicsContext3D::getImageData(Image* image,
// in which case image->data() should be null.
ASSERT(!image->data());
if (!premultiplyAlpha)
- neededAlphaOp = kAlphaDoUnmultiply;
+ neededAlphaOp = AlphaDoUnmultiply;
alphaFormat = AlphaFormatLast;
break;
case kCGImageAlphaLast:
if (premultiplyAlpha)
- neededAlphaOp = kAlphaDoPremultiply;
+ neededAlphaOp = AlphaDoPremultiply;
alphaFormat = AlphaFormatLast;
break;
case kCGImageAlphaNoneSkipLast:
@@ -190,8 +205,8 @@ bool GraphicsContext3D::getImageData(Image* image,
default:
return false;
}
- SourceDataFormat srcDataFormat = getSourceDataFormat(componentsPerPixel, alphaFormat, bitsPerComponent == 16, srcByteOrder16Big);
- if (srcDataFormat == kSourceFormatNumFormats)
+ SourceDataFormat srcDataFormat = getSourceDataFormat(componentsPerPixel, alphaFormat, bitsPerComponent == 16, bigEndianSource);
+ if (srcDataFormat == SourceFormatNumFormats)
return false;
RetainPtr<CFDataRef> pixelData;