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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 1856933002: WebGL GL_RGB emulation to support IOSurfaces on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Full client side implementation of GL_RGB emulation. Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 #include "public/platform/Platform.h" 96 #include "public/platform/Platform.h"
97 #include "public/platform/WebGraphicsContext3D.h" 97 #include "public/platform/WebGraphicsContext3D.h"
98 #include "public/platform/WebGraphicsContext3DProvider.h" 98 #include "public/platform/WebGraphicsContext3DProvider.h"
99 #include "public/platform/callback/WebClosure.h" 99 #include "public/platform/callback/WebClosure.h"
100 #include "wtf/ArrayBufferContents.h" 100 #include "wtf/ArrayBufferContents.h"
101 #include "wtf/Functional.h" 101 #include "wtf/Functional.h"
102 #include "wtf/PassOwnPtr.h" 102 #include "wtf/PassOwnPtr.h"
103 #include "wtf/text/StringBuilder.h" 103 #include "wtf/text/StringBuilder.h"
104 #include "wtf/text/StringUTF8Adaptor.h" 104 #include "wtf/text/StringUTF8Adaptor.h"
105 105
106 #include <memory>
107
106 namespace blink { 108 namespace blink {
107 109
108 namespace { 110 namespace {
109 111
110 const double secondsBetweenRestoreAttempts = 1.0; 112 const double secondsBetweenRestoreAttempts = 1.0;
111 const int maxGLErrorsAllowedToConsole = 256; 113 const int maxGLErrorsAllowedToConsole = 256;
112 const unsigned maxGLActiveContexts = 16; 114 const unsigned maxGLActiveContexts = 16;
113 115
114 using WebGLRenderingContextBaseSet = PersistentHeapHashSet<WeakMember<WebGLRende ringContextBase>>; 116 using WebGLRenderingContextBaseSet = PersistentHeapHashSet<WeakMember<WebGLRende ringContextBase>>;
115 WebGLRenderingContextBaseSet& activeContexts() 117 WebGLRenderingContextBaseSet& activeContexts()
116 { 118 {
117 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseSet, activeContexts, ()); 119 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseSet, activeContexts, ());
118 return activeContexts; 120 return activeContexts;
119 } 121 }
120 122
121 using WebGLRenderingContextBaseMap = PersistentHeapHashMap<WeakMember<WebGLRende ringContextBase>, int>; 123 using WebGLRenderingContextBaseMap = PersistentHeapHashMap<WeakMember<WebGLRende ringContextBase>, int>;
122 WebGLRenderingContextBaseMap& forciblyEvictedContexts() 124 WebGLRenderingContextBaseMap& forciblyEvictedContexts()
123 { 125 {
124 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseMap, forciblyEvictedContexts, ( )); 126 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseMap, forciblyEvictedContexts, ( ));
125 return forciblyEvictedContexts; 127 return forciblyEvictedContexts;
126 } 128 }
127 129
130 class ScopedRGBEmulationColorMask {
131 public:
132 ScopedRGBEmulationColorMask(gpu::gles2::GLES2Interface* contextGL, GLboolean * colorMask)
133 : m_contextGL(contextGL)
134 {
135 memcpy(m_colorMask, colorMask, 4 * sizeof(GLboolean));
136 m_contextGL->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], f alse);
137 }
138 ~ScopedRGBEmulationColorMask()
139 {
140 m_contextGL->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], m _colorMask[3]);
141 }
142
143 private:
144 gpu::gles2::GLES2Interface* m_contextGL;
145 GLboolean m_colorMask[4];
146 };
147
128 } // namespace 148 } // namespace
129 149
130 void WebGLRenderingContextBase::forciblyLoseOldestContext(const String& reason) 150 void WebGLRenderingContextBase::forciblyLoseOldestContext(const String& reason)
131 { 151 {
132 WebGLRenderingContextBase* candidate = oldestContext(); 152 WebGLRenderingContextBase* candidate = oldestContext();
133 if (!candidate) 153 if (!candidate)
134 return; 154 return;
135 155
136 // This context could belong to a dead page and the last JavaScript referenc e has already 156 // This context could belong to a dead page and the last JavaScript referenc e has already
137 // been lost. Garbage collection might be triggered in the middle of this fu nction, for 157 // been lost. Garbage collection might be triggered in the middle of this fu nction, for
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1179
1160 contextGL()->Disable(GL_SCISSOR_TEST); 1180 contextGL()->Disable(GL_SCISSOR_TEST);
1161 if (combinedClear && (mask & GL_COLOR_BUFFER_BIT)) { 1181 if (combinedClear && (mask & GL_COLOR_BUFFER_BIT)) {
1162 contextGL()->ClearColor(m_colorMask[0] ? m_clearColor[0] : 0, 1182 contextGL()->ClearColor(m_colorMask[0] ? m_clearColor[0] : 0,
1163 m_colorMask[1] ? m_clearColor[1] : 0, 1183 m_colorMask[1] ? m_clearColor[1] : 0,
1164 m_colorMask[2] ? m_clearColor[2] : 0, 1184 m_colorMask[2] ? m_clearColor[2] : 0,
1165 m_colorMask[3] ? m_clearColor[3] : 0); 1185 m_colorMask[3] ? m_clearColor[3] : 0);
1166 } else { 1186 } else {
1167 contextGL()->ClearColor(0, 0, 0, 0); 1187 contextGL()->ClearColor(0, 0, 0, 0);
1168 } 1188 }
1169 contextGL()->ColorMask(true, true, true, true); 1189 contextGL()->ColorMask(true, true, true, !drawingBuffer()->requiresRGBEmulat ion());
1170 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 1190 GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
1171 if (contextAttributes.get().depth()) { 1191 if (contextAttributes.get().depth()) {
1172 if (!combinedClear || !m_depthMask || !(mask & GL_DEPTH_BUFFER_BIT)) 1192 if (!combinedClear || !m_depthMask || !(mask & GL_DEPTH_BUFFER_BIT))
1173 contextGL()->ClearDepthf(1.0f); 1193 contextGL()->ClearDepthf(1.0f);
1174 clearMask |= GL_DEPTH_BUFFER_BIT; 1194 clearMask |= GL_DEPTH_BUFFER_BIT;
1175 contextGL()->DepthMask(true); 1195 contextGL()->DepthMask(true);
1176 } 1196 }
1177 if (contextAttributes.get().stencil() || drawingBuffer()->hasImplicitStencil Buffer()) { 1197 if (contextAttributes.get().stencil() || drawingBuffer()->hasImplicitStencil Buffer()) {
1178 if (combinedClear && (mask & GL_STENCIL_BUFFER_BIT)) 1198 if (combinedClear && (mask & GL_STENCIL_BUFFER_BIT))
1179 contextGL()->ClearStencil(m_clearStencil & m_stencilMask); 1199 contextGL()->ClearStencil(m_clearStencil & m_stencilMask);
(...skipping 23 matching lines...) Expand all
1203 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1], 1223 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1],
1204 m_clearColor[2], m_clearColor[3]); 1224 m_clearColor[2], m_clearColor[3]);
1205 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1], 1225 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1],
1206 m_colorMask[2], m_colorMask[3]); 1226 m_colorMask[2], m_colorMask[3]);
1207 contextGL()->ClearDepthf(m_clearDepth); 1227 contextGL()->ClearDepthf(m_clearDepth);
1208 contextGL()->ClearStencil(m_clearStencil); 1228 contextGL()->ClearStencil(m_clearStencil);
1209 contextGL()->StencilMaskSeparate(GL_FRONT, m_stencilMask); 1229 contextGL()->StencilMaskSeparate(GL_FRONT, m_stencilMask);
1210 contextGL()->DepthMask(m_depthMask); 1230 contextGL()->DepthMask(m_depthMask);
1211 } 1231 }
1212 1232
1233 void WebGLRenderingContextBase::moveGLErrorsToInternalQueue()
1234 {
1235 DCHECK(!isContextLost());
1236 GLenum error = GL_NO_ERROR;
1237 while ((error = contextGL()->GetError()) != GL_NO_ERROR) {
1238 if (!m_syntheticErrors.contains(error))
1239 m_syntheticErrors.append(error);
1240 }
1241 }
1242
1213 void WebGLRenderingContextBase::markLayerComposited() 1243 void WebGLRenderingContextBase::markLayerComposited()
1214 { 1244 {
1215 if (!isContextLost()) 1245 if (!isContextLost())
1216 drawingBuffer()->setBufferClearNeeded(true); 1246 drawingBuffer()->setBufferClearNeeded(true);
1217 } 1247 }
1218 1248
1219 void WebGLRenderingContextBase::setIsHidden(bool hidden) 1249 void WebGLRenderingContextBase::setIsHidden(bool hidden)
1220 { 1250 {
1221 m_isHidden = hidden; 1251 m_isHidden = hidden;
1222 if (drawingBuffer()) 1252 if (drawingBuffer())
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 return; 1719 return;
1690 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) { 1720 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) {
1691 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask"); 1721 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask");
1692 return; 1722 return;
1693 } 1723 }
1694 const char* reason = "framebuffer incomplete"; 1724 const char* reason = "framebuffer incomplete";
1695 if (m_framebufferBinding && m_framebufferBinding->checkDepthStencilStatus(&r eason) != GL_FRAMEBUFFER_COMPLETE) { 1725 if (m_framebufferBinding && m_framebufferBinding->checkDepthStencilStatus(&r eason) != GL_FRAMEBUFFER_COMPLETE) {
1696 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason); 1726 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
1697 return; 1727 return;
1698 } 1728 }
1729
1730 std::unique_ptr<ScopedRGBEmulationColorMask> scopedColorMask;
1731 if (m_drawingBuffer->requiresRGBEmulation())
1732 scopedColorMask.reset(new ScopedRGBEmulationColorMask(contextGL(), m_col orMask));
1733
1699 if (clearIfComposited(mask) != CombinedClear) { 1734 if (clearIfComposited(mask) != CombinedClear) {
1700 // If clearing the default back buffer's depth buffer, also clear the st encil buffer, if one 1735 // If clearing the default back buffer's depth buffer, also clear the st encil buffer, if one
1701 // was allocated implicitly. This avoids performance problems on some GP Us. 1736 // was allocated implicitly. This avoids performance problems on some GP Us.
1702 if (!m_framebufferBinding && drawingBuffer()->hasImplicitStencilBuffer() && (mask & GL_DEPTH_BUFFER_BIT)) { 1737 if (!m_framebufferBinding && drawingBuffer()->hasImplicitStencilBuffer() && (mask & GL_DEPTH_BUFFER_BIT)) {
1703 // It shouldn't matter what value it's cleared to, since in other qu eries in the API, we 1738 // It shouldn't matter what value it's cleared to, since in other qu eries in the API, we
1704 // claim that the stencil buffer doesn't exist. 1739 // claim that the stencil buffer doesn't exist.
1705 mask |= GL_STENCIL_BUFFER_BIT; 1740 mask |= GL_STENCIL_BUFFER_BIT;
1706 } 1741 }
1707 contextGL()->Clear(mask); 1742 contextGL()->Clear(mask);
1708 } 1743 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 { 1794 {
1760 if (isContextLost() || !validateWebGLObject("compileShader", shader)) 1795 if (isContextLost() || !validateWebGLObject("compileShader", shader))
1761 return; 1796 return;
1762 contextGL()->CompileShader(objectOrZero(shader)); 1797 contextGL()->CompileShader(objectOrZero(shader));
1763 } 1798 }
1764 1799
1765 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, DOMArrayBuf ferView* data) 1800 void WebGLRenderingContextBase::compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, DOMArrayBuf ferView* data)
1766 { 1801 {
1767 if (isContextLost()) 1802 if (isContextLost())
1768 return; 1803 return;
1769 if (!validateTexture2DBinding("compressedTexImage2D", target)) 1804 WebGLTexture* texture = validateTexture2DBinding("compressedTexImage2D", tar get);
1805 if (!texture)
1770 return; 1806 return;
1771 if (!validateCompressedTexFormat("compressedTexImage2D", internalformat)) 1807 if (!validateCompressedTexFormat("compressedTexImage2D", internalformat))
1772 return; 1808 return;
1809
1810 moveGLErrorsToInternalQueue();
1773 contextGL()->CompressedTexImage2D(target, level, internalformat, width, heig ht, 1811 contextGL()->CompressedTexImage2D(target, level, internalformat, width, heig ht,
1774 border, data->byteLength(), data->baseAddress()); 1812 border, data->byteLength(), data->baseAddress());
1813
1814 GLenum error = contextGL()->GetError();
1815 if (error == GL_NO_ERROR) {
1816 texture->setColorFormat(internalformat);
1817 } else {
1818 if (!m_syntheticErrors.contains(error))
1819 m_syntheticErrors.append(error);
1820 }
1775 } 1821 }
1776 1822
1777 void WebGLRenderingContextBase::compressedTexSubImage2D(GLenum target, GLint lev el, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, DOMArrayBufferView* data) 1823 void WebGLRenderingContextBase::compressedTexSubImage2D(GLenum target, GLint lev el, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, DOMArrayBufferView* data)
1778 { 1824 {
1779 if (isContextLost()) 1825 if (isContextLost())
1780 return; 1826 return;
1781 if (!validateTexture2DBinding("compressedTexSubImage2D", target)) 1827 if (!validateTexture2DBinding("compressedTexSubImage2D", target))
1782 return; 1828 return;
1783 if (!validateCompressedTexFormat("compressedTexSubImage2D", format)) 1829 if (!validateCompressedTexFormat("compressedTexSubImage2D", format))
1784 return; 1830 return;
(...skipping 25 matching lines...) Expand all
1810 return false; 1856 return false;
1811 } 1857 }
1812 1858
1813 return true; 1859 return true;
1814 } 1860 }
1815 1861
1816 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) 1862 void WebGLRenderingContextBase::copyTexImage2D(GLenum target, GLint level, GLenu m internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
1817 { 1863 {
1818 if (isContextLost()) 1864 if (isContextLost())
1819 return; 1865 return;
1820 if (!validateTexture2DBinding("copyTexImage2D", target)) 1866 WebGLTexture* texture = validateTexture2DBinding("copyTexImage2D", target);
1867 if (!texture)
1821 return; 1868 return;
1822 if (!validateCopyTexFormat("copyTexImage2D", internalformat)) 1869 if (!validateCopyTexFormat("copyTexImage2D", internalformat))
1823 return; 1870 return;
1824 if (!validateSettableTexFormat("copyTexImage2D", internalformat)) 1871 if (!validateSettableTexFormat("copyTexImage2D", internalformat))
1825 return; 1872 return;
1873
1874 // If RGB emulation is required, then the destination format should not have
1875 // an alpha channel.
1876 if (drawingBuffer()->requiresRGBEmulation()) {
1877 uint32_t channelsExist = WebGLImageConversion::getChannelBitsByFormat(GL _RGB);
1878 uint32_t channelsNeeded = WebGLImageConversion::getChannelBitsByFormat(i nternalformat);
1879 if ((channelsNeeded & channelsExist) != channelsNeeded) {
1880 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "incompati ble format");
1881 return;
1882 }
1883 }
1884
1826 WebGLFramebuffer* readFramebufferBinding = nullptr; 1885 WebGLFramebuffer* readFramebufferBinding = nullptr;
1827 if (!validateReadBufferAndGetInfo("copyTexImage2D", readFramebufferBinding)) 1886 if (!validateReadBufferAndGetInfo("copyTexImage2D", readFramebufferBinding))
1828 return; 1887 return;
1829 clearIfComposited(); 1888 clearIfComposited();
1830 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); 1889 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding);
1890 moveGLErrorsToInternalQueue();
1831 contextGL()->CopyTexImage2D(target, level, internalformat, x, y, width, heig ht, border); 1891 contextGL()->CopyTexImage2D(target, level, internalformat, x, y, width, heig ht, border);
1892
1893 GLenum error = contextGL()->GetError();
1894 if (error == GL_NO_ERROR) {
1895 texture->setColorFormat(internalformat);
1896 } else {
1897 if (!m_syntheticErrors.contains(error))
1898 m_syntheticErrors.append(error);
1899 }
1832 } 1900 }
1833 1901
1834 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) 1902 void WebGLRenderingContextBase::copyTexSubImage2D(GLenum target, GLint level, GL int xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1835 { 1903 {
1836 if (isContextLost()) 1904 if (isContextLost())
1837 return; 1905 return;
1838 if (!validateTexture2DBinding("copyTexSubImage2D", target)) 1906 WebGLTexture* texture = validateTexture2DBinding("copyTexSubImage2D", target );
1907 if (!texture)
1839 return; 1908 return;
1909
1910 // If RGB emulation is required, then the destination format should not have
1911 // an alpha channel.
1912 if (drawingBuffer()->requiresRGBEmulation()) {
1913 uint32_t channelsExist = WebGLImageConversion::getChannelBitsByFormat(GL _RGB);
1914 uint32_t channelsNeeded = WebGLImageConversion::getChannelBitsByFormat(t exture->getColorFormat());
1915 if ((channelsNeeded & channelsExist) != channelsNeeded) {
1916 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "incomp atible format");
1917 return;
1918 }
1919 }
1920
1840 WebGLFramebuffer* readFramebufferBinding = nullptr; 1921 WebGLFramebuffer* readFramebufferBinding = nullptr;
1841 if (!validateReadBufferAndGetInfo("copyTexSubImage2D", readFramebufferBindin g)) 1922 if (!validateReadBufferAndGetInfo("copyTexSubImage2D", readFramebufferBindin g))
1842 return; 1923 return;
1843 clearIfComposited(); 1924 clearIfComposited();
1844 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding); 1925 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding);
1845 contextGL()->CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 1926 contextGL()->CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
1846 } 1927 }
1847 1928
1848 WebGLBuffer* WebGLRenderingContextBase::createBuffer() 1929 WebGLBuffer* WebGLRenderingContextBase::createBuffer()
1849 { 1930 {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 return false; 2190 return false;
2110 } 2191 }
2111 return true; 2192 return true;
2112 } 2193 }
2113 2194
2114 void WebGLRenderingContextBase::drawArrays(GLenum mode, GLint first, GLsizei cou nt) 2195 void WebGLRenderingContextBase::drawArrays(GLenum mode, GLint first, GLsizei cou nt)
2115 { 2196 {
2116 if (!validateDrawArrays("drawArrays")) 2197 if (!validateDrawArrays("drawArrays"))
2117 return; 2198 return;
2118 2199
2200 std::unique_ptr<ScopedRGBEmulationColorMask> scopedColorMask;
2201 if (m_drawingBuffer->requiresRGBEmulation())
2202 scopedColorMask.reset(new ScopedRGBEmulationColorMask(contextGL(), m_col orMask));
2119 clearIfComposited(); 2203 clearIfComposited();
2120 contextGL()->DrawArrays(mode, first, count); 2204 contextGL()->DrawArrays(mode, first, count);
2121 markContextChanged(CanvasChanged); 2205 markContextChanged(CanvasChanged);
2122 } 2206 }
2123 2207
2124 void WebGLRenderingContextBase::drawElements(GLenum mode, GLsizei count, GLenum type, long long offset) 2208 void WebGLRenderingContextBase::drawElements(GLenum mode, GLsizei count, GLenum type, long long offset)
2125 { 2209 {
2126 if (!validateDrawElements("drawElements", type, offset)) 2210 if (!validateDrawElements("drawElements", type, offset))
2127 return; 2211 return;
2128 2212
2129 if (transformFeedbackActive() && !transformFeedbackPaused()) { 2213 if (transformFeedbackActive() && !transformFeedbackPaused()) {
2130 synthesizeGLError(GL_INVALID_OPERATION, "drawElements", "transform feedb ack is active and not paused"); 2214 synthesizeGLError(GL_INVALID_OPERATION, "drawElements", "transform feedb ack is active and not paused");
2131 return; 2215 return;
2132 } 2216 }
2133 2217
2218 std::unique_ptr<ScopedRGBEmulationColorMask> scopedColorMask;
2219 if (m_drawingBuffer->requiresRGBEmulation())
2220 scopedColorMask.reset(new ScopedRGBEmulationColorMask(contextGL(), m_col orMask));
2134 clearIfComposited(); 2221 clearIfComposited();
2135 contextGL()->DrawElements(mode, count, type, reinterpret_cast<void*>(static_ cast<intptr_t>(offset))); 2222 contextGL()->DrawElements(mode, count, type, reinterpret_cast<void*>(static_ cast<intptr_t>(offset)));
2136 markContextChanged(CanvasChanged); 2223 markContextChanged(CanvasChanged);
2137 } 2224 }
2138 2225
2139 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode, GLint firs t, GLsizei count, GLsizei primcount) 2226 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode, GLint firs t, GLsizei count, GLsizei primcount)
2140 { 2227 {
2141 if (!validateDrawArrays("drawArraysInstancedANGLE")) 2228 if (!validateDrawArrays("drawArraysInstancedANGLE"))
2142 return; 2229 return;
2143 2230
2231 std::unique_ptr<ScopedRGBEmulationColorMask> scopedColorMask;
2232 if (m_drawingBuffer->requiresRGBEmulation())
2233 scopedColorMask.reset(new ScopedRGBEmulationColorMask(contextGL(), m_col orMask));
2144 clearIfComposited(); 2234 clearIfComposited();
2145 contextGL()->DrawArraysInstancedANGLE(mode, first, count, primcount); 2235 contextGL()->DrawArraysInstancedANGLE(mode, first, count, primcount);
2146 markContextChanged(CanvasChanged); 2236 markContextChanged(CanvasChanged);
2147 } 2237 }
2148 2238
2149 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, long long offset, GLsizei primcount) 2239 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, long long offset, GLsizei primcount)
2150 { 2240 {
2151 if (!validateDrawElements("drawElementsInstancedANGLE", type, offset)) 2241 if (!validateDrawElements("drawElementsInstancedANGLE", type, offset))
2152 return; 2242 return;
2153 2243
2244 std::unique_ptr<ScopedRGBEmulationColorMask> scopedColorMask;
2245 if (m_drawingBuffer->requiresRGBEmulation())
2246 scopedColorMask.reset(new ScopedRGBEmulationColorMask(contextGL(), m_col orMask));
2154 clearIfComposited(); 2247 clearIfComposited();
2155 contextGL()->DrawElementsInstancedANGLE(mode, count, type, reinterpret_cast< void*>(static_cast<intptr_t>(offset)), primcount); 2248 contextGL()->DrawElementsInstancedANGLE(mode, count, type, reinterpret_cast< void*>(static_cast<intptr_t>(offset)), primcount);
2156 markContextChanged(CanvasChanged); 2249 markContextChanged(CanvasChanged);
2157 } 2250 }
2158 2251
2159 void WebGLRenderingContextBase::enable(GLenum cap) 2252 void WebGLRenderingContextBase::enable(GLenum cap)
2160 { 2253 {
2161 if (isContextLost() || !validateCapability("enable", cap)) 2254 if (isContextLost() || !validateCapability("enable", cap))
2162 return; 2255 return;
2163 if (cap == GL_STENCIL_TEST) { 2256 if (cap == GL_STENCIL_TEST) {
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 return ScriptValue::createNull(scriptState); 2668 return ScriptValue::createNull(scriptState);
2576 const int intZero = 0; 2669 const int intZero = 0;
2577 switch (pname) { 2670 switch (pname) {
2578 case GL_ACTIVE_TEXTURE: 2671 case GL_ACTIVE_TEXTURE:
2579 return getUnsignedIntParameter(scriptState, pname); 2672 return getUnsignedIntParameter(scriptState, pname);
2580 case GL_ALIASED_LINE_WIDTH_RANGE: 2673 case GL_ALIASED_LINE_WIDTH_RANGE:
2581 return getWebGLFloatArrayParameter(scriptState, pname); 2674 return getWebGLFloatArrayParameter(scriptState, pname);
2582 case GL_ALIASED_POINT_SIZE_RANGE: 2675 case GL_ALIASED_POINT_SIZE_RANGE:
2583 return getWebGLFloatArrayParameter(scriptState, pname); 2676 return getWebGLFloatArrayParameter(scriptState, pname);
2584 case GL_ALPHA_BITS: 2677 case GL_ALPHA_BITS:
2678 if (m_drawingBuffer->requiresRGBEmulation())
2679 return WebGLAny(scriptState, 0);
2585 return getIntParameter(scriptState, pname); 2680 return getIntParameter(scriptState, pname);
2586 case GL_ARRAY_BUFFER_BINDING: 2681 case GL_ARRAY_BUFFER_BINDING:
2587 return WebGLAny(scriptState, m_boundArrayBuffer.get()); 2682 return WebGLAny(scriptState, m_boundArrayBuffer.get());
2588 case GL_BLEND: 2683 case GL_BLEND:
2589 return getBooleanParameter(scriptState, pname); 2684 return getBooleanParameter(scriptState, pname);
2590 case GL_BLEND_COLOR: 2685 case GL_BLEND_COLOR:
2591 return getWebGLFloatArrayParameter(scriptState, pname); 2686 return getWebGLFloatArrayParameter(scriptState, pname);
2592 case GL_BLEND_DST_ALPHA: 2687 case GL_BLEND_DST_ALPHA:
2593 return getUnsignedIntParameter(scriptState, pname); 2688 return getUnsignedIntParameter(scriptState, pname);
2594 case GL_BLEND_DST_RGB: 2689 case GL_BLEND_DST_RGB:
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgba")) 3994 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgba"))
3900 return GL_RGBA32F_EXT; 3995 return GL_RGBA32F_EXT;
3901 if (type == GL_FLOAT && internalformat == GL_RGB 3996 if (type == GL_FLOAT && internalformat == GL_RGB
3902 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb")) 3997 && extensionsUtil()->isExtensionEnabled("GL_CHROMIUM_color_buffer_float_ rgb"))
3903 return GL_RGB32F_EXT; 3998 return GL_RGB32F_EXT;
3904 return internalformat; 3999 return internalformat;
3905 } 4000 }
3906 4001
3907 void WebGLRenderingContextBase::texImage2DBase(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLe num type, const void* pixels) 4002 void WebGLRenderingContextBase::texImage2DBase(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLe num type, const void* pixels)
3908 { 4003 {
4004 moveGLErrorsToInternalQueue();
4005
3909 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4006 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3910 contextGL()->TexImage2D(target, level, convertTexInternalFormat(internalform at, type), width, height, border, format, type, pixels); 4007 contextGL()->TexImage2D(target, level, convertTexInternalFormat(internalform at, type), width, height, border, format, type, pixels);
4008
4009 GLenum error = contextGL()->GetError();
Ken Russell (switch to Gerrit) 2016/04/06 00:02:53 Sorry, but this synchronous GetError call will kil
4010 if (error == GL_NO_ERROR) {
4011 WebGLTexture* texture = validateTexture2DBinding("texImage2DBase", targe t);
4012 if (texture)
4013 texture->setColorFormat(format);
4014 } else {
4015 if (!m_syntheticErrors.contains(error))
4016 m_syntheticErrors.append(error);
4017 }
3911 } 4018 }
3912 4019
3913 void WebGLRenderingContextBase::texImage2DImpl(GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type, Image* image, WebGLImageConversion: :ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha) 4020 void WebGLRenderingContextBase::texImage2DImpl(GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type, Image* image, WebGLImageConversion: :ImageHtmlDomSource domSource, bool flipY, bool premultiplyAlpha)
3914 { 4021 {
3915 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4022 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
3916 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4023 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
3917 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4024 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
3918 type = GL_FLOAT; 4025 type = GL_FLOAT;
3919 } 4026 }
3920 Vector<uint8_t> data; 4027 Vector<uint8_t> data;
(...skipping 2431 matching lines...) Expand 10 before | Expand all | Expand 10 after
6352 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6459 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6353 } 6460 }
6354 6461
6355 void WebGLRenderingContextBase::restoreUnpackParameters() 6462 void WebGLRenderingContextBase::restoreUnpackParameters()
6356 { 6463 {
6357 if (m_unpackAlignment != 1) 6464 if (m_unpackAlignment != 1)
6358 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6465 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6359 } 6466 }
6360 6467
6361 } // namespace blink 6468 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698