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

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: move test cases to directory LayoutTest/webgl/ 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 break; 82 break;
83 case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4: 83 case GraphicsContext3D::UNSIGNED_SHORT_4_4_4_4:
84 dstFormat = GraphicsContext3D::DataFormatRGBA4444; 84 dstFormat = GraphicsContext3D::DataFormatRGBA4444;
85 break; 85 break;
86 case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1: 86 case GraphicsContext3D::UNSIGNED_SHORT_5_5_5_1:
87 dstFormat = GraphicsContext3D::DataFormatRGBA5551; 87 dstFormat = GraphicsContext3D::DataFormatRGBA5551;
88 break; 88 break;
89 case GraphicsContext3D::UNSIGNED_SHORT_5_6_5: 89 case GraphicsContext3D::UNSIGNED_SHORT_5_6_5:
90 dstFormat = GraphicsContext3D::DataFormatRGB565; 90 dstFormat = GraphicsContext3D::DataFormatRGB565;
91 break; 91 break;
92 case GraphicsContext3D::HALF_FLOAT_OES: // OES_texture_half_float
93 switch (destinationFormat) {
94 case GraphicsContext3D::RGB:
95 dstFormat = GraphicsContext3D::DataFormatRGB16F;
96 break;
97 case GraphicsContext3D::RGBA:
98 dstFormat = GraphicsContext3D::DataFormatRGBA16F;
99 break;
100 case GraphicsContext3D::ALPHA:
101 dstFormat = GraphicsContext3D::DataFormatA16F;
102 break;
103 case GraphicsContext3D::LUMINANCE:
104 dstFormat = GraphicsContext3D::DataFormatR16F;
105 break;
106 case GraphicsContext3D::LUMINANCE_ALPHA:
107 dstFormat = GraphicsContext3D::DataFormatRA16F;
108 break;
109 default:
110 ASSERT_NOT_REACHED();
111 }
112 break;
92 case GraphicsContext3D::FLOAT: // OES_texture_float 113 case GraphicsContext3D::FLOAT: // OES_texture_float
93 switch (destinationFormat) { 114 switch (destinationFormat) {
94 case GraphicsContext3D::RGB: 115 case GraphicsContext3D::RGB:
95 dstFormat = GraphicsContext3D::DataFormatRGB32F; 116 dstFormat = GraphicsContext3D::DataFormatRGB32F;
96 break; 117 break;
97 case GraphicsContext3D::RGBA: 118 case GraphicsContext3D::RGBA:
98 dstFormat = GraphicsContext3D::DataFormatRGBA32F; 119 dstFormat = GraphicsContext3D::DataFormatRGBA32F;
99 break; 120 break;
100 case GraphicsContext3D::ALPHA: 121 case GraphicsContext3D::ALPHA:
101 dstFormat = GraphicsContext3D::DataFormatA32F; 122 dstFormat = GraphicsContext3D::DataFormatA32F;
(...skipping 21 matching lines...) Expand all
123 *frameBufferId = drawingBuffer->framebuffer(); 144 *frameBufferId = drawingBuffer->framebuffer();
124 *width = drawingBuffer->size().width(); 145 *width = drawingBuffer->size().width();
125 *height = drawingBuffer->size().height(); 146 *height = drawingBuffer->size().height();
126 } else { 147 } else {
127 *frameBufferId = 0; 148 *frameBufferId = 0;
128 *width = graphicsContext3D->width(); 149 *width = graphicsContext3D->width();
129 *height = graphicsContext3D->height(); 150 *height = graphicsContext3D->height();
130 } 151 }
131 } 152 }
132 153
154 // Following Float to Half-Float converion code is from the implementation of ft p://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf,
155 // "Fast Half Float Conversions" by Jeroen van der Zijp, November 2008 (Revised September 2010).
156 // Specially, the basetable[512] and shifttable[512] are generated as follows:
157 /*
158 unsigned short basetable[512];
159 unsigned char shifttable[512];
160
161 void generatetables(){
162 unsigned int i;
163 int e;
164 for (i = 0; i < 256; ++i){
165 e = i - 127;
166 if (e < -24){ // Very small numbers map to zero
167 basetable[i | 0x000] = 0x0000;
168 basetable[i | 0x100] = 0x8000;
169 shifttable[i | 0x000] = 24;
170 shifttable[i | 0x100] = 24;
171 }
172 else if (e < -14) { // Small numbers map to denorms
173 basetable[i | 0x000] = (0x0400>>(-e-14));
174 basetable[i | 0x100] = (0x0400>>(-e-14)) | 0x8000;
175 shifttable[i | 0x000] = -e-1;
176 shifttable[i | 0x100] = -e-1;
177 }
178 else if (e <= 15){ // Normal numbers just lose precision
179 basetable[i | 0x000] = ((e+15)<<10);
180 basetable[i| 0x100] = ((e+15)<<10) | 0x8000;
181 shifttable[i|0x000] = 13;
182 shifttable[i|0x100] = 13;
183 }
184 else if (e<128){ // Large numbers map to Infinity
185 basetable[i|0x000] = 0x7C00;
186 basetable[i|0x100] = 0xFC00;
187 shifttable[i|0x000] = 24;
188 shifttable[i|0x100] = 24;
189 }
190 else { // Infinity and NaN's stay Infinity and NaN's
191 basetable[i|0x000] = 0x7C00;
192 basetable[i|0x100] = 0xFC00;
193 shifttable[i|0x000] = 13;
194 shifttable[i|0x100] = 13;
195 }
196 }
197 }
198 */
199
200 unsigned short baseTable[512] = {
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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256,
208 512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360,
209 16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696, 30720, 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 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744, 31744,
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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
223 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32769, 32770, 32772, 32776, 32784, 32800, 32832, 32896, 33024,
224 33280, 33792, 34816, 35840, 36864, 37888, 38912, 39936, 40960, 41984, 43008, 44032, 45056, 46080, 47104, 48128,
225 49152, 50176, 51200, 52224, 53248, 54272, 55296, 56320, 57344, 58368, 59392, 60416, 61440, 62464, 63488, 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 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512
233 };
234
235 unsigned char shiftTable[512] = {
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, 24, 24, 24, 24, 24, 24, 24, 24, 24,
242 24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
243 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
244 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 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, 24,
251 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13,
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, 24, 24, 24, 24, 24, 24, 24, 24, 24,
258 24, 24, 24, 24, 24, 24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
259 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
260 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 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, 24,
267 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 13
268 };
269
270 unsigned short convertFloatToHalfFloat(float f)
271 {
272 unsigned temp = *(reinterpret_cast<unsigned *>(&f));
273 unsigned signexp = (temp >> 23) & 0x1ff;
274 return baseTable[signexp] + ((temp & 0x007fffff) >> shiftTable[signexp]);
275 }
276
133 } // anonymous namespace 277 } // anonymous namespace
134 278
135 // Macros to assist in delegating from GraphicsContext3D to 279 // Macros to assist in delegating from GraphicsContext3D to
136 // WebGraphicsContext3D. 280 // WebGraphicsContext3D.
137 281
138 #define DELEGATE_TO_WEBCONTEXT(name) \ 282 #define DELEGATE_TO_WEBCONTEXT(name) \
139 void GraphicsContext3D::name() \ 283 void GraphicsContext3D::name() \
140 { \ 284 { \
141 m_private->webContext()->name(); \ 285 m_private->webContext()->name(); \
142 } 286 }
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 { 1758 {
1615 for (unsigned int i = 0; i < pixelsPerRow; ++i) { 1759 for (unsigned int i = 0; i < pixelsPerRow; ++i) {
1616 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f; 1760 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1617 destination[0] = source[0] * scaleFactor; 1761 destination[0] = source[0] * scaleFactor;
1618 destination[1] = source[3]; 1762 destination[1] = source[3];
1619 source += 4; 1763 source += 4;
1620 destination += 2; 1764 destination += 2;
1621 } 1765 }
1622 } 1766 }
1623 1767
1768 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, Graphic sContext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* dest ination, unsigned pixelsPerRow)
1769 {
1770 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1771 destination[0] = convertFloatToHalfFloat(source[0]);
1772 destination[1] = convertFloatToHalfFloat(source[1]);
1773 destination[2] = convertFloatToHalfFloat(source[2]);
1774 destination[3] = convertFloatToHalfFloat(source[3]);
1775 source += 4;
1776 destination += 4;
1777 }
1778 }
1779
1780 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, Graphic sContext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* destination, unsigned pixelsPerRow)
1781 {
1782 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1783 float scaleFactor = source[3];
1784 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1785 destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
1786 destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
1787 destination[3] = convertFloatToHalfFloat(source[3]);
1788 source += 4;
1789 destination += 4;
1790 }
1791 }
1792
1793 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGBA16F, Graphic sContext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* d estination, unsigned pixelsPerRow)
1794 {
1795 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1796 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1797 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1798 destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
1799 destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
1800 destination[3] = convertFloatToHalfFloat(source[3]);
1801 source += 4;
1802 destination += 4;
1803 }
1804 }
1805
1806 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, Graphics Context3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* desti nation, unsigned pixelsPerRow)
1807 {
1808 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1809 destination[0] = convertFloatToHalfFloat(source[0]);
1810 destination[1] = convertFloatToHalfFloat(source[1]);
1811 destination[2] = convertFloatToHalfFloat(source[2]);
1812 source += 4;
1813 destination += 3;
1814 }
1815 }
1816
1817 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, Graphics Context3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* d estination, unsigned pixelsPerRow)
1818 {
1819 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1820 float scaleFactor = source[3];
1821 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1822 destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
1823 destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
1824 source += 4;
1825 destination += 3;
1826 }
1827 }
1828
1829 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRGB16F, Graphics Context3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* de stination, unsigned pixelsPerRow)
1830 {
1831 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1832 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1833 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1834 destination[1] = convertFloatToHalfFloat(source[1] * scaleFactor);
1835 destination[2] = convertFloatToHalfFloat(source[2] * scaleFactor);
1836 source += 4;
1837 destination += 3;
1838 }
1839 }
1840
1841 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsC ontext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destin ation, unsigned pixelsPerRow)
1842 {
1843 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1844 destination[0] = convertFloatToHalfFloat(source[0]);
1845 destination[1] = convertFloatToHalfFloat(source[3]);
1846 source += 4;
1847 destination += 2;
1848 }
1849 }
1850
1851 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsC ontext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* de stination, unsigned pixelsPerRow)
1852 {
1853 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1854 float scaleFactor = source[3];
1855 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1856 destination[1] = convertFloatToHalfFloat(source[3]);
1857 source += 4;
1858 destination += 2;
1859 }
1860 }
1861
1862 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatRA16F, GraphicsC ontext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* des tination, unsigned pixelsPerRow)
1863 {
1864 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1865 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1866 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1867 destination[1] = convertFloatToHalfFloat(source[3]);
1868 source += 4;
1869 destination += 2;
1870 }
1871 }
1872
1873 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsCo ntext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destina tion, unsigned pixelsPerRow)
1874 {
1875 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1876 destination[0] = convertFloatToHalfFloat(source[0]);
1877 source += 4;
1878 destination += 1;
1879 }
1880 }
1881
1882 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsCo ntext3D::AlphaDoPremultiply, float, uint16_t>(const float* source, uint16_t* des tination, unsigned pixelsPerRow)
1883 {
1884 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1885 float scaleFactor = source[3];
1886 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1887 source += 4;
1888 destination += 1;
1889 }
1890 }
1891
1892 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatR16F, GraphicsCo ntext3D::AlphaDoUnmultiply, float, uint16_t>(const float* source, uint16_t* dest ination, unsigned pixelsPerRow)
1893 {
1894 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1895 float scaleFactor = source[3] ? 1.0f / source[3] : 1.0f;
1896 destination[0] = convertFloatToHalfFloat(source[0] * scaleFactor);
1897 source += 4;
1898 destination += 1;
1899 }
1900 }
1901
1902 template<> ALWAYS_INLINE void pack<GraphicsContext3D::DataFormatA16F, GraphicsCo ntext3D::AlphaDoNothing, float, uint16_t>(const float* source, uint16_t* destina tion, unsigned pixelsPerRow)
1903 {
1904 for (unsigned i = 0; i < pixelsPerRow; ++i) {
1905 destination[0] = convertFloatToHalfFloat(source[3]);
1906 source += 4;
1907 destination += 1;
1908 }
1909 }
1910
1624 ALWAYS_INLINE bool HasAlpha(int format) 1911 ALWAYS_INLINE bool HasAlpha(int format)
1625 { 1912 {
1626 return format == GraphicsContext3D::DataFormatA8 1913 return format == GraphicsContext3D::DataFormatA8
1914 || format == GraphicsContext3D::DataFormatA16F
1627 || format == GraphicsContext3D::DataFormatA32F 1915 || format == GraphicsContext3D::DataFormatA32F
1628 || format == GraphicsContext3D::DataFormatRA8 1916 || format == GraphicsContext3D::DataFormatRA8
1629 || format == GraphicsContext3D::DataFormatAR8 1917 || format == GraphicsContext3D::DataFormatAR8
1918 || format == GraphicsContext3D::DataFormatRA16F
1630 || format == GraphicsContext3D::DataFormatRA32F 1919 || format == GraphicsContext3D::DataFormatRA32F
1631 || format == GraphicsContext3D::DataFormatRGBA8 1920 || format == GraphicsContext3D::DataFormatRGBA8
1632 || format == GraphicsContext3D::DataFormatBGRA8 1921 || format == GraphicsContext3D::DataFormatBGRA8
1633 || format == GraphicsContext3D::DataFormatARGB8 1922 || format == GraphicsContext3D::DataFormatARGB8
1634 || format == GraphicsContext3D::DataFormatABGR8 1923 || format == GraphicsContext3D::DataFormatABGR8
1924 || format == GraphicsContext3D::DataFormatRGBA16F
1635 || format == GraphicsContext3D::DataFormatRGBA32F 1925 || format == GraphicsContext3D::DataFormatRGBA32F
1636 || format == GraphicsContext3D::DataFormatRGBA4444 1926 || format == GraphicsContext3D::DataFormatRGBA4444
1637 || format == GraphicsContext3D::DataFormatRGBA5551; 1927 || format == GraphicsContext3D::DataFormatRGBA5551;
1638 } 1928 }
1639 1929
1640 ALWAYS_INLINE bool HasColor(int format) 1930 ALWAYS_INLINE bool HasColor(int format)
1641 { 1931 {
1642 return format == GraphicsContext3D::DataFormatRGBA8 1932 return format == GraphicsContext3D::DataFormatRGBA8
1933 || format == GraphicsContext3D::DataFormatRGBA16F
1643 || format == GraphicsContext3D::DataFormatRGBA32F 1934 || format == GraphicsContext3D::DataFormatRGBA32F
1644 || format == GraphicsContext3D::DataFormatRGB8 1935 || format == GraphicsContext3D::DataFormatRGB8
1936 || format == GraphicsContext3D::DataFormatRGB16F
1645 || format == GraphicsContext3D::DataFormatRGB32F 1937 || format == GraphicsContext3D::DataFormatRGB32F
1646 || format == GraphicsContext3D::DataFormatBGR8 1938 || format == GraphicsContext3D::DataFormatBGR8
1647 || format == GraphicsContext3D::DataFormatBGRA8 1939 || format == GraphicsContext3D::DataFormatBGRA8
1648 || format == GraphicsContext3D::DataFormatARGB8 1940 || format == GraphicsContext3D::DataFormatARGB8
1649 || format == GraphicsContext3D::DataFormatABGR8 1941 || format == GraphicsContext3D::DataFormatABGR8
1650 || format == GraphicsContext3D::DataFormatRGBA5551 1942 || format == GraphicsContext3D::DataFormatRGBA5551
1651 || format == GraphicsContext3D::DataFormatRGBA4444 1943 || format == GraphicsContext3D::DataFormatRGBA4444
1652 || format == GraphicsContext3D::DataFormatRGB565 1944 || format == GraphicsContext3D::DataFormatRGB565
1653 || format == GraphicsContext3D::DataFormatR8 1945 || format == GraphicsContext3D::DataFormatR8
1946 || format == GraphicsContext3D::DataFormatR16F
1654 || format == GraphicsContext3D::DataFormatR32F 1947 || format == GraphicsContext3D::DataFormatR32F
1655 || format == GraphicsContext3D::DataFormatRA8 1948 || format == GraphicsContext3D::DataFormatRA8
1949 || format == GraphicsContext3D::DataFormatRA16F
1656 || format == GraphicsContext3D::DataFormatRA32F 1950 || format == GraphicsContext3D::DataFormatRA32F
1657 || format == GraphicsContext3D::DataFormatAR8; 1951 || format == GraphicsContext3D::DataFormatAR8;
1658 } 1952 }
1659 1953
1660 template<int Format> 1954 template<int Format>
1661 struct IsFloatFormat { 1955 struct IsFloatFormat {
1662 static const bool Value = 1956 static const bool Value =
1663 Format == GraphicsContext3D::DataFormatRGBA32F 1957 Format == GraphicsContext3D::DataFormatRGBA32F
1664 || Format == GraphicsContext3D::DataFormatRGB32F 1958 || Format == GraphicsContext3D::DataFormatRGB32F
1665 || Format == GraphicsContext3D::DataFormatRA32F 1959 || Format == GraphicsContext3D::DataFormatRA32F
1666 || Format == GraphicsContext3D::DataFormatR32F 1960 || Format == GraphicsContext3D::DataFormatR32F
1667 || Format == GraphicsContext3D::DataFormatA32F; 1961 || Format == GraphicsContext3D::DataFormatA32F;
1668 }; 1962 };
1669 1963
1670 template<int Format> 1964 template<int Format>
1965 struct IsHalfFloatFormat {
1966 static const bool Value =
1967 Format == GraphicsContext3D::DataFormatRGBA16F
1968 || Format == GraphicsContext3D::DataFormatRGB16F
1969 || Format == GraphicsContext3D::DataFormatRA16F
1970 || Format == GraphicsContext3D::DataFormatR16F
1971 || Format == GraphicsContext3D::DataFormatA16F;
1972 };
1973
1974 template<int Format>
1671 struct Is16bppFormat { 1975 struct Is16bppFormat {
1672 static const bool Value = 1976 static const bool Value =
1673 Format == GraphicsContext3D::DataFormatRGBA5551 1977 Format == GraphicsContext3D::DataFormatRGBA5551
1674 || Format == GraphicsContext3D::DataFormatRGBA4444 1978 || Format == GraphicsContext3D::DataFormatRGBA4444
1675 || Format == GraphicsContext3D::DataFormatRGB565; 1979 || Format == GraphicsContext3D::DataFormatRGB565;
1676 }; 1980 };
1677 1981
1678 template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Value> 1982 template<int Format, bool IsFloat = IsFloatFormat<Format>::Value, bool IsHalfFlo at = IsHalfFloatFormat<Format>::Value, bool Is16bpp = Is16bppFormat<Format>::Val ue>
1679 struct DataTypeForFormat { 1983 struct DataTypeForFormat {
1680 typedef uint8_t Type; 1984 typedef uint8_t Type;
1681 }; 1985 };
1682 1986
1683 template<int Format> 1987 template<int Format>
1684 struct DataTypeForFormat<Format, true, false> { 1988 struct DataTypeForFormat<Format, true, false, false> {
1685 typedef float Type; 1989 typedef float Type;
1686 }; 1990 };
1687 1991
1688 template<int Format> 1992 template<int Format>
1689 struct DataTypeForFormat<Format, false, true> { 1993 struct DataTypeForFormat<Format, false, true, false> {
1994 typedef uint16_t Type;
1995 };
1996
1997 template<int Format>
1998 struct DataTypeForFormat<Format, false, false, true> {
1690 typedef uint16_t Type; 1999 typedef uint16_t Type;
1691 }; 2000 };
1692 2001
1693 template<int Format> 2002 template<int Format>
1694 struct IntermediateFormat { 2003 struct IntermediateFormat {
1695 static const int Value = IsFloatFormat<Format>::Value ? GraphicsContext3D::D ataFormatRGBA32F : GraphicsContext3D::DataFormatRGBA8; 2004 static const int Value = (IsFloatFormat<Format>::Value || IsHalfFloatFormat< Format>::Value) ? GraphicsContext3D::DataFormatRGBA32F : GraphicsContext3D::Data FormatRGBA8;
1696 }; 2005 };
1697 2006
1698 ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContext3D::DataFormat format) 2007 ALWAYS_INLINE unsigned TexelBytesForFormat(GraphicsContext3D::DataFormat format)
1699 { 2008 {
1700 switch (format) { 2009 switch (format) {
1701 case GraphicsContext3D::DataFormatR8: 2010 case GraphicsContext3D::DataFormatR8:
1702 case GraphicsContext3D::DataFormatA8: 2011 case GraphicsContext3D::DataFormatA8:
1703 return 1; 2012 return 1;
1704 case GraphicsContext3D::DataFormatRA8: 2013 case GraphicsContext3D::DataFormatRA8:
1705 case GraphicsContext3D::DataFormatAR8: 2014 case GraphicsContext3D::DataFormatAR8:
1706 case GraphicsContext3D::DataFormatRGBA5551: 2015 case GraphicsContext3D::DataFormatRGBA5551:
1707 case GraphicsContext3D::DataFormatRGBA4444: 2016 case GraphicsContext3D::DataFormatRGBA4444:
1708 case GraphicsContext3D::DataFormatRGB565: 2017 case GraphicsContext3D::DataFormatRGB565:
2018 case GraphicsContext3D::DataFormatA16F:
2019 case GraphicsContext3D::DataFormatR16F:
1709 return 2; 2020 return 2;
1710 case GraphicsContext3D::DataFormatRGB8: 2021 case GraphicsContext3D::DataFormatRGB8:
1711 case GraphicsContext3D::DataFormatBGR8: 2022 case GraphicsContext3D::DataFormatBGR8:
1712 return 3; 2023 return 3;
1713 case GraphicsContext3D::DataFormatRGBA8: 2024 case GraphicsContext3D::DataFormatRGBA8:
1714 case GraphicsContext3D::DataFormatARGB8: 2025 case GraphicsContext3D::DataFormatARGB8:
1715 case GraphicsContext3D::DataFormatABGR8: 2026 case GraphicsContext3D::DataFormatABGR8:
1716 case GraphicsContext3D::DataFormatBGRA8: 2027 case GraphicsContext3D::DataFormatBGRA8:
1717 case GraphicsContext3D::DataFormatR32F: 2028 case GraphicsContext3D::DataFormatR32F:
1718 case GraphicsContext3D::DataFormatA32F: 2029 case GraphicsContext3D::DataFormatA32F:
2030 case GraphicsContext3D::DataFormatRA16F:
1719 return 4; 2031 return 4;
2032 case GraphicsContext3D::DataFormatRGB16F:
2033 return 6;
1720 case GraphicsContext3D::DataFormatRA32F: 2034 case GraphicsContext3D::DataFormatRA32F:
2035 case GraphicsContext3D::DataFormatRGBA16F:
1721 return 8; 2036 return 8;
1722 case GraphicsContext3D::DataFormatRGB32F: 2037 case GraphicsContext3D::DataFormatRGB32F:
1723 return 12; 2038 return 12;
1724 case GraphicsContext3D::DataFormatRGBA32F: 2039 case GraphicsContext3D::DataFormatRGBA32F:
1725 return 16; 2040 return 16;
1726 default: 2041 default:
1727 return 0; 2042 return 0;
1728 } 2043 }
1729 } 2044 }
1730 2045
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 2111
1797 template<GraphicsContext3D::DataFormat SrcFormat> 2112 template<GraphicsContext3D::DataFormat SrcFormat>
1798 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::DataFormat dstFor mat, GraphicsContext3D::AlphaOp alphaOp) 2113 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::DataFormat dstFor mat, GraphicsContext3D::AlphaOp alphaOp)
1799 { 2114 {
1800 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \ 2115 #define FORMATCONVERTER_CASE_DSTFORMAT(DstFormat) \
1801 case DstFormat: \ 2116 case DstFormat: \
1802 return convert<SrcFormat, DstFormat>(alphaOp); 2117 return convert<SrcFormat, DstFormat>(alphaOp);
1803 2118
1804 switch (dstFormat) { 2119 switch (dstFormat) {
1805 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8) 2120 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR8)
2121 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR16F)
2122 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F)
1806 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8) 2123 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA8)
1807 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatR32F) 2124 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA16F)
1808 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F) 2125 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatA32F)
1809 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8) 2126 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA8)
2127 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA16F)
1810 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F) 2128 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRA32F)
1811 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8) 2129 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB8)
1812 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565) 2130 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB565)
2131 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB16F)
1813 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F) 2132 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGB32F)
1814 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8) 2133 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA8)
1815 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551 ) 2134 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA5551 )
1816 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444 ) 2135 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA4444 )
2136 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA16F)
1817 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F) 2137 FORMATCONVERTER_CASE_DSTFORMAT(GraphicsContext3D::DataFormatRGBA32F)
1818 default: 2138 default:
1819 ASSERT_NOT_REACHED(); 2139 ASSERT_NOT_REACHED();
1820 } 2140 }
1821 2141
1822 #undef FORMATCONVERTER_CASE_DSTFORMAT 2142 #undef FORMATCONVERTER_CASE_DSTFORMAT
1823 } 2143 }
1824 2144
1825 template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat> 2145 template<GraphicsContext3D::DataFormat SrcFormat, GraphicsContext3D::DataFormat DstFormat>
1826 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp) 2146 ALWAYS_INLINE void FormatConverter::convert(GraphicsContext3D::AlphaOp alphaOp)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 ASSERT_NOT_REACHED(); 2188 ASSERT_NOT_REACHED();
1869 return; 2189 return;
1870 } 2190 }
1871 2191
1872 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType; 2192 typedef typename DataTypeForFormat<SrcFormat>::Type SrcType;
1873 typedef typename DataTypeForFormat<DstFormat>::Type DstType; 2193 typedef typename DataTypeForFormat<DstFormat>::Type DstType;
1874 const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value; 2194 const int IntermediateSrcFormat = IntermediateFormat<DstFormat>::Value;
1875 typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type Intermediate SrcType; 2195 typedef typename DataTypeForFormat<IntermediateSrcFormat>::Type Intermediate SrcType;
1876 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType); 2196 const ptrdiff_t srcStrideInElements = m_srcStride / sizeof(SrcType);
1877 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType); 2197 const ptrdiff_t dstStrideInElements = m_dstStride / sizeof(DstType);
1878 const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataForm atRGBA32F; 2198 const bool trivialUnpack = (SrcFormat == GraphicsContext3D::DataFormatRGBA8 && !IsFloatFormat<DstFormat>::Value && !IsHalfFloatFormat<DstFormat>::Value) || SrcFormat == GraphicsContext3D::DataFormatRGBA32F;
1879 const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContex t3D::AlphaDoNothing && m_dstStride > 0; 2199 const bool trivialPack = (DstFormat == GraphicsContext3D::DataFormatRGBA8 || DstFormat == GraphicsContext3D::DataFormatRGBA32F) && alphaOp == GraphicsContex t3D::AlphaDoNothing && m_dstStride > 0;
1880 ASSERT(!trivialUnpack || !trivialPack); 2200 ASSERT(!trivialUnpack || !trivialPack);
1881 2201
1882 const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart); 2202 const SrcType *srcRowStart = static_cast<const SrcType*>(m_srcStart);
1883 DstType* dstRowStart = static_cast<DstType*>(m_dstStart); 2203 DstType* dstRowStart = static_cast<DstType*>(m_dstStart);
1884 if (!trivialUnpack && trivialPack) { 2204 if (!trivialUnpack && trivialPack) {
1885 for (size_t i = 0; i < m_height; ++i) { 2205 for (size_t i = 0; i < m_height; ++i) {
1886 unpack<SrcFormat>(srcRowStart, dstRowStart, m_width); 2206 unpack<SrcFormat>(srcRowStart, dstRowStart, m_width);
1887 srcRowStart += srcStrideInElements; 2207 srcRowStart += srcStrideInElements;
1888 dstRowStart += dstStrideInElements; 2208 dstRowStart += dstStrideInElements;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 case GraphicsContext3D::DEPTH_STENCIL: 2341 case GraphicsContext3D::DEPTH_STENCIL:
2022 return ChannelDepth | ChannelStencil; 2342 return ChannelDepth | ChannelStencil;
2023 default: 2343 default:
2024 return 0; 2344 return 0;
2025 } 2345 }
2026 } 2346 }
2027 2347
2028 } // namespace WebCore 2348 } // namespace WebCore
2029 2349
2030 #endif // USE(3D_GRAPHICS) 2350 #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