Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: Source/core/platform/graphics/GraphicsContext3D.cpp

Issue 13842017: Add OES_texture_half_float extension support in WebGL. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: pass value instead of pointer Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext3D.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. 4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 break; 81 break;
82 case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4: 82 case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4:
83 dstFormat = GraphicsContext3D::DataFormatRGBA4444; 83 dstFormat = GraphicsContext3D::DataFormatRGBA4444;
84 break; 84 break;
85 case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1: 85 case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1:
86 dstFormat = GraphicsContext3D::DataFormatRGBA5551; 86 dstFormat = GraphicsContext3D::DataFormatRGBA5551;
87 break; 87 break;
88 case GraphicsContext3D::UNSIGNED_SHORT_5_6_5: 88 case GraphicsContext3D::UNSIGNED_SHORT_5_6_5:
89 dstFormat = GraphicsContext3D::DataFormatRGB565; 89 dstFormat = GraphicsContext3D::DataFormatRGB565;
90 break; 90 break;
91 case GraphicsContext3D::HALF_FLOAT_OES: // OES_texture_half_float
92 switch (destinationFormat) {
93 case GraphicsContext3D::RGB:
94 dstFormat = GraphicsContext3D::DataFormatRGB16F;
95 break;
96 case GraphicsContext3D::RGBA:
97 dstFormat = GraphicsContext3D::DataFormatRGBA16F;
98 break;
99 case GraphicsContext3D::ALPHA:
100 dstFormat = GraphicsContext3D::DataFormatA16F;
101 break;
102 case GraphicsContext3D::LUMINANCE:
103 dstFormat = GraphicsContext3D::DataFormatR16F;
104 break;
105 case GraphicsContext3D::LUMINANCE_ALPHA:
106 dstFormat = GraphicsContext3D::DataFormatRA16F;
107 break;
108 default:
109 ASSERT_NOT_REACHED();
110 }
111 break;
91 case GraphicsContext3D::FLOAT: // OES_texture_float 112 case GraphicsContext3D::FLOAT: // OES_texture_float
92 switch (destinationFormat) { 113 switch (destinationFormat) {
93 case GraphicsContext3D::RGB: 114 case GraphicsContext3D::RGB:
94 dstFormat = GraphicsContext3D::DataFormatRGB32F; 115 dstFormat = GraphicsContext3D::DataFormatRGB32F;
95 break; 116 break;
96 case GraphicsContext3D::RGBA: 117 case GraphicsContext3D::RGBA:
97 dstFormat = GraphicsContext3D::DataFormatRGBA32F; 118 dstFormat = GraphicsContext3D::DataFormatRGBA32F;
98 break; 119 break;
99 case GraphicsContext3D::ALPHA: 120 case GraphicsContext3D::ALPHA:
100 dstFormat = GraphicsContext3D::DataFormatA32F; 121 dstFormat = GraphicsContext3D::DataFormatA32F;
(...skipping 21 matching lines...) Expand all
122 *frameBufferId = drawingBuffer->framebuffer(); 143 *frameBufferId = drawingBuffer->framebuffer();
123 *width = drawingBuffer->size().width(); 144 *width = drawingBuffer->size().width();
124 *height = drawingBuffer->size().height(); 145 *height = drawingBuffer->size().height();
125 } else { 146 } else {
126 *frameBufferId = 0; 147 *frameBufferId = 0;
127 *width = graphicsContext3D->width(); 148 *width = graphicsContext3D->width();
128 *height = graphicsContext3D->height(); 149 *height = graphicsContext3D->height();
129 } 150 }
130 } 151 }
131 152
153 // Following Float to Half-Float converion code is from the implementation of ft p://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf,
154 // "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010).
155 // Specially, the basetable[512] and shifttable[512] are generated as follows:
156 /*
157 unsigned short basetable[512];
158 unsigned char shifttable[512];
159
160 void generatetables(){
161 unsigned int i;
162 int e;
163 for (i = 0; i < 256; ++i){
164 e = i - 127;
165 if (e < -24){ // Very small numbers map to zero
166 basetable[i | 0x000] = 0x0000;
167 basetable[i | 0x100] = 0x8000;
168 shifttable[i | 0x000] = 24;
169 shifttable[i | 0x100] = 24;
170 }
171 else if (e < -14) { // Small numbers map to denorms
172 basetable[i | 0x000] = (0x0400>>(-e-14));
173 basetable[i | 0x100] = (0x0400>>(-e-14)) | 0x8000;
174 shifttable[i | 0x000] = -e-1;
175 shifttable[i | 0x100] = -e-1;
176 }
177 else if (e <= 15){ // Normal numbers just lose precision
178 basetable[i | 0x000] = ((e+15)<<10);
179 basetable[i| 0x100] = ((e+15)<<10) | 0x8000;
180 shifttable[i|0x000] = 13;
181 shifttable[i|0x100] = 13;
182 }
183 else if (e<128){ // Large numbers map to Infinity
184 basetable[i|0x000] = 0x7C00;
185 basetable[i|0x100] = 0xFC00;
186 shifttable[i|0x000] = 24;
187 shifttable[i|0x100] = 24;
188 }
189 else { // Infinity and NaN's stay Infinity and NaN's
190 basetable[i|0x000] = 0x7C00;
191 basetable[i|0x100] = 0xFC00;
192 shifttable[i|0x000] = 13;
193 shifttable[i|0x100] = 13;
194 }
195 }
196 }
197 */
198
199 unsigned short baseTable[512] = {
200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256,
207 512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360,
208 16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696, 30720, 31744,
209 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
210 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
211 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
212 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
213 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
214 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
215 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
216 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
217 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
218 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
219 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
220 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
221 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
222 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32769, 32770, 32772, 32776, 32784, 32800, 32832, 32896, 33024,
223 33280, 33792, 34816, 35840, 36864, 37888, 38912, 39936, 40960, 41984, 43008, 44032, 45056, 46080, 47104, 48128,
224 49152, 50176, 51200, 52224, 53248, 54272, 55296, 56320, 57344, 58368, 59392, 60416, 61440, 62464, 63488, 64512,
225 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
226 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
227 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
228 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
229 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
230 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512,
231 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512
232 };
233
234 unsigned char shiftTable[512] = {
235 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
236 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
237 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
238 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
239 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
240 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
241 24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
242 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
243 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24,
244 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
245 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
246 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
247 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
248 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
249 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
250 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13,
251 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
252 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
253 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
254 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
255 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
256 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
257 24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
258 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
259 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 24,
260 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
261 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
262 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
263 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
264 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
265 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
266 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13
267 };
268
269 unsigned short convertFloatToHalfFloat(float f)
270 {
271 unsigned temp = *(reinterpret_cast<unsigned *>(&f));
272 unsigned signexp = (temp >> 23) & 0x1ff;
273 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]);
274 }
275
132 } // anonymous namespace 276 } // anonymous namespace
133 277
134 // Macros to assist in delegating from GraphicsContext3D to 278 // Macros to assist in delegating from GraphicsContext3D to
135 // WebGraphicsContext3D. 279 // WebGraphicsContext3D.
136 280
137 #define DELEGATE_TO_WEBCONTEXT(name) \ 281 #define DELEGATE_TO_WEBCONTEXT(name) \
138 void GraphicsContext3D::name() \ 282 void GraphicsContext3D::name() \
139 { \ 283 { \
140 m_private->webContext()->name(); \ 284 m_private->webContext()->name(); \
141 } 285 }
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 { 1699 {
1556 for (unsigned int i = 0; i < pixelsPerRow; ++i) { 1700 for (unsigned int i = 0; i < pixelsPerRow; ++i) {
1557 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 1701 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1558 destination[0] = source[0] * scaleFactor; 1702 destination[0] = source[0] * scaleFactor;
1559 destination[1] = source[3]; 1703 destination[1] = source[3];
1560 source += 4; 1704 source += 4;
1561 destination += 2; 1705 destination += 2;
1562 } 1706 }
1563 } 1707 }
1564 1708
1709 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, Graphic sContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* dest ination, unsigned pixelsPerRow)
1710 {
1711 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1712 destination[0] = convertFloatToHalfFloat(source[0]);
1713 destination[1] = convertFloatToHalfFloat(source[1]);
1714 destination[2] = convertFloatToHalfFloat(source[2]);
1715 destination[3] = convertFloatToHalfFloat(source[3]);
1716 source += 4;
1717 destination += 4;
1718 }
1719 }
1720
1721 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, Graphic sContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
1722 {
1723 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1724 float scaleFactor = source[3];
1725 const float tempArray[3] = {
1726 source[0] * scaleFactor,
1727 source[1] * scaleFactor,
1728 source[2] * scaleFactor
1729 };
Ken Russell (switch to Gerrit) 2013/04/24 23:15:47 The temporary arrays here and throughout are no lo
1730
1731 destination[0] = convertFloatToHalfFloat(tempArray[0]);
1732 destination[1] = convertFloatToHalfFloat(tempArray[1]);
1733 destination[2] = convertFloatToHalfFloat(tempArray[2]);
1734 destination[3] = convertFloatToHalfFloat(source[3]);
1735 source += 4;
1736 destination += 4;
1737 }
1738 }
1739
1740 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, Graphic sContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* d estination, unsigned pixelsPerRow)
1741 {
1742 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1743 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1744 const float tempArray[3] = {
1745 source[0] * scaleFactor,
1746 source[1] * scaleFactor,
1747 source[2] * scaleFactor
1748 };
1749
1750 destination[0] = convertFloatToHalfFloat(tempArray[0]);
1751 destination[1] = convertFloatToHalfFloat(tempArray[1]);
1752 destination[2] = convertFloatToHalfFloat(tempArray[2]);
1753 destination[3] = convertFloatToHalfFloat(source[3]);
1754 source += 4;
1755 destination += 4;
1756 }
1757 }
1758
1759 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, Graphics Context3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* desti nation, unsigned pixelsPerRow)
1760 {
1761 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1762 destination[0] = convertFloatToHalfFloat(source[0]);
1763 destination[1] = convertFloatToHalfFloat(source[1]);
1764 destination[2] = convertFloatToHalfFloat(source[2]);
1765 source += 4;
1766 destination += 3;
1767 }
1768 }
1769
1770 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, Graphics Context3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* d estination, unsigned pixelsPerRow)
1771 {
1772 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1773 float scaleFactor = source[3];
1774 const float tempArray[3] = {
1775 source[0] * scaleFactor,
1776 source[1] * scaleFactor,
1777 source[2] * scaleFactor
1778 };
1779
1780 destination[0] = convertFloatToHalfFloat(tempArray[0]);
1781 destination[1] = convertFloatToHalfFloat(tempArray[1]);
1782 destination[2] = convertFloatToHalfFloat(tempArray[2]);
1783 source += 4;
1784 destination += 3;
1785 }
1786 }
1787
1788 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, Graphics Context3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* de stination, unsigned pixelsPerRow)
1789 {
1790 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1791 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1792 const float tempArray[3] = {
1793 source[0] * scaleFactor,
1794 source[1] * scaleFactor,
1795 source[2] * scaleFactor
1796 };
1797
1798 destination[0] = convertFloatToHalfFloat(tempArray[0]);
1799 destination[1] = convertFloatToHalfFloat(tempArray[1]);
1800 destination[2] = convertFloatToHalfFloat(tempArray[2]);
1801 source += 4;
1802 destination += 3;
1803 }
1804 }
1805
1806 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsC ontext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destin ation, unsigned pixelsPerRow)
1807 {
1808 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1809 destination[0] = convertFloatToHalfFloat(source[0]);
1810 destination[1] = convertFloatToHalfFloat(source[3]);
1811 source += 4;
1812 destination += 2;
1813 }
1814 }
1815
1816 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsC ontext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* de stination, unsigned pixelsPerRow)
1817 {
1818 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1819 float scaleFactor = source[3];
1820 const float temp = source[0] * scaleFactor;
1821 destination[0] = convertFloatToHalfFloat(temp);
1822 destination[1] = convertFloatToHalfFloat(source[3]);
1823 source += 4;
1824 destination += 2;
1825 }
1826 }
1827
1828 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsC ontext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* des tination, unsigned pixelsPerRow)
1829 {
1830 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1831 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1832 const float temp = source[0] * scaleFactor;
1833 destination[0] = convertFloatToHalfFloat(temp);
1834 destination[1] = convertFloatToHalfFloat(source[3]);
1835 source += 4;
1836 destination += 2;
1837 }
1838 }
1839
1840 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsCo ntext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destina tion, unsigned pixelsPerRow)
1841 {
1842 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1843 destination[0] = convertFloatToHalfFloat(source[0]);
1844 source += 4;
1845 destination += 1;
1846 }
1847 }
1848
1849 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsCo ntext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* des tination, unsigned pixelsPerRow)
1850 {
1851 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1852 float scaleFactor = source[3];
1853 const float temp = source[0] * scaleFactor;
1854 destination[0] = convertFloatToHalfFloat(temp);
1855 source += 4;
1856 destination += 1;
1857 }
1858 }
1859
1860 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsCo ntext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* dest ination, unsigned pixelsPerRow)
1861 {
1862 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1863 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1864 const float temp = source[0] * scaleFactor;
1865 destination[0] = convertFloatToHalfFloat(temp);
1866 source += 4;
1867 destination += 1;
1868 }
1869 }
1870
1871 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA16F, GraphicsCo ntext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destina tion, unsigned pixelsPerRow)
1872 {
1873 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1874 destination[0] = convertFloatToHalfFloat(source[3]);
1875 source += 4;
1876 destination += 1;
1877 }
1878 }
1879
1565 ALWAYS_INLINE bool HasAlpha(int format) 1880 ALWAYS_INLINE bool HasAlpha(int format)
1566 { 1881 {
1567 return format == GraphicsContext3D::DataFormatA8 1882 return format == GraphicsContext3D::DataFormatA8
1883 || format == GraphicsContext3D::DataFormatA16F
1568 || format == GraphicsContext3D::DataFormatA32F 1884 || format == GraphicsContext3D::DataFormatA32F
1569 || format == GraphicsContext3D::DataFormatRA8 1885 || format == GraphicsContext3D::DataFormatRA8
1570 || format == GraphicsContext3D::DataFormatAR8 1886 || format == GraphicsContext3D::DataFormatAR8
1887 || format == GraphicsContext3D::DataFormatRA16F
1571 || format == GraphicsContext3D::DataFormatRA32F 1888 || format == GraphicsContext3D::DataFormatRA32F
1572 || format == GraphicsContext3D::DataFormatRGBA8 1889 || format == GraphicsContext3D::DataFormatRGBA8
1573 || format == GraphicsContext3D::DataFormatBGRA8 1890 || format == GraphicsContext3D::DataFormatBGRA8
1574 || format == GraphicsContext3D::DataFormatARGB8 1891 || format == GraphicsContext3D::DataFormatARGB8
1575 || format == GraphicsContext3D::DataFormatABGR8 1892 || format == GraphicsContext3D::DataFormatABGR8
1893 || format == GraphicsContext3D::DataFormatRGBA16F
1576 || format == GraphicsContext3D::DataFormatRGBA32F 1894 || format == GraphicsContext3D::DataFormatRGBA32F
1577 || format == GraphicsContext3D::DataFormatRGBA4444 1895 || format == GraphicsContext3D::DataFormatRGBA4444
1578 || format == GraphicsContext3D::DataFormatRGBA5551; 1896 || format == GraphicsContext3D::DataFormatRGBA5551;
1579 } 1897 }
1580 1898
1581 ALWAYS_INLINE bool HasColor(int format) 1899 ALWAYS_INLINE bool HasColor(int format)
1582 { 1900 {
1583 return format == GraphicsContext3D::DataFormatRGBA8 1901 return format == GraphicsContext3D::DataFormatRGBA8
1902 || format == GraphicsContext3D::DataFormatRGBA16F
1584 || format == GraphicsContext3D::DataFormatRGBA32F 1903 || format == GraphicsContext3D::DataFormatRGBA32F
1585 || format == GraphicsContext3D::DataFormatRGB8 1904 || format == GraphicsContext3D::DataFormatRGB8
1905 || format == GraphicsContext3D::DataFormatRGB16F
1586 || format == GraphicsContext3D::DataFormatRGB32F 1906 || format == GraphicsContext3D::DataFormatRGB32F
1587 || format == GraphicsContext3D::DataFormatBGR8 1907 || format == GraphicsContext3D::DataFormatBGR8
1588 || format == GraphicsContext3D::DataFormatBGRA8 1908 || format == GraphicsContext3D::DataFormatBGRA8
1589 || format == GraphicsContext3D::DataFormatARGB8 1909 || format == GraphicsContext3D::DataFormatARGB8
1590 || format == GraphicsContext3D::DataFormatABGR8 1910 || format == GraphicsContext3D::DataFormatABGR8
1591 || format == GraphicsContext3D::DataFormatRGBA5551 1911 || format == GraphicsContext3D::DataFormatRGBA5551
1592 || format == GraphicsContext3D::DataFormatRGBA4444 1912 || format == GraphicsContext3D::DataFormatRGBA4444
1593 || format == GraphicsContext3D::DataFormatRGB565 1913 || format == GraphicsContext3D::DataFormatRGB565
1594 || format == GraphicsContext3D::DataFormatR8 1914 || format == GraphicsContext3D::DataFormatR8
1915 || format == GraphicsContext3D::DataFormatR16F
1595 || format == GraphicsContext3D::DataFormatR32F 1916 || format == GraphicsContext3D::DataFormatR32F
1596 || format == GraphicsContext3D::DataFormatRA8 1917 || format == GraphicsContext3D::DataFormatRA8
1918 || format == GraphicsContext3D::DataFormatRA16F
1597 || format == GraphicsContext3D::DataFormatRA32F 1919 || format == GraphicsContext3D::DataFormatRA32F
1598 || format == GraphicsContext3D::DataFormatAR8; 1920 || format == GraphicsContext3D::DataFormatAR8;
1599 } 1921 }
1600 1922
1601 template<int Format> 1923 template<int Format>
1602 struct IsFloatFormat { 1924 struct IsFloatFormat {
1603 static const bool Value = 1925 static const bool Value =
1604 Format == GraphicsContext3D::DataFormatRGBA32F 1926 Format == GraphicsContext3D::DataFormatRGBA32F
1605 || Format == GraphicsContext3D::DataFormatRGB32F 1927 || Format == GraphicsContext3D::DataFormatRGB32F
1606 || Format == GraphicsContext3D::DataFormatRA32F 1928 || Format == GraphicsContext3D::DataFormatRA32F
1607 || Format == GraphicsContext3D::DataFormatR32F 1929 || Format == GraphicsContext3D::DataFormatR32F
1608 || Format == GraphicsContext3D::DataFormatA32F; 1930 || Format == GraphicsContext3D::DataFormatA32F;
1609 }; 1931 };
1610 1932
1611 template<int Format> 1933 template<int Format>
1934 struct IsHalfFloatFormat {
1935 static const bool Value =
1936 Format == GraphicsContext3D::DataFormatRGBA16F
1937 || Format == GraphicsContext3D::DataFormatRGB16F
1938 || Format == GraphicsContext3D::DataFormatRA16F
1939 || Format == GraphicsContext3D::DataFormatR16F
1940 || Format == GraphicsContext3D::DataFormatA16F;
1941 };
1942
1943 template<int Format>
1612 struct Is16bppFormat { 1944 struct Is16bppFormat {
1613 static const bool Value = 1945 static const bool Value =
1614 Format == GraphicsContext3D::DataFormatRGBA5551 1946 Format == GraphicsContext3D::DataFormatRGBA5551
1615 || Format == GraphicsContext3D::DataFormatRGBA4444 1947 || Format == GraphicsContext3D::DataFormatRGBA4444
1616 || Format == GraphicsContext3D::DataFormatRGB565; 1948 || Format == GraphicsContext3D::DataFormatRGB565;
1617 }; 1949 };
1618 1950
1619 template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Value> 1951 template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool IsHalfFlo at = IsHalfFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Val ue>
1620 struct DataTypeForFormat { 1952 struct DataTypeForFormat {
1621 typedef uint8_t Type; 1953 typedef uint8_t Type;
1622 }; 1954 };
1623 1955
1624 template<int Format> 1956 template<int Format>
1625 struct DataTypeForFormat<Format, true, false> { 1957 struct DataTypeForFormat<Format, true, false, false> {
1626 typedef float Type; 1958 typedef float Type;
1627 }; 1959 };
1628 1960
1629 template<int Format> 1961 template<int Format>
1630 struct DataTypeForFormat<Format, false, true> { 1962 struct DataTypeForFormat<Format, false, true, false> {
1963 typedef uint16_t Type;
1964 };
1965
1966 template<int Format>
1967 struct DataTypeForFormat<Format, false, false, true> {
1631 typedef uint16_t Type; 1968 typedef uint16_t Type;
1632 }; 1969 };
1633 1970
1634 template<int Format> 1971 template<int Format>
1635 struct IntermediateFormat { 1972 struct IntermediateFormat {
1636 static const int Value = IsFloatFormat<Format>::Value ? GraphicsContext3D::D ataFormatRGBA32F : GraphicsContext3D::DataFormatRGBA8; 1973 static const int Value = (IsFloatFormat<Format>::Value || IsHalfFloatFormat< Format>::Value) ? GraphicsContext3D::DataFormatRGBA32F : GraphicsContext3D::Data FormatRGBA8;
1637 }; 1974 };
1638 1975
1639 ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContext3D::DataFormat format) 1976 ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContext3D::DataFormat format)
1640 { 1977 {
1641 switch (format) { 1978 switch (format) {
1642 case GraphicsContext3D::DataFormatR8: 1979 case GraphicsContext3D::DataFormatR8:
1643 case GraphicsContext3D::DataFormatA8: 1980 case GraphicsContext3D::DataFormatA8:
1644 return 1; 1981 return 1;
1645 case GraphicsContext3D::DataFormatRA8: 1982 case GraphicsContext3D::DataFormatRA8:
1646 case GraphicsContext3D::DataFormatAR8: 1983 case GraphicsContext3D::DataFormatAR8:
1647 case GraphicsContext3D::DataFormatRGBA5551: 1984 case GraphicsContext3D::DataFormatRGBA5551:
1648 case GraphicsContext3D::DataFormatRGBA4444: 1985 case GraphicsContext3D::DataFormatRGBA4444:
1649 case GraphicsContext3D::DataFormatRGB565: 1986 case GraphicsContext3D::DataFormatRGB565:
1987 case GraphicsContext3D::DataFormatA16F:
1988 case GraphicsContext3D::DataFormatR16F:
1650 return 2; 1989 return 2;
1651 case GraphicsContext3D::DataFormatRGB8: 1990 case GraphicsContext3D::DataFormatRGB8:
1652 case GraphicsContext3D::DataFormatBGR8: 1991 case GraphicsContext3D::DataFormatBGR8:
1653 return 3; 1992 return 3;
1654 case GraphicsContext3D::DataFormatRGBA8: 1993 case GraphicsContext3D::DataFormatRGBA8:
1655 case GraphicsContext3D::DataFormatARGB8: 1994 case GraphicsContext3D::DataFormatARGB8:
1656 case GraphicsContext3D::DataFormatABGR8: 1995 case GraphicsContext3D::DataFormatABGR8:
1657 case GraphicsContext3D::DataFormatBGRA8: 1996 case GraphicsContext3D::DataFormatBGRA8:
1658 case GraphicsContext3D::DataFormatR32F: 1997 case GraphicsContext3D::DataFormatR32F:
1659 case GraphicsContext3D::DataFormatA32F: 1998 case GraphicsContext3D::DataFormatA32F:
1999 case GraphicsContext3D::DataFormatRA16F:
1660 return 4; 2000 return 4;
2001 case GraphicsContext3D::DataFormatRGB16F:
2002 return 6;
1661 case GraphicsContext3D::DataFormatRA32F: 2003 case GraphicsContext3D::DataFormatRA32F:
2004 case GraphicsContext3D::DataFormatRGBA16F:
1662 return 8; 2005 return 8;
1663 case GraphicsContext3D::DataFormatRGB32F: 2006 case GraphicsContext3D::DataFormatRGB32F:
1664 return 12; 2007 return 12;
1665 case GraphicsContext3D::DataFormatRGBA32F: 2008 case GraphicsContext3D::DataFormatRGBA32F:
1666 return 16; 2009 return 16;
1667 default: 2010 default:
1668 return 0; 2011 return 0;
1669 } 2012 }
1670 } 2013 }
1671 2014
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 2080
1738 template<GraphicsContext3D::DataFormat SrcFormat> 2081 template<GraphicsContext3D::DataFormat SrcFormat>
1739 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::DataFormat dstFor mat, GraphicsContext3D::AlphaOp alphaOp) 2082 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::DataFormat dstFor mat, GraphicsContext3D::AlphaOp alphaOp)
1740 { 2083 {
1741 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \ 2084 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \
1742 case DstFormat: \ 2085 case DstFormat: \
1743 return convert<SrcFormat, DstFormat>(alphaOp); 2086 return convert<SrcFormat, DstFormat>(alphaOp);
1744 2087
1745 switch (dstFormat) { 2088 switch (dstFormat) {
1746 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8) 2089 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8)
2090 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR16F)
2091 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F)
1747 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8) 2092 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8)
1748 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F) 2093 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA16F)
1749 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F) 2094 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F)
1750 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8) 2095 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8)
2096 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA16F)
1751 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F) 2097 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F)
1752 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8) 2098 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8)
1753 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565) 2099 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565)
2100 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB16F)
1754 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F) 2101 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F)
1755 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8) 2102 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8)
1756 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551 ) 2103 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551 )
1757 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444 ) 2104 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444 )
2105 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA16F)
1758 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F) 2106 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F)
1759 default: 2107 default:
1760 ASSERT_NOT_REACHED(); 2108 ASSERT_NOT_REACHED();
1761 } 2109 }
1762 2110
1763 #undef FORMATCONVERTER_CASE_DSTFORMAT 2111 #undef FORMATCONVERTER_CASE_DSTFORMAT
1764 } 2112 }
1765 2113
1766 template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat> 2114 template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat>
1767 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp) 2115 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 ASSERT_NOT_REACHED(); 2157 ASSERT_NOT_REACHED();
1810 return; 2158 return;
1811 } 2159 }
1812 2160
1813 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; 2161 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType;
1814 typedef typename DataTypeForFormat<DstFormat>::Type DstType; 2162 typedef typename DataTypeForFormat<DstFormat>::Type DstType;
1815 const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value; 2163 const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value;
1816 typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type Intermediate SrcType; 2164 typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type Intermediate SrcType;
1817 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType); 2165 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType);
1818 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType); 2166 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType);
1819 const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataForm atRGBA32F; 2167 const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value && !IsHalfFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataFormatRGBA32F;
1820 const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContex t3D::AlphaDoNothing && m_dstStride > 0; 2168 const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContex t3D::AlphaDoNothing && m_dstStride > 0;
1821 ASSERT(!trivialUnpack || !trivialPack); 2169 ASSERT(!trivialUnpack || !trivialPack);
1822 2170
1823 const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart); 2171 const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart);
1824 DstType* dstRowStart = static_cast<DstType*>(m_dstStart); 2172 DstType* dstRowStart = static_cast<DstType*>(m_dstStart);
1825 if (!trivialUnpack && trivialPack) { 2173 if (!trivialUnpack && trivialPack) {
1826 for (size_t i = 0; i < m_height; ++i) { 2174 for (size_t i = 0; i < m_height; ++i) {
1827 unpack<SrcFormat>(srcRowStart, dstRowStart, m_width); 2175 unpack<SrcFormat>(srcRowStart, dstRowStart, m_width);
1828 srcRowStart += srcStrideInElements; 2176 srcRowStart += srcStrideInElements;
1829 dstRowStart += dstStrideInElements; 2177 dstRowStart += dstStrideInElements;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 case GraphicsContext3D::DEPTH_STENCIL: 2310 case GraphicsContext3D::DEPTH_STENCIL:
1963 return ChannelDepth | ChannelStencil; 2311 return ChannelDepth | ChannelStencil;
1964 default: 2312 default:
1965 return 0; 2313 return 0;
1966 } 2314 }
1967 } 2315 }
1968 2316
1969 } // namespace WebCore 2317 } // namespace WebCore
1970 2318
1971 #endif // USE(3D_GRAPHICS) 2319 #endif // USE(3D_GRAPHICS)
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext3D.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698