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

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

Issue 2535173002: Prevent implicit framebuffer clear from clobbering alpha in emulated RGB (Closed)
Patch Set: remove unnecessary std::list Created 4 years 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ThreadSpecific<WebGLRenderingContextBaseMap>, forciblyEvictedContexts, 133 ThreadSpecific<WebGLRenderingContextBaseMap>, forciblyEvictedContexts,
134 new ThreadSpecific<WebGLRenderingContextBaseMap>()); 134 new ThreadSpecific<WebGLRenderingContextBaseMap>());
135 if (!forciblyEvictedContexts.isSet()) 135 if (!forciblyEvictedContexts.isSet())
136 forciblyEvictedContexts->registerAsStaticReference(); 136 forciblyEvictedContexts->registerAsStaticReference();
137 return *forciblyEvictedContexts; 137 return *forciblyEvictedContexts;
138 } 138 }
139 139
140 } // namespace 140 } // namespace
141 141
142 ScopedRGBEmulationColorMask::ScopedRGBEmulationColorMask( 142 ScopedRGBEmulationColorMask::ScopedRGBEmulationColorMask(
143 gpu::gles2::GLES2Interface* contextGL, 143 WebGLRenderingContextBase* context,
144 GLboolean* colorMask, 144 GLboolean* colorMask,
145 DrawingBuffer* drawingBuffer) 145 DrawingBuffer* drawingBuffer)
146 : m_contextGL(contextGL), 146 : m_context(context),
147 m_requiresEmulation(drawingBuffer->requiresAlphaChannelToBePreserved()) { 147 m_requiresEmulation(drawingBuffer->requiresAlphaChannelToBePreserved()) {
148 if (m_requiresEmulation) { 148 if (m_requiresEmulation) {
149 m_context->m_activeScopedRGBEmulationColorMasks++;
149 memcpy(m_colorMask, colorMask, 4 * sizeof(GLboolean)); 150 memcpy(m_colorMask, colorMask, 4 * sizeof(GLboolean));
150 m_contextGL->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], 151 m_context->contextGL()->ColorMask(m_colorMask[0], m_colorMask[1],
151 false); 152 m_colorMask[2], false);
152 } 153 }
153 } 154 }
154 155
155 ScopedRGBEmulationColorMask::~ScopedRGBEmulationColorMask() { 156 ScopedRGBEmulationColorMask::~ScopedRGBEmulationColorMask() {
156 if (m_requiresEmulation) 157 if (m_requiresEmulation) {
157 m_contextGL->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], 158 DCHECK(m_context->m_activeScopedRGBEmulationColorMasks);
158 m_colorMask[3]); 159 m_context->m_activeScopedRGBEmulationColorMasks--;
160 m_context->contextGL()->ColorMask(m_colorMask[0], m_colorMask[1],
161 m_colorMask[2], m_colorMask[3]);
162 }
159 } 163 }
160 164
161 void WebGLRenderingContextBase::forciblyLoseOldestContext( 165 void WebGLRenderingContextBase::forciblyLoseOldestContext(
162 const String& reason) { 166 const String& reason) {
163 WebGLRenderingContextBase* candidate = oldestContext(); 167 WebGLRenderingContextBase* candidate = oldestContext();
164 if (!candidate) 168 if (!candidate)
165 return; 169 return;
166 170
167 candidate->printWarningToConsole(reason); 171 candidate->printWarningToConsole(reason);
168 InspectorInstrumentation::didFireWebGLWarning(candidate->canvas()); 172 InspectorInstrumentation::didFireWebGLWarning(candidate->canvas());
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1957 return; 1961 return;
1958 } 1962 }
1959 const char* reason = "framebuffer incomplete"; 1963 const char* reason = "framebuffer incomplete";
1960 if (m_framebufferBinding && 1964 if (m_framebufferBinding &&
1961 m_framebufferBinding->checkDepthStencilStatus(&reason) != 1965 m_framebufferBinding->checkDepthStencilStatus(&reason) !=
1962 GL_FRAMEBUFFER_COMPLETE) { 1966 GL_FRAMEBUFFER_COMPLETE) {
1963 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason); 1967 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
1964 return; 1968 return;
1965 } 1969 }
1966 1970
1967 ScopedRGBEmulationColorMask emulationColorMask(contextGL(), m_colorMask, 1971 ScopedRGBEmulationColorMask emulationColorMask(this, m_colorMask,
1968 m_drawingBuffer.get()); 1972 m_drawingBuffer.get());
1969 1973
1970 if (clearIfComposited(mask) != CombinedClear) { 1974 if (clearIfComposited(mask) != CombinedClear) {
1971 // If clearing the default back buffer's depth buffer, also clear the 1975 // If clearing the default back buffer's depth buffer, also clear the
1972 // stencil buffer, if one was allocated implicitly. This avoids performance 1976 // stencil buffer, if one was allocated implicitly. This avoids performance
1973 // problems on some GPUs. 1977 // problems on some GPUs.
1974 if (!m_framebufferBinding && drawingBuffer()->hasImplicitStencilBuffer() && 1978 if (!m_framebufferBinding && drawingBuffer()->hasImplicitStencilBuffer() &&
1975 (mask & GL_DEPTH_BUFFER_BIT)) { 1979 (mask & GL_DEPTH_BUFFER_BIT)) {
1976 // It shouldn't matter what value it's cleared to, since in other queries 1980 // It shouldn't matter what value it's cleared to, since in other queries
1977 // in the API, we claim that the stencil buffer doesn't exist. 1981 // in the API, we claim that the stencil buffer doesn't exist.
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 GLsizei count) { 2420 GLsizei count) {
2417 if (!validateDrawArrays("drawArrays")) 2421 if (!validateDrawArrays("drawArrays"))
2418 return; 2422 return;
2419 2423
2420 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) { 2424 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) {
2421 synthesizeGLError(GL_INVALID_OPERATION, "drawArrays", 2425 synthesizeGLError(GL_INVALID_OPERATION, "drawArrays",
2422 "no buffer is bound to enabled attribute"); 2426 "no buffer is bound to enabled attribute");
2423 return; 2427 return;
2424 } 2428 }
2425 2429
2426 ScopedRGBEmulationColorMask emulationColorMask(contextGL(), m_colorMask, 2430 ScopedRGBEmulationColorMask emulationColorMask(this, m_colorMask,
2427 m_drawingBuffer.get()); 2431 m_drawingBuffer.get());
2428 clearIfComposited(); 2432 clearIfComposited();
2429 contextGL()->DrawArrays(mode, first, count); 2433 contextGL()->DrawArrays(mode, first, count);
2430 markContextChanged(CanvasChanged); 2434 markContextChanged(CanvasChanged);
2431 } 2435 }
2432 2436
2433 void WebGLRenderingContextBase::drawElements(GLenum mode, 2437 void WebGLRenderingContextBase::drawElements(GLenum mode,
2434 GLsizei count, 2438 GLsizei count,
2435 GLenum type, 2439 GLenum type,
2436 long long offset) { 2440 long long offset) {
2437 if (!validateDrawElements("drawElements", type, offset)) 2441 if (!validateDrawElements("drawElements", type, offset))
2438 return; 2442 return;
2439 2443
2440 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) { 2444 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) {
2441 synthesizeGLError(GL_INVALID_OPERATION, "drawElements", 2445 synthesizeGLError(GL_INVALID_OPERATION, "drawElements",
2442 "no buffer is bound to enabled attribute"); 2446 "no buffer is bound to enabled attribute");
2443 return; 2447 return;
2444 } 2448 }
2445 2449
2446 ScopedRGBEmulationColorMask emulationColorMask(contextGL(), m_colorMask, 2450 ScopedRGBEmulationColorMask emulationColorMask(this, m_colorMask,
2447 m_drawingBuffer.get()); 2451 m_drawingBuffer.get());
2448 clearIfComposited(); 2452 clearIfComposited();
2449 contextGL()->DrawElements( 2453 contextGL()->DrawElements(
2450 mode, count, type, 2454 mode, count, type,
2451 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 2455 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
2452 markContextChanged(CanvasChanged); 2456 markContextChanged(CanvasChanged);
2453 } 2457 }
2454 2458
2455 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode, 2459 void WebGLRenderingContextBase::drawArraysInstancedANGLE(GLenum mode,
2456 GLint first, 2460 GLint first,
2457 GLsizei count, 2461 GLsizei count,
2458 GLsizei primcount) { 2462 GLsizei primcount) {
2459 if (!validateDrawArrays("drawArraysInstancedANGLE")) 2463 if (!validateDrawArrays("drawArraysInstancedANGLE"))
2460 return; 2464 return;
2461 2465
2462 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) { 2466 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) {
2463 synthesizeGLError(GL_INVALID_OPERATION, "drawArraysInstancedANGLE", 2467 synthesizeGLError(GL_INVALID_OPERATION, "drawArraysInstancedANGLE",
2464 "no buffer is bound to enabled attribute"); 2468 "no buffer is bound to enabled attribute");
2465 return; 2469 return;
2466 } 2470 }
2467 2471
2468 ScopedRGBEmulationColorMask emulationColorMask(contextGL(), m_colorMask, 2472 ScopedRGBEmulationColorMask emulationColorMask(this, m_colorMask,
2469 m_drawingBuffer.get()); 2473 m_drawingBuffer.get());
2470 clearIfComposited(); 2474 clearIfComposited();
2471 contextGL()->DrawArraysInstancedANGLE(mode, first, count, primcount); 2475 contextGL()->DrawArraysInstancedANGLE(mode, first, count, primcount);
2472 markContextChanged(CanvasChanged); 2476 markContextChanged(CanvasChanged);
2473 } 2477 }
2474 2478
2475 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode, 2479 void WebGLRenderingContextBase::drawElementsInstancedANGLE(GLenum mode,
2476 GLsizei count, 2480 GLsizei count,
2477 GLenum type, 2481 GLenum type,
2478 long long offset, 2482 long long offset,
2479 GLsizei primcount) { 2483 GLsizei primcount) {
2480 if (!validateDrawElements("drawElementsInstancedANGLE", type, offset)) 2484 if (!validateDrawElements("drawElementsInstancedANGLE", type, offset))
2481 return; 2485 return;
2482 2486
2483 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) { 2487 if (!m_boundVertexArrayObject->isAllEnabledAttribBufferBound()) {
2484 synthesizeGLError(GL_INVALID_OPERATION, "drawElementsInstancedANGLE", 2488 synthesizeGLError(GL_INVALID_OPERATION, "drawElementsInstancedANGLE",
2485 "no buffer is bound to enabled attribute"); 2489 "no buffer is bound to enabled attribute");
2486 return; 2490 return;
2487 } 2491 }
2488 2492
2489 ScopedRGBEmulationColorMask emulationColorMask(contextGL(), m_colorMask, 2493 ScopedRGBEmulationColorMask emulationColorMask(this, m_colorMask,
2490 m_drawingBuffer.get()); 2494 m_drawingBuffer.get());
2491 clearIfComposited(); 2495 clearIfComposited();
2492 contextGL()->DrawElementsInstancedANGLE( 2496 contextGL()->DrawElementsInstancedANGLE(
2493 mode, count, type, reinterpret_cast<void*>(static_cast<intptr_t>(offset)), 2497 mode, count, type, reinterpret_cast<void*>(static_cast<intptr_t>(offset)),
2494 primcount); 2498 primcount);
2495 markContextChanged(CanvasChanged); 2499 markContextChanged(CanvasChanged);
2496 } 2500 }
2497 2501
2498 void WebGLRenderingContextBase::enable(GLenum cap) { 2502 void WebGLRenderingContextBase::enable(GLenum cap) {
2499 if (isContextLost() || !validateCapability("enable", cap)) 2503 if (isContextLost() || !validateCapability("enable", cap))
(...skipping 3780 matching lines...) Expand 10 before | Expand all | Expand 10 after
6280 return; 6284 return;
6281 if (m_scissorEnabled) 6285 if (m_scissorEnabled)
6282 contextGL()->Enable(GL_SCISSOR_TEST); 6286 contextGL()->Enable(GL_SCISSOR_TEST);
6283 else 6287 else
6284 contextGL()->Disable(GL_SCISSOR_TEST); 6288 contextGL()->Disable(GL_SCISSOR_TEST);
6285 } 6289 }
6286 6290
6287 void WebGLRenderingContextBase::DrawingBufferClientRestoreMaskAndClearValues() { 6291 void WebGLRenderingContextBase::DrawingBufferClientRestoreMaskAndClearValues() {
6288 if (!contextGL()) 6292 if (!contextGL())
6289 return; 6293 return;
6294 bool colorMaskAlpha =
6295 m_colorMask[3] && m_activeScopedRGBEmulationColorMasks == 0;
6290 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2], 6296 contextGL()->ColorMask(m_colorMask[0], m_colorMask[1], m_colorMask[2],
6291 m_colorMask[3]); 6297 colorMaskAlpha);
6292 contextGL()->DepthMask(m_depthMask); 6298 contextGL()->DepthMask(m_depthMask);
6293 contextGL()->StencilMaskSeparate(GL_FRONT, m_stencilMask); 6299 contextGL()->StencilMaskSeparate(GL_FRONT, m_stencilMask);
6294 6300
6295 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2], 6301 contextGL()->ClearColor(m_clearColor[0], m_clearColor[1], m_clearColor[2],
6296 m_clearColor[3]); 6302 m_clearColor[3]);
6297 contextGL()->ClearDepthf(m_clearDepth); 6303 contextGL()->ClearDepthf(m_clearDepth);
6298 contextGL()->ClearStencil(m_clearStencil); 6304 contextGL()->ClearStencil(m_clearStencil);
6299 } 6305 }
6300 6306
6301 void WebGLRenderingContextBase::DrawingBufferClientRestorePixelPackAlignment() { 6307 void WebGLRenderingContextBase::DrawingBufferClientRestorePixelPackAlignment() {
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
7762 7768
7763 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7769 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7764 HTMLCanvasElementOrOffscreenCanvas& result) const { 7770 HTMLCanvasElementOrOffscreenCanvas& result) const {
7765 if (canvas()) 7771 if (canvas())
7766 result.setHTMLCanvasElement(canvas()); 7772 result.setHTMLCanvasElement(canvas());
7767 else 7773 else
7768 result.setOffscreenCanvas(getOffscreenCanvas()); 7774 result.setOffscreenCanvas(getOffscreenCanvas());
7769 } 7775 }
7770 7776
7771 } // namespace blink 7777 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698