<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[161783] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/161783">161783</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-01-11 14:56:40 -0800 (Sat, 11 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Extract the FormatConverter class out of GraphicsContext3D.cpp and into its own file
https://bugs.webkit.org/show_bug.cgi?id=126820
Patch by Sam Weinig <sam@webkit.org> on 2014-01-11
Reviewed by Anders Carlsson.
* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/FormatConverter.cpp: Copied from Source/WebCore/platform/graphics/GraphicsContext3D.cpp.
(WebCore::convertFloatToHalfFloat):
(WebCore::FormatConverter::convert):
* platform/graphics/FormatConverter.h: Copied from Source/WebCore/platform/graphics/GraphicsContext3D.cpp.
(WebCore::FormatConverter::FormatConverter):
(WebCore::FormatConverter::success):
* platform/graphics/GraphicsContext3D.cpp:
(WebCore::GraphicsContext3D::computeFormatAndTypeParameters):
(WebCore::GraphicsContext3D::computeImageSizeInBytes):
(WebCore::GraphicsContext3D::packImageData):
(WebCore::GraphicsContext3D::extractImageData):
(WebCore::GraphicsContext3D::extractTextureData):
(WebCore::GraphicsContext3D::packPixels):
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::hasAlpha):
(WebCore::GraphicsContext3D::hasColor):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreGNUmakefilelistam">trunk/Source/WebCore/GNUmakefile.list.am</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContext3Dcpp">trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContext3Dh">trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicsFormatConvertercpp">trunk/Source/WebCore/platform/graphics/FormatConverter.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFormatConverterh">trunk/Source/WebCore/platform/graphics/FormatConverter.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/CMakeLists.txt        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -2979,6 +2979,7 @@
</span><span class="cx"> list(APPEND WebCore_SOURCES
</span><span class="cx"> platform/graphics/ANGLEWebKitBridge.cpp
</span><span class="cx"> platform/graphics/GraphicsContext3D.cpp
</span><ins>+ platform/graphics/FormatConverter.cpp
</ins><span class="cx">
</span><span class="cx"> platform/graphics/gpu/DrawingBuffer.cpp
</span><span class="cx"> )
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/ChangeLog        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2014-01-11 Sam Weinig <sam@webkit.org>
+
+ Extract the FormatConverter class out of GraphicsContext3D.cpp and into its own file
+ https://bugs.webkit.org/show_bug.cgi?id=126820
+
+ Reviewed by Anders Carlsson.
+
+ * CMakeLists.txt:
+ * GNUmakefile.list.am:
+ * WebCore.vcxproj/WebCore.vcxproj:
+ * WebCore.vcxproj/WebCore.vcxproj.filters:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/FormatConverter.cpp: Copied from Source/WebCore/platform/graphics/GraphicsContext3D.cpp.
+ (WebCore::convertFloatToHalfFloat):
+ (WebCore::FormatConverter::convert):
+ * platform/graphics/FormatConverter.h: Copied from Source/WebCore/platform/graphics/GraphicsContext3D.cpp.
+ (WebCore::FormatConverter::FormatConverter):
+ (WebCore::FormatConverter::success):
+ * platform/graphics/GraphicsContext3D.cpp:
+ (WebCore::GraphicsContext3D::computeFormatAndTypeParameters):
+ (WebCore::GraphicsContext3D::computeImageSizeInBytes):
+ (WebCore::GraphicsContext3D::packImageData):
+ (WebCore::GraphicsContext3D::extractImageData):
+ (WebCore::GraphicsContext3D::extractTextureData):
+ (WebCore::GraphicsContext3D::packPixels):
+ * platform/graphics/GraphicsContext3D.h:
+ (WebCore::GraphicsContext3D::hasAlpha):
+ (WebCore::GraphicsContext3D::hasColor):
+
</ins><span class="cx"> 2014-01-11 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix updateScrollingLayerWithClient() for iOS.
</span></span></pre></div>
<a id="trunkSourceWebCoreGNUmakefilelistam"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/GNUmakefile.list.am (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/GNUmakefile.list.am        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/GNUmakefile.list.am        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -5366,6 +5366,8 @@
</span><span class="cx">         Source/WebCore/platform/graphics/filters/FilterOperations.h \
</span><span class="cx">         Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp \
</span><span class="cx">         Source/WebCore/platform/graphics/gpu/DrawingBuffer.h \
</span><ins>+        Source/WebCore/platform/graphics/FormatConverter.cpp \
+        Source/WebCore/platform/graphics/FormatConverter.h \
</ins><span class="cx">         Source/WebCore/platform/graphics/GraphicsContext3D.cpp \
</span><span class="cx">         Source/WebCore/platform/graphics/GraphicsContext3D.h \
</span><span class="cx">         Source/WebCore/platform/graphics/GraphicsLayer.h \
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -7295,6 +7295,7 @@
</span><span class="cx"> <ClCompile Include="..\platform\graphics\gpu\SharedGraphicsContext3D.cpp" />
</span><span class="cx"> <ClCompile Include="..\platform\graphics\gpu\Texture.cpp" />
</span><span class="cx"> <ClCompile Include="..\platform\graphics\gpu\TilingData.cpp" />
</span><ins>+ <ClCompile Include="..\platform\graphics\FormatConverter.cpp" />
</ins><span class="cx"> <ClCompile Include="..\platform\graphics\GraphicsContext3D.cpp" />
</span><span class="cx"> <ClCompile Include="..\platform\graphics\GraphicsLayerAnimation.cpp" />
</span><span class="cx"> <ClCompile Include="..\platform\graphics\GraphicsLayerTransform.cpp" />
</span><span class="lines">@@ -19073,6 +19074,7 @@
</span><span class="cx"> <ClInclude Include="..\platform\graphics\gpu\SharedGraphicsContext3D.h" />
</span><span class="cx"> <ClInclude Include="..\platform\graphics\gpu\Texture.h" />
</span><span class="cx"> <ClInclude Include="..\platform\graphics\gpu\TilingData.h" />
</span><ins>+ <ClInclude Include="..\platform\graphics\FormatConverter.h" />
</ins><span class="cx"> <ClInclude Include="..\platform\graphics\GraphicsContext3D.h" />
</span><span class="cx"> <ClInclude Include="..\platform\graphics\GraphicsLayerAnimation.h" />
</span><span class="cx"> <ClInclude Include="..\platform\graphics\GraphicsLayerFactory.h" />
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -6739,6 +6739,9 @@
</span><span class="cx"> <ClCompile Include="..\platform\graphics\ANGLEWebKitBridge.cpp">
</span><span class="cx"> <Filter>platform\graphics</Filter>
</span><span class="cx"> </ClCompile>
</span><ins>+ <ClCompile Include="..\platform\graphics\FormatConverter.cpp">
+ <Filter>platform\graphics</Filter>
+ </ClCompile>
</ins><span class="cx"> <ClCompile Include="..\platform\graphics\GraphicsContext3D.cpp">
</span><span class="cx"> <Filter>platform\graphics</Filter>
</span><span class="cx"> </ClCompile>
</span><span class="lines">@@ -14602,6 +14605,9 @@
</span><span class="cx"> <ClInclude Include="..\platform\graphics\ANGLEWebKitBridge.h">
</span><span class="cx"> <Filter>platform\graphics</Filter>
</span><span class="cx"> </ClInclude>
</span><ins>+ <ClInclude Include="..\platform\graphics\FormatConverter.h">
+ <Filter>platform\graphics</Filter>
+ </ClInclude>
</ins><span class="cx"> <ClInclude Include="..\platform\graphics\GraphicsContext3D.h">
</span><span class="cx"> <Filter>platform\graphics</Filter>
</span><span class="cx"> </ClInclude>
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -2293,6 +2293,8 @@
</span><span class="cx">                 7C5343FC17B74B63004232F0 /* JSMediaQueryListListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C5343FA17B74B63004232F0 /* JSMediaQueryListListener.cpp */; };
</span><span class="cx">                 7C5343FD17B74B63004232F0 /* JSMediaQueryListListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C5343FB17B74B63004232F0 /* JSMediaQueryListListener.h */; };
</span><span class="cx">                 7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; };
</span><ins>+                7CE6CBFB187F370700D46BF5 /* FormatConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE6CBFA187F370700D46BF5 /* FormatConverter.h */; };
+                7CE6CBFD187F394900D46BF5 /* FormatConverter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */; };
</ins><span class="cx">                 7D741BDA177226AA00859170 /* CSSValueKeywords.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 6565814809D13043000E61D7 /* CSSValueKeywords.h */; };
</span><span class="cx">                 7E12E90F15FA5D3A005E4126 /* CustomFilterMeshGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E12E90D15FA5D3A005E4126 /* CustomFilterMeshGenerator.h */; };
</span><span class="cx">                 7E12E91015FA5D3A005E4126 /* CustomFilterMeshGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E12E90E15FA5D3A005E4126 /* CustomFilterMeshGenerator.cpp */; };
</span><span class="lines">@@ -9266,6 +9268,8 @@
</span><span class="cx">                 7C6136F81710C35200FF4A57 /* InFilesParser.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = InFilesParser.pm; path = scripts/InFilesParser.pm; sourceTree = "<group>"; };
</span><span class="cx">                 7C6136F91710C35200FF4A57 /* StaticString.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = StaticString.pm; path = scripts/StaticString.pm; sourceTree = "<group>"; };
</span><span class="cx">                 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDNScriptWhiteList.txt; sourceTree = "<group>"; };
</span><ins>+                7CE6CBFA187F370700D46BF5 /* FormatConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatConverter.h; sourceTree = "<group>"; };
+                7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatConverter.cpp; sourceTree = "<group>"; };
</ins><span class="cx">                 7E12E90D15FA5D3A005E4126 /* CustomFilterMeshGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterMeshGenerator.h; path = filters/CustomFilterMeshGenerator.h; sourceTree = "<group>"; };
</span><span class="cx">                 7E12E90E15FA5D3A005E4126 /* CustomFilterMeshGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomFilterMeshGenerator.cpp; path = filters/CustomFilterMeshGenerator.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -19832,10 +19836,6 @@
</span><span class="cx">                 B2A015910AF6CD53006BCE0E /* graphics */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><del>-                                6E0E5699183BFFE600E0E8D5 /* FloatRoundedRect.cpp */,
-                                6E0E569A183BFFE600E0E8D5 /* FloatRoundedRect.h */,
-                                CD641EB11818F5ED00EE4C41 /* MediaSourcePrivate.h */,
-                                CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */,
</del><span class="cx">                                 076F0D0812B8192700C26AA4 /* avfoundation */,
</span><span class="cx">                                 499B3EC0128CCC1800E726C2 /* ca */,
</span><span class="cx">                                 B27535290B053814002CE64F /* cg */,
</span><span class="lines">@@ -19872,6 +19872,8 @@
</span><span class="cx">                                 0FD723800EC8BD9300CA5DD7 /* FloatQuad.h */,
</span><span class="cx">                                 B275353C0B053814002CE64F /* FloatRect.cpp */,
</span><span class="cx">                                 B275353D0B053814002CE64F /* FloatRect.h */,
</span><ins>+                                6E0E5699183BFFE600E0E8D5 /* FloatRoundedRect.cpp */,
+                                6E0E569A183BFFE600E0E8D5 /* FloatRoundedRect.h */,
</ins><span class="cx">                                 B275353E0B053814002CE64F /* FloatSize.cpp */,
</span><span class="cx">                                 B275353F0B053814002CE64F /* FloatSize.h */,
</span><span class="cx">                                 B2C3DA4F0D006CD600EF6F26 /* Font.cpp */,
</span><span class="lines">@@ -19899,10 +19901,10 @@
</span><span class="cx">                                 37202198106213C600F25C4B /* FontSmoothingMode.h */,
</span><span class="cx">                                 3784C34A0E11AA34007D8D48 /* FontTraitsMask.h */,
</span><span class="cx">                                 BCE4413512F7490B009B84B8 /* FontWidthVariant.h */,
</span><ins>+                                7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */,
+                                7CE6CBFA187F370700D46BF5 /* FormatConverter.h */,
</ins><span class="cx">                                 4FB390AC15EF61F3007AD51F /* GeneratedImage.cpp */,
</span><span class="cx">                                 BC23F0DA0DAFF4A4009FDC91 /* GeneratedImage.h */,
</span><del>-                                2D2FC0561460CD6F00263633 /* GradientImage.cpp */,
-                                2D2FC0571460CD6F00263633 /* GradientImage.h */,
</del><span class="cx">                                 086BBD0E136039C2008B15D8 /* Glyph.h */,
</span><span class="cx">                                 B2C3DA5B0D006CD600EF6F26 /* GlyphBuffer.h */,
</span><span class="cx">                                 C5D4AA78116BAFB60069CA93 /* GlyphMetricsMap.h */,
</span><span class="lines">@@ -19911,6 +19913,8 @@
</span><span class="cx">                                 B2C3DA5D0D006CD600EF6F26 /* GlyphPageTreeNode.h */,
</span><span class="cx">                                 BC53C6070DA56C570021EB5D /* Gradient.cpp */,
</span><span class="cx">                                 BC53C5F40DA56B920021EB5D /* Gradient.h */,
</span><ins>+                                2D2FC0561460CD6F00263633 /* GradientImage.cpp */,
+                                2D2FC0571460CD6F00263633 /* GradientImage.h */,
</ins><span class="cx">                                 B2A015920AF6CD53006BCE0E /* GraphicsContext.cpp */,
</span><span class="cx">                                 B2A015930AF6CD53006BCE0E /* GraphicsContext.h */,
</span><span class="cx">                                 6E21C6BF1126338500A7BE02 /* GraphicsContext3D.cpp */,
</span><span class="lines">@@ -19957,6 +19961,7 @@
</span><span class="cx">                                 E4B41E0C0CBF90BD00AF2ECE /* MediaPlayer.cpp */,
</span><span class="cx">                                 E4B41E0D0CBF90BD00AF2ECE /* MediaPlayer.h */,
</span><span class="cx">                                 079F5E4B0F3BEBEA005E0782 /* MediaPlayerPrivate.h */,
</span><ins>+                                CD641EB11818F5ED00EE4C41 /* MediaSourcePrivate.h */,
</ins><span class="cx">                                 6B3480920EEF50D400AC1B41 /* NativeImagePtr.h */,
</span><span class="cx">                                 B27535520B053814002CE64F /* Path.cpp */,
</span><span class="cx">                                 B27535530B053814002CE64F /* Path.h */,
</span><span class="lines">@@ -19977,8 +19982,7 @@
</span><span class="cx">                                 0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */,
</span><span class="cx">                                 B2C3DA530D006CD600EF6F26 /* SimpleFontData.cpp */,
</span><span class="cx">                                 B2C3DA540D006CD600EF6F26 /* SimpleFontData.h */,
</span><del>-                                CDC61DA0180867D8004B913F /* SourceBufferPrivate.h */,
-                                CD54A75E180F535000B076C9 /* MediaSourcePrivate.h */,
</del><ins>+                                CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */,
</ins><span class="cx">                                 CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */,
</span><span class="cx">                                 B23540F00D00782E002382FA /* StringTruncator.cpp */,
</span><span class="cx">                                 B23540F10D00782E002382FA /* StringTruncator.h */,
</span><span class="lines">@@ -20002,6 +20006,8 @@
</span><span class="cx">                                 501BAAA813950E2C00F7ACEB /* WindRule.h */,
</span><span class="cx">                                 379919941200DDF400EA041C /* WOFFFileFormat.cpp */,
</span><span class="cx">                                 379919951200DDF400EA041C /* WOFFFileFormat.h */,
</span><ins>+                                CDC61DA0180867D8004B913F /* SourceBufferPrivate.h */,
+                                CD54A75E180F535000B076C9 /* MediaSourcePrivate.h */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = graphics;
</span><span class="cx">                         sourceTree = "<group>";
</span><span class="lines">@@ -24944,6 +24950,7 @@
</span><span class="cx">                                 BC5C762B1497FE1400BC4775 /* PlatformEvent.h in Headers */,
</span><span class="cx">                                 BCAA487014A052530088FAC4 /* PlatformEventFactoryMac.h in Headers */,
</span><span class="cx">                                 A723F77B1484CA4C008C6DBE /* PlatformExportMacros.h in Headers */,
</span><ins>+                                7CE6CBFB187F370700D46BF5 /* FormatConverter.h in Headers */,
</ins><span class="cx">                                 935C476809AC4D4300A6AAB4 /* PlatformKeyboardEvent.h in Headers */,
</span><span class="cx">                                 0562F9611573F88F0031CA16 /* PlatformLayer.h in Headers */,
</span><span class="cx">                                 F544F78915CFB2A800AF33A8 /* PlatformLocale.h in Headers */,
</span><span class="lines">@@ -27110,6 +27117,7 @@
</span><span class="cx">                                 511EF2C817F0FD3500E4FA16 /* JSIDBOpenDBRequest.cpp in Sources */,
</span><span class="cx">                                 31313F651443B35F006E2A90 /* FilterEffectRenderer.cpp in Sources */,
</span><span class="cx">                                 49ECEB6D1499790D00CDD3A4 /* FilterOperation.cpp in Sources */,
</span><ins>+                                7CE6CBFD187F394900D46BF5 /* FormatConverter.cpp in Sources */,
</ins><span class="cx">                                 49ECEB6F1499790D00CDD3A4 /* FilterOperations.cpp in Sources */,
</span><span class="cx">                                 A8CFF04D0A154F09000A4234 /* FixedTableLayout.cpp in Sources */,
</span><span class="cx">                                 51D719B6181106E00016DC51 /* DOMWindowIndexedDatabase.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFormatConvertercppfromrev161780trunkSourceWebCoreplatformgraphicsGraphicsContext3Dcpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/platform/graphics/FormatConverter.cpp (from rev 161780, trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp) (0 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FormatConverter.cpp         (rev 0)
+++ trunk/Source/WebCore/platform/graphics/FormatConverter.cpp        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -0,0 +1,1276 @@
</span><ins>+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2010 Mozilla Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(3D_GRAPHICS)
+
+#include "FormatConverter.h"
+
+#if HAVE(ARM_NEON_INTRINSICS)
+#include "GraphicsContext3DNEON.h"
+#endif
+
+// Visual Studio crashes with a C1063 Fatal Error if everything is inlined.
+#if COMPILER(MSVC)
+#define ALWAYS_INLINE_EXCEPT_MSVC
+#else
+#define ALWAYS_INLINE_EXCEPT_MSVC ALWAYS_INLINE
+#endif
+
+namespace WebCore {
+
+
+// Following Float to Half-Float converion code is from the implementation of ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf,
+// "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010).
+// Specially, the basetable[512] and shifttable[512] are generated as follows:
+/*
+unsigned short basetable[512];
+unsigned char shifttable[512];
+
+void generatetables(){
+ unsigned int i;
+ int e;
+ for (i = 0; i < 256; ++i){
+ e = i - 127;
+ if (e < -24){ // Very small numbers map to zero
+ basetable[i | 0x000] = 0x0000;
+ basetable[i | 0x100] = 0x8000;
+ shifttable[i | 0x000] = 24;
+ shifttable[i | 0x100] = 24;
+ }
+ else if (e < -14) { // Small numbers map to denorms
+ basetable[i | 0x000] = (0x0400>>(-e-14));
+ basetable[i | 0x100] = (0x0400>>(-e-14)) | 0x8000;
+ shifttable[i | 0x000] = -e-1;
+ shifttable[i | 0x100] = -e-1;
+ }
+ else if (e <= 15){ // Normal numbers just lose precision
+ basetable[i | 0x000] = ((e+15)<<10);
+ basetable[i| 0x100] = ((e+15)<<10) | 0x8000;
+ shifttable[i|0x000] = 13;
+ shifttable[i|0x100] = 13;
+ }
+ else if (e<128){ // Large numbers map to Infinity
+ basetable[i|0x000] = 0x7C00;
+ basetable[i|0x100] = 0xFC00;
+ shifttable[i|0x000] = 24;
+ shifttable[i|0x100] = 24;
+ }
+ else { // Infinity and NaN's stay Infinity and NaN's
+ basetable[i|0x000] = 0x7C00;
+ basetable[i|0x100] = 0xFC00;
+ shifttable[i|0x000] = 13;
+ shifttable[i|0x100] = 13;
+ }
+ }
+}
+*/
+
+unsigned short baseTable[512] = {
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256,
+512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360,
+16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696, 30720, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
+32768, 32768, 32768, 32768, 32768, 32768, 32768, 32769, 32770, 32772, 32776, 32784, 32800, 32832, 32896, 33024,
+33280, 33792, 34816, 35840, 36864, 37888, 38912, 39936, 40960, 41984, 43008, 44032, 45056, 46080, 47104, 48128,
+49152, 50176, 51200, 52224, 53248, 54272, 55296, 56320, 57344, 58368, 59392, 60416, 61440, 62464, 63488, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
+64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512
+};
+
+unsigned char shiftTable[512] = {
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
+14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
+14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13
+};
+
+inline unsigned short convertFloatToHalfFloat(float f)
+{
+ unsigned temp = *(reinterpret_cast<unsigned *>(&f));
+ unsigned signexp = (temp >> 23) & 0x1ff;
+ return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]);
+}
+
+/* BEGIN CODE SHARED WITH MOZILLA FIREFOX */
+
+// The following packing and unpacking routines are expressed in terms of function templates and inline functions to achieve generality and speedup.
+// Explicit template specializations correspond to the cases that would occur.
+// Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/WebGLTexelConversions.h
+
+//----------------------------------------------------------------------
+// Pixel unpacking routines.
+template<int format, typename SourceType, typename DstType>
+ALWAYS_INLINE void unpack(const SourceType*, DstType*, unsigned)
+{
+ ASSERT_NOT_REACHED();
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[1];
+ destination[2] = source[2];
+ destination[3] = 0xFF;
+ source += 3;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[2];
+ destination[1] = source[1];
+ destination[2] = source[0];
+ destination[3] = 0xFF;
+ source += 3;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatARGB8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[1];
+ destination[1] = source[2];
+ destination[2] = source[3];
+ destination[3] = source[0];
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatABGR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[3];
+ destination[1] = source[2];
+ destination[2] = source[1];
+ destination[3] = source[0];
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGRA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ const uint32_t* source32 = reinterpret_cast_ptr<const uint32_t*>(source);
+ uint32_t* destination32 = reinterpret_cast_ptr<uint32_t*>(destination);
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ uint32_t bgra = source32[i];
+#if CPU(BIG_ENDIAN)
+ uint32_t brMask = 0xff00ff00;
+ uint32_t gaMask = 0x00ff00ff;
+#else
+ uint32_t brMask = 0x00ff00ff;
+ uint32_t gaMask = 0xff00ff00;
+#endif
+ uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMask);
+ destination32[i] = rgba;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGBA5551, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+#if HAVE(ARM_NEON_INTRINSICS)
+ SIMD::unpackOneRowOfRGBA5551ToRGBA8(source, destination, pixelsPerRow);
+#endif
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ uint16_t packedValue = source[0];
+ uint8_t r = packedValue >> 11;
+ uint8_t g = (packedValue >> 6) & 0x1F;
+ uint8_t b = (packedValue >> 1) & 0x1F;
+ destination[0] = (r << 3) | (r & 0x7);
+ destination[1] = (g << 3) | (g & 0x7);
+ destination[2] = (b << 3) | (b & 0x7);
+ destination[3] = (packedValue & 0x1) ? 0xFF : 0x0;
+ source += 1;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGBA4444, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+#if HAVE(ARM_NEON_INTRINSICS)
+ SIMD::unpackOneRowOfRGBA4444ToRGBA8(source, destination, pixelsPerRow);
+#endif
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ uint16_t packedValue = source[0];
+ uint8_t r = packedValue >> 12;
+ uint8_t g = (packedValue >> 8) & 0x0F;
+ uint8_t b = (packedValue >> 4) & 0x0F;
+ uint8_t a = packedValue & 0x0F;
+ destination[0] = r << 4 | r;
+ destination[1] = g << 4 | g;
+ destination[2] = b << 4 | b;
+ destination[3] = a << 4 | a;
+ source += 1;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB565, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+#if HAVE(ARM_NEON_INTRINSICS)
+ SIMD::unpackOneRowOfRGB565ToRGBA8(source, destination, pixelsPerRow);
+#endif
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ uint16_t packedValue = source[0];
+ uint8_t r = packedValue >> 11;
+ uint8_t g = (packedValue >> 5) & 0x3F;
+ uint8_t b = packedValue & 0x1F;
+ destination[0] = (r << 3) | (r & 0x7);
+ destination[1] = (g << 2) | (g & 0x3);
+ destination[2] = (b << 3) | (b & 0x7);
+ destination[3] = 0xFF;
+ source += 1;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[0];
+ destination[2] = source[0];
+ destination[3] = 0xFF;
+ source += 1;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[0];
+ destination[2] = source[0];
+ destination[3] = source[1];
+ source += 2;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatAR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[1];
+ destination[1] = source[1];
+ destination[2] = source[1];
+ destination[3] = source[0];
+ source += 2;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = 0x0;
+ destination[1] = 0x0;
+ destination[2] = 0x0;
+ destination[3] = source[0];
+ source += 1;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGBA8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
+{
+ const float scaleFactor = 1.0f / 255.0f;
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[2] * scaleFactor;
+ destination[3] = source[3] * scaleFactor;
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGRA8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
+{
+ const float scaleFactor = 1.0f / 255.0f;
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[2] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[0] * scaleFactor;
+ destination[3] = source[3] * scaleFactor;
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatABGR8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
+{
+ const float scaleFactor = 1.0f / 255.0f;
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[3] * scaleFactor;
+ destination[1] = source[2] * scaleFactor;
+ destination[2] = source[1] * scaleFactor;
+ destination[3] = source[0] * scaleFactor;
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatARGB8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
+{
+ const float scaleFactor = 1.0f / 255.0f;
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[1] * scaleFactor;
+ destination[1] = source[2] * scaleFactor;
+ destination[2] = source[3] * scaleFactor;
+ destination[3] = source[0] * scaleFactor;
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
+{
+ const float scaleFactor = 1.0f / 255.0f;
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[2] * scaleFactor;
+ destination[3] = 1;
+ source += 3;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGR8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
+{
+ const float scaleFactor = 1.0f / 255.0f;
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[2] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[0] * scaleFactor;
+ destination[3] = 1;
+ source += 3;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[1];
+ destination[2] = source[2];
+ destination[3] = 1;
+ source += 3;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatR32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[0];
+ destination[2] = source[0];
+ destination[3] = 1;
+ source += 1;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRA32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[0];
+ destination[2] = source[0];
+ destination[3] = source[1];
+ source += 2;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatA32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = 0;
+ destination[1] = 0;
+ destination[2] = 0;
+ destination[3] = source[0];
+ source += 1;
+ destination += 4;
+ }
+}
+
+//----------------------------------------------------------------------
+// Pixel packing routines.
+//
+
+template<int format, int alphaOp, typename SourceType, typename DstType>
+ALWAYS_INLINE void pack(const SourceType*, DstType*, unsigned)
+{
+ ASSERT_NOT_REACHED();
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[3];
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ destination[0] = sourceR;
+ source += 4;
+ destination += 1;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ destination[0] = sourceR;
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[3];
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ destination[0] = sourceR;
+ destination[1] = source[3];
+ source += 4;
+ destination += 2;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ destination[0] = sourceR;
+ destination[1] = source[3];
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[1];
+ destination[2] = source[2];
+ source += 4;
+ destination += 3;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ destination[0] = sourceR;
+ destination[1] = sourceG;
+ destination[2] = sourceB;
+ source += 4;
+ destination += 3;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ destination[0] = sourceR;
+ destination[1] = sourceG;
+ destination[2] = sourceB;
+ source += 4;
+ destination += 3;
+ }
+}
+
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ memcpy(destination, source, pixelsPerRow * 4);
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ destination[0] = sourceR;
+ destination[1] = sourceG;
+ destination[2] = sourceB;
+ destination[3] = source[3];
+ source += 4;
+ destination += 4;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ destination[0] = sourceR;
+ destination[1] = sourceG;
+ destination[2] = sourceB;
+ destination[3] = source[3];
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+#if HAVE(ARM_NEON_INTRINSICS)
+ SIMD::packOneRowOfRGBA8ToUnsignedShort4444(source, destination, pixelsPerRow);
+#endif
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ *destination = (((source[0] & 0xF0) << 8)
+ | ((source[1] & 0xF0) << 4)
+ | (source[2] & 0xF0)
+ | (source[3] >> 4));
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ *destination = (((sourceR & 0xF0) << 8)
+ | ((sourceG & 0xF0) << 4)
+ | (sourceB & 0xF0)
+ | (source[3] >> 4));
+ source += 4;
+ destination += 1;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ *destination = (((sourceR & 0xF0) << 8)
+ | ((sourceG & 0xF0) << 4)
+ | (sourceB & 0xF0)
+ | (source[3] >> 4));
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+#if HAVE(ARM_NEON_INTRINSICS)
+ SIMD::packOneRowOfRGBA8ToUnsignedShort5551(source, destination, pixelsPerRow);
+#endif
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ *destination = (((source[0] & 0xF8) << 8)
+ | ((source[1] & 0xF8) << 3)
+ | ((source[2] & 0xF8) >> 2)
+ | (source[3] >> 7));
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ *destination = (((sourceR & 0xF8) << 8)
+ | ((sourceG & 0xF8) << 3)
+ | ((sourceB & 0xF8) >> 2)
+ | (source[3] >> 7));
+ source += 4;
+ destination += 1;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ *destination = (((sourceR & 0xF8) << 8)
+ | ((sourceG & 0xF8) << 3)
+ | ((sourceB & 0xF8) >> 2)
+ | (source[3] >> 7));
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+#if HAVE(ARM_NEON_INTRINSICS)
+ SIMD::packOneRowOfRGBA8ToUnsignedShort565(source, destination, pixelsPerRow);
+#endif
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ *destination = (((source[0] & 0xF8) << 8)
+ | ((source[1] & 0xFC) << 3)
+ | ((source[2] & 0xF8) >> 3));
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] / 255.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ *destination = (((sourceR & 0xF8) << 8)
+ | ((sourceG & 0xFC) << 3)
+ | ((sourceB & 0xF8) >> 3));
+ source += 4;
+ destination += 1;
+ }
+}
+
+// FIXME: this routine is lossy and must be removed.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
+ uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
+ uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
+ uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
+ *destination = (((sourceR & 0xF8) << 8)
+ | ((sourceG & 0xFC) << 3)
+ | ((sourceB & 0xF8) >> 3));
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[1];
+ destination[2] = source[2];
+ source += 4;
+ destination += 3;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[2] * scaleFactor;
+ source += 4;
+ destination += 3;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[2] * scaleFactor;
+ source += 4;
+ destination += 3;
+ }
+}
+
+// Used only during RGBA8 or BGRA8 -> floating-point uploads.
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ memcpy(destination, source, pixelsPerRow * 4 * sizeof(float));
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[2] * scaleFactor;
+ destination[3] = source[3];
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[1] * scaleFactor;
+ destination[2] = source[2] * scaleFactor;
+ destination[3] = source[3];
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[3];
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = source[0] * scaleFactor;
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = source[0] * scaleFactor;
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = source[0];
+ destination[1] = source[3];
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[3];
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
+{
+ for (unsigned int i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = source[0] * scaleFactor;
+ destination[1] = source[3];
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = convertFloatToHalfFloat(source[0]);
+ destination[1] = convertFloatToHalfFloat(source[1]);
+ destination[2] = convertFloatToHalfFloat(source[2]);
+ destination[3] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
+ destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
+ destination[3] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
+ destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
+ destination[3] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 4;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = convertFloatToHalfFloat(source[0]);
+ destination[1] = convertFloatToHalfFloat(source[1]);
+ destination[2] = convertFloatToHalfFloat(source[2]);
+ source += 4;
+ destination += 3;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
+ destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
+ source += 4;
+ destination += 3;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
+ destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
+ source += 4;
+ destination += 3;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = convertFloatToHalfFloat(source[0]);
+ destination[1] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ destination[1] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ destination[1] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 2;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = convertFloatToHalfFloat(source[0]);
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3];
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
+ destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
+{
+ for (unsigned i = 0; i < pixelsPerRow; ++i) {
+ destination[0] = convertFloatToHalfFloat(source[3]);
+ source += 4;
+ destination += 1;
+ }
+}
+
+template<int Format>
+struct IsFloatFormat {
+ static const bool Value =
+ Format == GraphicsContext3D::DataFormatRGBA32F
+ || Format == GraphicsContext3D::DataFormatRGB32F
+ || Format == GraphicsContext3D::DataFormatRA32F
+ || Format == GraphicsContext3D::DataFormatR32F
+ || Format == GraphicsContext3D::DataFormatA32F;
+};
+
+template<int Format>
+struct IsHalfFloatFormat {
+ static const bool Value =
+ Format == GraphicsContext3D::DataFormatRGBA16F
+ || Format == GraphicsContext3D::DataFormatRGB16F
+ || Format == GraphicsContext3D::DataFormatRA16F
+ || Format == GraphicsContext3D::DataFormatR16F
+ || Format == GraphicsContext3D::DataFormatA16F;
+};
+
+template<int Format>
+struct Is16bppFormat {
+ static const bool Value =
+ Format == GraphicsContext3D::DataFormatRGBA5551
+ || Format == GraphicsContext3D::DataFormatRGBA4444
+ || Format == GraphicsContext3D::DataFormatRGB565;
+};
+
+template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool IsHalfFloat = IsHalfFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Value>
+struct DataTypeForFormat {
+ typedef uint8_t Type;
+};
+
+template<int Format>
+struct DataTypeForFormat<Format, true, false, false> {
+ typedef float Type;
+};
+
+template<int Format>
+struct DataTypeForFormat<Format, false, true, false> {
+ typedef uint16_t Type;
+};
+
+template<int Format>
+struct DataTypeForFormat<Format, false, false, true> {
+ typedef uint16_t Type;
+};
+
+template<int Format>
+struct IntermediateFormat {
+ static const int Value = (IsFloatFormat<Format>::Value || IsHalfFloatFormat<Format>::Value) ? GraphicsContext3D::DataFormatRGBA32F : GraphicsContext3D::DataFormatRGBA8;
+};
+
+
+/* END CODE SHARED WITH MOZILLA FIREFOX */
+
+void FormatConverter::convert(GraphicsContext3D::DataFormat srcFormat, GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp alphaOp)
+{
+#define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \
+ case SrcFormat: \
+ return convert<SrcFormat>(dstFormat, alphaOp);
+
+ switch (srcFormat) {
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatR8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatA8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatR32F)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatA32F)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRA8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRA32F)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatBGR8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB565)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB32F)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatARGB8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatABGR8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatAR8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatBGRA8)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA5551)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA4444)
+ FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA32F)
+ default:
+ ASSERT_NOT_REACHED();
+ }
+#undef FORMATCONVERTER_CASE_SRCFORMAT
+}
+
+template<GraphicsContext3D::DataFormat SrcFormat>
+ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp alphaOp)
+{
+#define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \
+ case DstFormat: \
+ return convert<SrcFormat, DstFormat>(alphaOp);
+
+ switch (dstFormat) {
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR16F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA16F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA16F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB16F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA16F)
+ FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F)
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+#undef FORMATCONVERTER_CASE_DSTFORMAT
+}
+
+template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat>
+ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp)
+{
+#define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \
+ case alphaOp: \
+ return convert<SrcFormat, DstFormat, alphaOp>();
+
+ switch (alphaOp) {
+ FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoNothing)
+ FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoPremultiply)
+ FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoUnmultiply)
+ default:
+ ASSERT_NOT_REACHED();
+ }
+#undef FORMATCONVERTER_CASE_ALPHAOP
+}
+
+template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat, GraphicsContext3D::AlphaOp alphaOp>
+ALWAYS_INLINE_EXCEPT_MSVC void FormatConverter::convert()
+{
+ // Many instantiations of this template function will never be entered, so we try
+ // to return immediately in these cases to avoid the compiler to generate useless code.
+ if (SrcFormat == DstFormat && alphaOp == GraphicsContext3D::AlphaDoNothing) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ if (!IsFloatFormat<DstFormat>::Value && IsFloatFormat<SrcFormat>::Value) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ // Only textures uploaded from DOM elements or ImageData can allow DstFormat != SrcFormat.
+ const bool srcFormatComesFromDOMElementOrImageData = GraphicsContext3D::srcFormatComesFromDOMElementOrImageData(SrcFormat);
+ if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ // Likewise, only textures uploaded from DOM elements or ImageData can possibly have to be unpremultiplied.
+ if (!srcFormatComesFromDOMElementOrImageData && alphaOp == GraphicsContext3D::AlphaDoUnmultiply) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ if ((!GraphicsContext3D::hasAlpha(SrcFormat) || !GraphicsContext3D::hasColor(SrcFormat) || !GraphicsContext3D::hasColor(DstFormat)) && alphaOp != GraphicsContext3D::AlphaDoNothing) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ typedef typename DataTypeForFormat<SrcFormat>::Type SrcType;
+ typedef typename DataTypeForFormat<DstFormat>::Type DstType;
+ const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value;
+ typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type IntermediateSrcType;
+ const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType);
+ const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType);
+ const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value && !IsHalfFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataFormatRGBA32F;
+ const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContext3D::AlphaDoNothing && m_dstStride > 0;
+ ASSERT(!trivialUnpack || !trivialPack);
+
+ const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart);
+ DstType* dstRowStart = static_cast<DstType*>(m_dstStart);
+ if (!trivialUnpack && trivialPack) {
+ for (size_t i = 0; i < m_height; ++i) {
+ unpack<SrcFormat>(srcRowStart, dstRowStart, m_width);
+ srcRowStart += srcStrideInElements;
+ dstRowStart += dstStrideInElements;
+ }
+ } else if (!trivialUnpack && !trivialPack) {
+ for (size_t i = 0; i < m_height; ++i) {
+ unpack<SrcFormat>(srcRowStart, reinterpret_cast_ptr<IntermediateSrcType*>(m_unpackedIntermediateSrcData.get()), m_width);
+ pack<DstFormat, alphaOp>(reinterpret_cast_ptr<IntermediateSrcType*>(m_unpackedIntermediateSrcData.get()), dstRowStart, m_width);
+ srcRowStart += srcStrideInElements;
+ dstRowStart += dstStrideInElements;
+ }
+ } else {
+ for (size_t i = 0; i < m_height; ++i) {
+ pack<DstFormat, alphaOp>(srcRowStart, dstRowStart, m_width);
+ srcRowStart += srcStrideInElements;
+ dstRowStart += dstStrideInElements;
+ }
+ }
+ m_success = true;
+ return;
+}
+
+} // namespace WebCore
+
+#endif // USE(3D_GRAPHICS)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFormatConverterh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/FormatConverter.h (0 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FormatConverter.h         (rev 0)
+++ trunk/Source/WebCore/platform/graphics/FormatConverter.h        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -0,0 +1,78 @@
</span><ins>+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2010 Mozilla Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(3D_GRAPHICS)
+
+#include "GraphicsContext3D.h"
+#include <wtf/StdLibExtras.h>
+
+namespace WebCore {
+
+class FormatConverter {
+public:
+ FormatConverter(unsigned width, unsigned height, const void* srcStart, void* dstStart, int srcStride, int dstStride)
+ : m_width(width)
+ , m_height(height)
+ , m_srcStart(srcStart)
+ , m_dstStart(dstStart)
+ , m_srcStride(srcStride)
+ , m_dstStride(dstStride)
+ , m_success(false)
+ {
+ const unsigned MaxNumberOfComponents = 4;
+ const unsigned MaxBytesPerComponent = 4;
+ m_unpackedIntermediateSrcData = std::make_unique<uint8_t[]>(m_width * MaxNumberOfComponents * MaxBytesPerComponent);
+
+ ASSERT(m_unpackedIntermediateSrcData.get());
+ }
+
+ void convert(GraphicsContext3D::DataFormat srcFormat, GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp);
+ bool success() const { return m_success; }
+
+private:
+ template<GraphicsContext3D::DataFormat SrcFormat>
+ ALWAYS_INLINE void convert(GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp);
+
+ template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat>
+ ALWAYS_INLINE void convert(GraphicsContext3D::AlphaOp);
+
+ template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat, GraphicsContext3D::AlphaOp alphaOp>
+ ALWAYS_INLINE void convert();
+
+ const unsigned m_width, m_height;
+ const void* const m_srcStart;
+ void* const m_dstStart;
+ const int m_srcStride, m_dstStride;
+ bool m_success;
+ std::unique_ptr<uint8_t[]> m_unpackedIntermediateSrcData;
+};
+
+} // namespace WebCore
+
+#endif // USE(3D_GRAPHICS)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContext3Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -32,24 +32,11 @@
</span><span class="cx"> #include "GraphicsContext3D.h"
</span><span class="cx">
</span><span class="cx"> #include "Extensions3D.h"
</span><ins>+#include "FormatConverter.h"
</ins><span class="cx"> #include "Image.h"
</span><span class="cx"> #include "ImageData.h"
</span><span class="cx"> #include "ImageObserver.h"
</span><span class="cx">
</span><del>-#if HAVE(ARM_NEON_INTRINSICS)
-#include "GraphicsContext3DNEON.h"
-#endif
-
-#include <runtime/ArrayBufferView.h>
-#include <wtf/StdLibExtras.h>
-
-// Visual Studio crashes with a C1063 Fatal Error if everything is inlined.
-#if COMPILER(MSVC)
-#define ALWAYS_INLINE_EXCEPT_MSVC
-#else
-#define ALWAYS_INLINE_EXCEPT_MSVC ALWAYS_INLINE
-#endif
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> namespace {
</span><span class="lines">@@ -159,10 +146,7 @@
</span><span class="cx"> return texImage2D(target, level, internalformat, width, height, border, format, type, zero.get());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool GraphicsContext3D::computeFormatAndTypeParameters(GC3Denum format,
- GC3Denum type,
- unsigned int* componentsPerPixel,
- unsigned int* bytesPerComponent)
</del><ins>+bool GraphicsContext3D::computeFormatAndTypeParameters(GC3Denum format, GC3Denum type, unsigned int* componentsPerPixel, unsigned int* bytesPerComponent)
</ins><span class="cx"> {
</span><span class="cx"> switch (format) {
</span><span class="cx"> case GraphicsContext3D::ALPHA:
</span><span class="lines">@@ -213,8 +197,7 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-GC3Denum GraphicsContext3D::computeImageSizeInBytes(GC3Denum format, GC3Denum type, GC3Dsizei width, GC3Dsizei height, GC3Dint alignment,
- unsigned int* imageSizeInBytes, unsigned int* paddingInBytes)
</del><ins>+GC3Denum GraphicsContext3D::computeImageSizeInBytes(GC3Denum format, GC3Denum type, GC3Dsizei width, GC3Dsizei height, GC3Dint alignment, unsigned int* imageSizeInBytes, unsigned int* paddingInBytes)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(imageSizeInBytes);
</span><span class="cx"> ASSERT(alignment == 1 || alignment == 2 || alignment == 4 || alignment == 8);
</span><span class="lines">@@ -258,18 +241,7 @@
</span><span class="cx"> m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfile);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool GraphicsContext3D::packImageData(
- Image* image,
- const void* pixels,
- GC3Denum format,
- GC3Denum type,
- bool flipY,
- AlphaOp alphaOp,
- DataFormat sourceFormat,
- unsigned width,
- unsigned height,
- unsigned sourceUnpackAlignment,
- Vector<uint8_t>& data)
</del><ins>+bool GraphicsContext3D::packImageData( Image* image, const void* pixels, GC3Denum format, GC3Denum type, bool flipY, AlphaOp alphaOp, DataFormat sourceFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, Vector<uint8_t>& data)
</ins><span class="cx"> {
</span><span class="cx"> if (!pixels)
</span><span class="cx"> return false;
</span><span class="lines">@@ -282,17 +254,12 @@
</span><span class="cx">
</span><span class="cx"> if (!packPixels(reinterpret_cast<const uint8_t*>(pixels), sourceFormat, width, height, sourceUnpackAlignment, format, type, alphaOp, data.data(), flipY))
</span><span class="cx"> return false;
</span><del>- if (ImageObserver *observer = image->imageObserver())
</del><ins>+ if (ImageObserver* observer = image->imageObserver())
</ins><span class="cx"> observer->didDraw(image);
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool GraphicsContext3D::extractImageData(ImageData* imageData,
- GC3Denum format,
- GC3Denum type,
- bool flipY,
- bool premultiplyAlpha,
- Vector<uint8_t>& data)
</del><ins>+bool GraphicsContext3D::extractImageData(ImageData* imageData, GC3Denum format, GC3Denum type, bool flipY, bool premultiplyAlpha, Vector<uint8_t>& data)
</ins><span class="cx"> {
</span><span class="cx"> if (!imageData)
</span><span class="cx"> return false;
</span><span class="lines">@@ -311,21 +278,14 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool GraphicsContext3D::extractTextureData(unsigned int width, unsigned int height,
- GC3Denum format, GC3Denum type,
- unsigned int unpackAlignment,
- bool flipY, bool premultiplyAlpha,
- const void* pixels,
- Vector<uint8_t>& data)
</del><ins>+bool GraphicsContext3D::extractTextureData(unsigned int width, unsigned int height, GC3Denum format, GC3Denum type, unsigned int unpackAlignment, bool flipY, bool premultiplyAlpha, const void* pixels, Vector<uint8_t>& data)
</ins><span class="cx"> {
</span><span class="cx"> // Assumes format, type, etc. have already been validated.
</span><span class="cx"> DataFormat sourceDataFormat = getDataFormat(format, type);
</span><span class="cx">
</span><span class="cx"> // Resize the output buffer.
</span><span class="cx"> unsigned int componentsPerPixel, bytesPerComponent;
</span><del>- if (!computeFormatAndTypeParameters(format, type,
- &componentsPerPixel,
- &bytesPerComponent))
</del><ins>+ if (!computeFormatAndTypeParameters(format, type, &componentsPerPixel, &bytesPerComponent))
</ins><span class="cx"> return false;
</span><span class="cx"> unsigned int bytesPerPixel = componentsPerPixel * bytesPerComponent;
</span><span class="cx"> data.resize(width * height * bytesPerPixel);
</span><span class="lines">@@ -336,1127 +296,6 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-namespace {
-
-// Following Float to Half-Float converion code is from the implementation of ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf,
-// "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010).
-// Specially, the basetable[512] and shifttable[512] are generated as follows:
-/*
-unsigned short basetable[512];
-unsigned char shifttable[512];
-
-void generatetables(){
- unsigned int i;
- int e;
- for (i = 0; i < 256; ++i){
- e = i - 127;
- if (e < -24){ // Very small numbers map to zero
- basetable[i | 0x000] = 0x0000;
- basetable[i | 0x100] = 0x8000;
- shifttable[i | 0x000] = 24;
- shifttable[i | 0x100] = 24;
- }
- else if (e < -14) { // Small numbers map to denorms
- basetable[i | 0x000] = (0x0400>>(-e-14));
- basetable[i | 0x100] = (0x0400>>(-e-14)) | 0x8000;
- shifttable[i | 0x000] = -e-1;
- shifttable[i | 0x100] = -e-1;
- }
- else if (e <= 15){ // Normal numbers just lose precision
- basetable[i | 0x000] = ((e+15)<<10);
- basetable[i| 0x100] = ((e+15)<<10) | 0x8000;
- shifttable[i|0x000] = 13;
- shifttable[i|0x100] = 13;
- }
- else if (e<128){ // Large numbers map to Infinity
- basetable[i|0x000] = 0x7C00;
- basetable[i|0x100] = 0xFC00;
- shifttable[i|0x000] = 24;
- shifttable[i|0x100] = 24;
- }
- else { // Infinity and NaN's stay Infinity and NaN's
- basetable[i|0x000] = 0x7C00;
- basetable[i|0x100] = 0xFC00;
- shifttable[i|0x000] = 13;
- shifttable[i|0x100] = 13;
- }
- }
-}
-*/
-
-unsigned short baseTable[512] = {
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256,
-512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360,
-16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696, 30720, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
-32768, 32768, 32768, 32768, 32768, 32768, 32768, 32769, 32770, 32772, 32776, 32784, 32800, 32832, 32896, 33024,
-33280, 33792, 34816, 35840, 36864, 37888, 38912, 39936, 40960, 41984, 43008, 44032, 45056, 46080, 47104, 48128,
-49152, 50176, 51200, 52224, 53248, 54272, 55296, 56320, 57344, 58368, 59392, 60416, 61440, 62464, 63488, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
-64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512
-};
-
-unsigned char shiftTable[512] = {
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
-14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
-14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
-24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13
-};
-
-unsigned short convertFloatToHalfFloat(float f)
-{
- unsigned temp = *(reinterpret_cast<unsigned *>(&f));
- unsigned signexp = (temp >> 23) & 0x1ff;
- return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]);
-}
-
-/* BEGIN CODE SHARED WITH MOZILLA FIREFOX */
-
-// The following packing and unpacking routines are expressed in terms of function templates and inline functions to achieve generality and speedup.
-// Explicit template specializations correspond to the cases that would occur.
-// Some code are merged back from Mozilla code in http://mxr.mozilla.org/mozilla-central/source/content/canvas/src/WebGLTexelConversions.h
-
-//----------------------------------------------------------------------
-// Pixel unpacking routines.
-template<int format, typename SourceType, typename DstType>
-ALWAYS_INLINE void unpack(const SourceType*, DstType*, unsigned)
-{
- ASSERT_NOT_REACHED();
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[1];
- destination[2] = source[2];
- destination[3] = 0xFF;
- source += 3;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[2];
- destination[1] = source[1];
- destination[2] = source[0];
- destination[3] = 0xFF;
- source += 3;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatARGB8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[1];
- destination[1] = source[2];
- destination[2] = source[3];
- destination[3] = source[0];
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatABGR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[3];
- destination[1] = source[2];
- destination[2] = source[1];
- destination[3] = source[0];
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGRA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- const uint32_t* source32 = reinterpret_cast_ptr<const uint32_t*>(source);
- uint32_t* destination32 = reinterpret_cast_ptr<uint32_t*>(destination);
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- uint32_t bgra = source32[i];
-#if CPU(BIG_ENDIAN)
- uint32_t brMask = 0xff00ff00;
- uint32_t gaMask = 0x00ff00ff;
-#else
- uint32_t brMask = 0x00ff00ff;
- uint32_t gaMask = 0xff00ff00;
-#endif
- uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMask);
- destination32[i] = rgba;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGBA5551, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
-#if HAVE(ARM_NEON_INTRINSICS)
- SIMD::unpackOneRowOfRGBA5551ToRGBA8(source, destination, pixelsPerRow);
-#endif
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- uint16_t packedValue = source[0];
- uint8_t r = packedValue >> 11;
- uint8_t g = (packedValue >> 6) & 0x1F;
- uint8_t b = (packedValue >> 1) & 0x1F;
- destination[0] = (r << 3) | (r & 0x7);
- destination[1] = (g << 3) | (g & 0x7);
- destination[2] = (b << 3) | (b & 0x7);
- destination[3] = (packedValue & 0x1) ? 0xFF : 0x0;
- source += 1;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGBA4444, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
-#if HAVE(ARM_NEON_INTRINSICS)
- SIMD::unpackOneRowOfRGBA4444ToRGBA8(source, destination, pixelsPerRow);
-#endif
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- uint16_t packedValue = source[0];
- uint8_t r = packedValue >> 12;
- uint8_t g = (packedValue >> 8) & 0x0F;
- uint8_t b = (packedValue >> 4) & 0x0F;
- uint8_t a = packedValue & 0x0F;
- destination[0] = r << 4 | r;
- destination[1] = g << 4 | g;
- destination[2] = b << 4 | b;
- destination[3] = a << 4 | a;
- source += 1;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB565, uint16_t, uint8_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
-#if HAVE(ARM_NEON_INTRINSICS)
- SIMD::unpackOneRowOfRGB565ToRGBA8(source, destination, pixelsPerRow);
-#endif
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- uint16_t packedValue = source[0];
- uint8_t r = packedValue >> 11;
- uint8_t g = (packedValue >> 5) & 0x3F;
- uint8_t b = packedValue & 0x1F;
- destination[0] = (r << 3) | (r & 0x7);
- destination[1] = (g << 2) | (g & 0x3);
- destination[2] = (b << 3) | (b & 0x7);
- destination[3] = 0xFF;
- source += 1;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[0];
- destination[2] = source[0];
- destination[3] = 0xFF;
- source += 1;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[0];
- destination[2] = source[0];
- destination[3] = source[1];
- source += 2;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatAR8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[1];
- destination[1] = source[1];
- destination[2] = source[1];
- destination[3] = source[0];
- source += 2;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatA8, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = 0x0;
- destination[1] = 0x0;
- destination[2] = 0x0;
- destination[3] = source[0];
- source += 1;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGBA8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
-{
- const float scaleFactor = 1.0f / 255.0f;
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[2] * scaleFactor;
- destination[3] = source[3] * scaleFactor;
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGRA8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
-{
- const float scaleFactor = 1.0f / 255.0f;
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[2] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[0] * scaleFactor;
- destination[3] = source[3] * scaleFactor;
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatABGR8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
-{
- const float scaleFactor = 1.0f / 255.0f;
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[3] * scaleFactor;
- destination[1] = source[2] * scaleFactor;
- destination[2] = source[1] * scaleFactor;
- destination[3] = source[0] * scaleFactor;
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatARGB8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
-{
- const float scaleFactor = 1.0f / 255.0f;
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[1] * scaleFactor;
- destination[1] = source[2] * scaleFactor;
- destination[2] = source[3] * scaleFactor;
- destination[3] = source[0] * scaleFactor;
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
-{
- const float scaleFactor = 1.0f / 255.0f;
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[2] * scaleFactor;
- destination[3] = 1;
- source += 3;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatBGR8, uint8_t, float>(const uint8_t* source, float* destination, unsigned pixelsPerRow)
-{
- const float scaleFactor = 1.0f / 255.0f;
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[2] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[0] * scaleFactor;
- destination[3] = 1;
- source += 3;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRGB32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[1];
- destination[2] = source[2];
- destination[3] = 1;
- source += 3;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatR32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[0];
- destination[2] = source[0];
- destination[3] = 1;
- source += 1;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatRA32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[0];
- destination[2] = source[0];
- destination[3] = source[1];
- source += 2;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void unpack<GraphicsContext3D::DataFormatA32F, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = 0;
- destination[1] = 0;
- destination[2] = 0;
- destination[3] = source[0];
- source += 1;
- destination += 4;
- }
-}
-
-//----------------------------------------------------------------------
-// Pixel packing routines.
-//
-
-template<int format, int alphaOp, typename SourceType, typename DstType>
-ALWAYS_INLINE void pack(const SourceType*, DstType*, unsigned)
-{
- ASSERT_NOT_REACHED();
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[3];
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- destination[0] = sourceR;
- source += 4;
- destination += 1;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- destination[0] = sourceR;
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[3];
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- destination[0] = sourceR;
- destination[1] = source[3];
- source += 4;
- destination += 2;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- destination[0] = sourceR;
- destination[1] = source[3];
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[1];
- destination[2] = source[2];
- source += 4;
- destination += 3;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- destination[0] = sourceR;
- destination[1] = sourceG;
- destination[2] = sourceB;
- source += 4;
- destination += 3;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- destination[0] = sourceR;
- destination[1] = sourceG;
- destination[2] = sourceB;
- source += 4;
- destination += 3;
- }
-}
-
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoNothing, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- memcpy(destination, source, pixelsPerRow * 4);
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- destination[0] = sourceR;
- destination[1] = sourceG;
- destination[2] = sourceB;
- destination[3] = source[3];
- source += 4;
- destination += 4;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA8, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- destination[0] = sourceR;
- destination[1] = sourceG;
- destination[2] = sourceB;
- destination[3] = source[3];
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
-#if HAVE(ARM_NEON_INTRINSICS)
- SIMD::packOneRowOfRGBA8ToUnsignedShort4444(source, destination, pixelsPerRow);
-#endif
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- *destination = (((source[0] & 0xF0) << 8)
- | ((source[1] & 0xF0) << 4)
- | (source[2] & 0xF0)
- | (source[3] >> 4));
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- *destination = (((sourceR & 0xF0) << 8)
- | ((sourceG & 0xF0) << 4)
- | (sourceB & 0xF0)
- | (source[3] >> 4));
- source += 4;
- destination += 1;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA4444, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- *destination = (((sourceR & 0xF0) << 8)
- | ((sourceG & 0xF0) << 4)
- | (sourceB & 0xF0)
- | (source[3] >> 4));
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
-#if HAVE(ARM_NEON_INTRINSICS)
- SIMD::packOneRowOfRGBA8ToUnsignedShort5551(source, destination, pixelsPerRow);
-#endif
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- *destination = (((source[0] & 0xF8) << 8)
- | ((source[1] & 0xF8) << 3)
- | ((source[2] & 0xF8) >> 2)
- | (source[3] >> 7));
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- *destination = (((sourceR & 0xF8) << 8)
- | ((sourceG & 0xF8) << 3)
- | ((sourceB & 0xF8) >> 2)
- | (source[3] >> 7));
- source += 4;
- destination += 1;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA5551, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- *destination = (((sourceR & 0xF8) << 8)
- | ((sourceG & 0xF8) << 3)
- | ((sourceB & 0xF8) >> 2)
- | (source[3] >> 7));
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
-#if HAVE(ARM_NEON_INTRINSICS)
- SIMD::packOneRowOfRGBA8ToUnsignedShort565(source, destination, pixelsPerRow);
-#endif
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- *destination = (((source[0] & 0xF8) << 8)
- | ((source[1] & 0xFC) << 3)
- | ((source[2] & 0xF8) >> 3));
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] / 255.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- *destination = (((sourceR & 0xF8) << 8)
- | ((sourceG & 0xFC) << 3)
- | ((sourceB & 0xF8) >> 3));
- source += 4;
- destination += 1;
- }
-}
-
-// FIXME: this routine is lossy and must be removed.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB565, GraphicsContext3D::AlphaDoUnmultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f;
- uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * scaleFactor);
- uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * scaleFactor);
- uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * scaleFactor);
- *destination = (((sourceR & 0xF8) << 8)
- | ((sourceG & 0xFC) << 3)
- | ((sourceB & 0xF8) >> 3));
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[1];
- destination[2] = source[2];
- source += 4;
- destination += 3;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[2] * scaleFactor;
- source += 4;
- destination += 3;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[2] * scaleFactor;
- source += 4;
- destination += 3;
- }
-}
-
-// Used only during RGBA8 or BGRA8 -> floating-point uploads.
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- memcpy(destination, source, pixelsPerRow * 4 * sizeof(float));
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[2] * scaleFactor;
- destination[3] = source[3];
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[1] * scaleFactor;
- destination[2] = source[2] * scaleFactor;
- destination[3] = source[3];
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[3];
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = source[0] * scaleFactor;
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = source[0] * scaleFactor;
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoNothing, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- destination[0] = source[0];
- destination[1] = source[3];
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoPremultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[3];
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA32F, GraphicsContext3D::AlphaDoUnmultiply, float, float>(const float* source, float* destination, unsigned pixelsPerRow)
-{
- for (unsigned int i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = source[0] * scaleFactor;
- destination[1] = source[3];
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = convertFloatToHalfFloat(source[0]);
- destination[1] = convertFloatToHalfFloat(source[1]);
- destination[2] = convertFloatToHalfFloat(source[2]);
- destination[3] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
- destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
- destination[3] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
- destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
- destination[3] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 4;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = convertFloatToHalfFloat(source[0]);
- destination[1] = convertFloatToHalfFloat(source[1]);
- destination[2] = convertFloatToHalfFloat(source[2]);
- source += 4;
- destination += 3;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
- destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
- source += 4;
- destination += 3;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
- destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
- source += 4;
- destination += 3;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = convertFloatToHalfFloat(source[0]);
- destination[1] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- destination[1] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- destination[1] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 2;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = convertFloatToHalfFloat(source[0]);
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3];
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
- destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
- source += 4;
- destination += 1;
- }
-}
-
-template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA16F, GraphicsContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
-{
- for (unsigned i = 0; i < pixelsPerRow; ++i) {
- destination[0] = convertFloatToHalfFloat(source[3]);
- source += 4;
- destination += 1;
- }
-}
-
-ALWAYS_INLINE bool HasAlpha(int format)
-{
- return format == GraphicsContext3D::DataFormatA8
- || format == GraphicsContext3D::DataFormatA16F
- || format == GraphicsContext3D::DataFormatA32F
- || format == GraphicsContext3D::DataFormatRA8
- || format == GraphicsContext3D::DataFormatAR8
- || format == GraphicsContext3D::DataFormatRA16F
- || format == GraphicsContext3D::DataFormatRA32F
- || format == GraphicsContext3D::DataFormatRGBA8
- || format == GraphicsContext3D::DataFormatBGRA8
- || format == GraphicsContext3D::DataFormatARGB8
- || format == GraphicsContext3D::DataFormatABGR8
- || format == GraphicsContext3D::DataFormatRGBA16F
- || format == GraphicsContext3D::DataFormatRGBA32F
- || format == GraphicsContext3D::DataFormatRGBA4444
- || format == GraphicsContext3D::DataFormatRGBA5551;
-}
-
-ALWAYS_INLINE bool HasColor(int format)
-{
- return format == GraphicsContext3D::DataFormatRGBA8
- || format == GraphicsContext3D::DataFormatRGBA16F
- || format == GraphicsContext3D::DataFormatRGBA32F
- || format == GraphicsContext3D::DataFormatRGB8
- || format == GraphicsContext3D::DataFormatRGB16F
- || format == GraphicsContext3D::DataFormatRGB32F
- || format == GraphicsContext3D::DataFormatBGR8
- || format == GraphicsContext3D::DataFormatBGRA8
- || format == GraphicsContext3D::DataFormatARGB8
- || format == GraphicsContext3D::DataFormatABGR8
- || format == GraphicsContext3D::DataFormatRGBA5551
- || format == GraphicsContext3D::DataFormatRGBA4444
- || format == GraphicsContext3D::DataFormatRGB565
- || format == GraphicsContext3D::DataFormatR8
- || format == GraphicsContext3D::DataFormatR16F
- || format == GraphicsContext3D::DataFormatR32F
- || format == GraphicsContext3D::DataFormatRA8
- || format == GraphicsContext3D::DataFormatRA16F
- || format == GraphicsContext3D::DataFormatRA32F
- || format == GraphicsContext3D::DataFormatAR8;
-}
-
-template<int Format>
-struct IsFloatFormat {
- static const bool Value =
- Format == GraphicsContext3D::DataFormatRGBA32F
- || Format == GraphicsContext3D::DataFormatRGB32F
- || Format == GraphicsContext3D::DataFormatRA32F
- || Format == GraphicsContext3D::DataFormatR32F
- || Format == GraphicsContext3D::DataFormatA32F;
-};
-
-template<int Format>
-struct IsHalfFloatFormat {
- static const bool Value =
- Format == GraphicsContext3D::DataFormatRGBA16F
- || Format == GraphicsContext3D::DataFormatRGB16F
- || Format == GraphicsContext3D::DataFormatRA16F
- || Format == GraphicsContext3D::DataFormatR16F
- || Format == GraphicsContext3D::DataFormatA16F;
-};
-
-template<int Format>
-struct Is16bppFormat {
- static const bool Value =
- Format == GraphicsContext3D::DataFormatRGBA5551
- || Format == GraphicsContext3D::DataFormatRGBA4444
- || Format == GraphicsContext3D::DataFormatRGB565;
-};
-
-template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool IsHalfFloat = IsHalfFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Value>
-struct DataTypeForFormat {
- typedef uint8_t Type;
-};
-
-template<int Format>
-struct DataTypeForFormat<Format, true, false, false> {
- typedef float Type;
-};
-
-template<int Format>
-struct DataTypeForFormat<Format, false, true, false> {
- typedef uint16_t Type;
-};
-
-template<int Format>
-struct DataTypeForFormat<Format, false, false, true> {
- typedef uint16_t Type;
-};
-
-template<int Format>
-struct IntermediateFormat {
- static const int Value = (IsFloatFormat<Format>::Value || IsHalfFloatFormat<Format>::Value) ? GraphicsContext3D::DataFormatRGBA32F : GraphicsContext3D::DataFormatRGBA8;
-};
-
</del><span class="cx"> ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContext3D::DataFormat format)
</span><span class="cx"> {
</span><span class="cx"> switch (format) {
</span><span class="lines">@@ -1496,191 +335,6 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-/* END CODE SHARED WITH MOZILLA FIREFOX */
-
-class FormatConverter {
-public:
- FormatConverter(unsigned width, unsigned height,
- const void* srcStart, void* dstStart, int srcStride, int dstStride)
- : m_width(width), m_height(height), m_srcStart(srcStart), m_dstStart(dstStart), m_srcStride(srcStride), m_dstStride(dstStride), m_success(false)
- {
- const unsigned MaxNumberOfComponents = 4;
- const unsigned MaxBytesPerComponent = 4;
- m_unpackedIntermediateSrcData = std::make_unique<uint8_t[]>(m_width * MaxNumberOfComponents * MaxBytesPerComponent);
-
- ASSERT(m_unpackedIntermediateSrcData.get());
- }
-
- void convert(GraphicsContext3D::DataFormat srcFormat, GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp);
- bool Success() const { return m_success; }
-
-private:
- template<GraphicsContext3D::DataFormat SrcFormat>
- ALWAYS_INLINE void convert(GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp);
-
- template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat>
- ALWAYS_INLINE void convert(GraphicsContext3D::AlphaOp);
-
- template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat, GraphicsContext3D::AlphaOp alphaOp>
- ALWAYS_INLINE void convert();
-
- const unsigned m_width, m_height;
- const void* const m_srcStart;
- void* const m_dstStart;
- const int m_srcStride, m_dstStride;
- bool m_success;
- std::unique_ptr<uint8_t[]> m_unpackedIntermediateSrcData;
-};
-
-void FormatConverter::convert(GraphicsContext3D::DataFormat srcFormat, GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp alphaOp)
-{
-#define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \
- case SrcFormat: \
- return convert<SrcFormat>(dstFormat, alphaOp);
-
- switch (srcFormat) {
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatR8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatA8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatR32F)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatA32F)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRA8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRA32F)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatBGR8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB565)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGB32F)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatARGB8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatABGR8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatAR8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatBGRA8)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA5551)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA4444)
- FORMATCONVERTER_CASE_SRCFORMAT(GraphicsContext3D::DataFormatRGBA32F)
- default:
- ASSERT_NOT_REACHED();
- }
-#undef FORMATCONVERTER_CASE_SRCFORMAT
-}
-
-template<GraphicsContext3D::DataFormat SrcFormat>
-ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::DataFormat dstFormat, GraphicsContext3D::AlphaOp alphaOp)
-{
-#define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \
- case DstFormat: \
- return convert<SrcFormat, DstFormat>(alphaOp);
-
- switch (dstFormat) {
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR16F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA16F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA16F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB16F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA16F)
- FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F)
- default:
- ASSERT_NOT_REACHED();
- }
-
-#undef FORMATCONVERTER_CASE_DSTFORMAT
-}
-
-template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat>
-ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp)
-{
-#define FORMATCONVERTER_CASE_ALPHAOP(alphaOp) \
- case alphaOp: \
- return convert<SrcFormat, DstFormat, alphaOp>();
-
- switch (alphaOp) {
- FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoNothing)
- FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoPremultiply)
- FORMATCONVERTER_CASE_ALPHAOP(GraphicsContext3D::AlphaDoUnmultiply)
- default:
- ASSERT_NOT_REACHED();
- }
-#undef FORMATCONVERTER_CASE_ALPHAOP
-}
-
-template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat, GraphicsContext3D::AlphaOp alphaOp>
-ALWAYS_INLINE_EXCEPT_MSVC void FormatConverter::convert()
-{
- // Many instantiations of this template function will never be entered, so we try
- // to return immediately in these cases to avoid the compiler to generate useless code.
- if (SrcFormat == DstFormat && alphaOp == GraphicsContext3D::AlphaDoNothing) {
- ASSERT_NOT_REACHED();
- return;
- }
- if (!IsFloatFormat<DstFormat>::Value && IsFloatFormat<SrcFormat>::Value) {
- ASSERT_NOT_REACHED();
- return;
- }
-
- // Only textures uploaded from DOM elements or ImageData can allow DstFormat != SrcFormat.
- const bool srcFormatComesFromDOMElementOrImageData = GraphicsContext3D::srcFormatComesFromDOMElementOrImageData(SrcFormat);
- if (!srcFormatComesFromDOMElementOrImageData && SrcFormat != DstFormat) {
- ASSERT_NOT_REACHED();
- return;
- }
- // Likewise, only textures uploaded from DOM elements or ImageData can possibly have to be unpremultiplied.
- if (!srcFormatComesFromDOMElementOrImageData && alphaOp == GraphicsContext3D::AlphaDoUnmultiply) {
- ASSERT_NOT_REACHED();
- return;
- }
- if ((!HasAlpha(SrcFormat) || !HasColor(SrcFormat) || !HasColor(DstFormat)) && alphaOp != GraphicsContext3D::AlphaDoNothing) {
- ASSERT_NOT_REACHED();
- return;
- }
-
- typedef typename DataTypeForFormat<SrcFormat>::Type SrcType;
- typedef typename DataTypeForFormat<DstFormat>::Type DstType;
- const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value;
- typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type IntermediateSrcType;
- const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType);
- const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType);
- const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value && !IsHalfFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataFormatRGBA32F;
- const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContext3D::AlphaDoNothing && m_dstStride > 0;
- ASSERT(!trivialUnpack || !trivialPack);
-
- const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart);
- DstType* dstRowStart = static_cast<DstType*>(m_dstStart);
- if (!trivialUnpack && trivialPack) {
- for (size_t i = 0; i < m_height; ++i) {
- unpack<SrcFormat>(srcRowStart, dstRowStart, m_width);
- srcRowStart += srcStrideInElements;
- dstRowStart += dstStrideInElements;
- }
- } else if (!trivialUnpack && !trivialPack) {
- for (size_t i = 0; i < m_height; ++i) {
- unpack<SrcFormat>(srcRowStart, reinterpret_cast_ptr<IntermediateSrcType*>(m_unpackedIntermediateSrcData.get()), m_width);
- pack<DstFormat, alphaOp>(reinterpret_cast_ptr<IntermediateSrcType*>(m_unpackedIntermediateSrcData.get()), dstRowStart, m_width);
- srcRowStart += srcStrideInElements;
- dstRowStart += dstStrideInElements;
- }
- } else {
- for (size_t i = 0; i < m_height; ++i) {
- pack<DstFormat, alphaOp>(srcRowStart, dstRowStart, m_width);
- srcRowStart += srcStrideInElements;
- dstRowStart += dstStrideInElements;
- }
- }
- m_success = true;
- return;
-}
-
-} // anonymous namespace
-
</del><span class="cx"> bool GraphicsContext3D::packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp alphaOp, void* destinationData, bool flipY)
</span><span class="cx"> {
</span><span class="cx"> int validSrc = width * TexelBytesForFormat(sourceDataFormat);
</span><span class="lines">@@ -1693,7 +347,7 @@
</span><span class="cx"> destinationData = static_cast<uint8_t*>(destinationData) + dstStride*(height - 1);
</span><span class="cx"> dstStride = -dstStride;
</span><span class="cx"> }
</span><del>- if (!HasAlpha(sourceDataFormat) || !HasColor(sourceDataFormat) || !HasColor(dstDataFormat))
</del><ins>+ if (!hasAlpha(sourceDataFormat) || !hasColor(sourceDataFormat) || !hasColor(dstDataFormat))
</ins><span class="cx"> alphaOp = AlphaDoNothing;
</span><span class="cx">
</span><span class="cx"> if (sourceDataFormat == dstDataFormat && alphaOp == AlphaDoNothing) {
</span><span class="lines">@@ -1711,7 +365,7 @@
</span><span class="cx">
</span><span class="cx"> FormatConverter converter(width, height, sourceData, destinationData, srcStride, dstStride);
</span><span class="cx"> converter.convert(sourceDataFormat, dstDataFormat, alphaOp);
</span><del>- if (!converter.Success())
</del><ins>+ if (!converter.success())
</ins><span class="cx"> return false;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContext3Dh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (161782 => 161783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h        2014-01-11 21:58:23 UTC (rev 161782)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h        2014-01-11 22:56:40 UTC (rev 161783)
</span><span class="lines">@@ -606,6 +606,49 @@
</span><span class="cx"> DataFormatNumFormats
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+ ALWAYS_INLINE static bool hasAlpha(DataFormat format)
+ {
+ return format == GraphicsContext3D::DataFormatA8
+ || format == GraphicsContext3D::DataFormatA16F
+ || format == GraphicsContext3D::DataFormatA32F
+ || format == GraphicsContext3D::DataFormatRA8
+ || format == GraphicsContext3D::DataFormatAR8
+ || format == GraphicsContext3D::DataFormatRA16F
+ || format == GraphicsContext3D::DataFormatRA32F
+ || format == GraphicsContext3D::DataFormatRGBA8
+ || format == GraphicsContext3D::DataFormatBGRA8
+ || format == GraphicsContext3D::DataFormatARGB8
+ || format == GraphicsContext3D::DataFormatABGR8
+ || format == GraphicsContext3D::DataFormatRGBA16F
+ || format == GraphicsContext3D::DataFormatRGBA32F
+ || format == GraphicsContext3D::DataFormatRGBA4444
+ || format == GraphicsContext3D::DataFormatRGBA5551;
+ }
+
+ ALWAYS_INLINE static bool hasColor(DataFormat format)
+ {
+ return format == GraphicsContext3D::DataFormatRGBA8
+ || format == GraphicsContext3D::DataFormatRGBA16F
+ || format == GraphicsContext3D::DataFormatRGBA32F
+ || format == GraphicsContext3D::DataFormatRGB8
+ || format == GraphicsContext3D::DataFormatRGB16F
+ || format == GraphicsContext3D::DataFormatRGB32F
+ || format == GraphicsContext3D::DataFormatBGR8
+ || format == GraphicsContext3D::DataFormatBGRA8
+ || format == GraphicsContext3D::DataFormatARGB8
+ || format == GraphicsContext3D::DataFormatABGR8
+ || format == GraphicsContext3D::DataFormatRGBA5551
+ || format == GraphicsContext3D::DataFormatRGBA4444
+ || format == GraphicsContext3D::DataFormatRGB565
+ || format == GraphicsContext3D::DataFormatR8
+ || format == GraphicsContext3D::DataFormatR16F
+ || format == GraphicsContext3D::DataFormatR32F
+ || format == GraphicsContext3D::DataFormatRA8
+ || format == GraphicsContext3D::DataFormatRA16F
+ || format == GraphicsContext3D::DataFormatRA32F
+ || format == GraphicsContext3D::DataFormatAR8;
+ }
+
</ins><span class="cx"> // Check if the format is one of the formats from the ImageData or DOM elements.
</span><span class="cx"> // The formats from ImageData is always RGBA8.
</span><span class="cx"> // The formats from DOM elements vary with Graphics ports. It can only be RGBA8 or BGRA8 for non-CG port while a little more for CG port.
</span></span></pre>
</div>
</div>
</body>
</html>