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

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

Issue 1852533002: Remove alpha/depth/stencil/antialias from WGC3D::Attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@premul
Patch Set: 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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 555 }
556 Settings* settings = frame->settings(); 556 Settings* settings = frame->settings();
557 557
558 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in 558 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
559 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension. 559 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
560 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) { 560 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) {
561 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext.")); 561 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
562 return nullptr; 562 return nullptr;
563 } 563 }
564 564
565 WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsContext3DAtt ributes(attributes, document.topDocument().url().getString(), settings, webGLVer sion); 565 WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsContext3DAtt ributes(attributes, document.topDocument().url().getString(), webGLVersion);
566 Platform::GraphicsInfo glInfo; 566 Platform::GraphicsInfo glInfo;
567 glInfo.testFailContext = shouldFailContextCreationForTesting; 567 glInfo.testFailContext = shouldFailContextCreationForTesting;
568 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(wgc3dAttributes, 0, &glInfo)); 568 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(wgc3dAttributes, 0, &glInfo));
569 if (!contextProvider || shouldFailContextCreationForTesting) { 569 if (!contextProvider || shouldFailContextCreationForTesting) {
570 shouldFailContextCreationForTesting = false; 570 shouldFailContextCreationForTesting = false;
571 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo))); 571 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo)));
572 return nullptr; 572 return nullptr;
573 } 573 }
574 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); 574 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
575 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { 575 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 } 873 }
874 874
875 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); 875 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
876 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); 876 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2);
877 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 877 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
878 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 878 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
879 } 879 }
880 880
881 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3DProvider> contextProvider) 881 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3DProvider> contextProvider)
882 { 882 {
883 WebGraphicsContext3D::Attributes attrs;
884 attrs.alpha = m_requestedAttributes.alpha();
885 attrs.depth = m_requestedAttributes.depth();
886 attrs.stencil = m_requestedAttributes.stencil();
887 attrs.antialias = m_requestedAttributes.antialias();
888 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha(); 883 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha();
884 bool wantAlphaChannel = m_requestedAttributes.alpha();
885 bool wantDepthBuffer = m_requestedAttributes.depth();
886 bool wantStencilBuffer = m_requestedAttributes.stencil();
887 bool wantAntialiasing = m_requestedAttributes.antialias();
danakj 2016/03/31 20:27:56 WebGL can still turn off MSAA if the author reques
889 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 888 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
890 return DrawingBuffer::create(contextProvider, clampedCanvasSize(), premultip liedAlpha, preserve, attrs); 889 return DrawingBuffer::create(
890 contextProvider,
891 clampedCanvasSize(),
892 premultipliedAlpha,
893 wantAlphaChannel,
894 wantDepthBuffer,
895 wantStencilBuffer,
896 wantAntialiasing,
897 preserve);
891 } 898 }
892 899
893 void WebGLRenderingContextBase::initializeNewContext() 900 void WebGLRenderingContextBase::initializeNewContext()
894 { 901 {
895 ASSERT(!isContextLost()); 902 ASSERT(!isContextLost());
896 ASSERT(drawingBuffer()); 903 ASSERT(drawingBuffer());
897 904
898 m_markedCanvasDirty = false; 905 m_markedCanvasDirty = false;
899 m_activeTextureUnit = 0; 906 m_activeTextureUnit = 0;
900 m_packAlignment = 4; 907 m_packAlignment = 4;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 int currentArea = width * height; 1299 int currentArea = width * height;
1293 if (currentArea > maxArea) { 1300 if (currentArea > maxArea) {
1294 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits. 1301 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits.
1295 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea)); 1302 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea));
1296 width = std::max(1, static_cast<int>(width * scaleFactor)); 1303 width = std::max(1, static_cast<int>(width * scaleFactor));
1297 height = std::max(1, static_cast<int>(height * scaleFactor)); 1304 height = std::max(1, static_cast<int>(height * scaleFactor));
1298 } 1305 }
1299 1306
1300 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 1307 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
1301 // clear (and this matches what reshape will do). 1308 // clear (and this matches what reshape will do).
1302 drawingBuffer()->reset(IntSize(width, height)); 1309 bool wantAlphaChannel = m_requestedAttributes.alpha();
danakj 2016/03/31 20:27:56 I assume that m_requestedAttributes is still valid
1310 bool wantDepthBuffer = m_requestedAttributes.depth();
1311 bool wantStencilBuffer = m_requestedAttributes.stencil();
1312 drawingBuffer()->reset(IntSize(width, height), wantAlphaChannel, wantDepthBu ffer || wantStencilBuffer);
1303 restoreStateAfterClear(); 1313 restoreStateAfterClear();
1304 1314
1305 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get())); 1315 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get()));
1306 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get())); 1316 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get()));
1307 drawingBuffer()->restoreFramebufferBindings(); 1317 drawingBuffer()->restoreFramebufferBindings();
1308 } 1318 }
1309 1319
1310 int WebGLRenderingContextBase::drawingBufferWidth() const 1320 int WebGLRenderingContextBase::drawingBufferWidth() const
1311 { 1321 {
1312 return isContextLost() ? 0 : drawingBuffer()->size().width(); 1322 return isContextLost() ? 0 : drawingBuffer()->size().width();
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 } 2409 }
2400 } 2410 }
2401 2411
2402 void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttrib utes>& result) 2412 void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttrib utes>& result)
2403 { 2413 {
2404 if (isContextLost()) 2414 if (isContextLost())
2405 return; 2415 return;
2406 result.set(m_requestedAttributes); 2416 result.set(m_requestedAttributes);
2407 // Some requested attributes may not be honored, so we need to query the und erlying 2417 // Some requested attributes may not be honored, so we need to query the und erlying
2408 // context/drawing buffer and adjust accordingly. 2418 // context/drawing buffer and adjust accordingly.
2409 WebGraphicsContext3D::Attributes attrs = drawingBuffer()->getActualAttribute s(); 2419 if (m_requestedAttributes.depth() && !drawingBuffer()->hasDepthBuffer())
2410 if (m_requestedAttributes.depth() && !attrs.depth)
2411 result.get().setDepth(false); 2420 result.get().setDepth(false);
2412 if (m_requestedAttributes.stencil() && !attrs.stencil) 2421 if (m_requestedAttributes.stencil() && !drawingBuffer()->hasStencilBuffer())
2413 result.get().setStencil(false); 2422 result.get().setStencil(false);
2414 result.get().setAntialias(drawingBuffer()->multisample()); 2423 result.get().setAntialias(drawingBuffer()->multisample());
2415 } 2424 }
2416 2425
2417 GLenum WebGLRenderingContextBase::getError() 2426 GLenum WebGLRenderingContextBase::getError()
2418 { 2427 {
2419 if (!m_lostContextErrors.isEmpty()) { 2428 if (!m_lostContextErrors.isEmpty()) {
2420 GLenum error = m_lostContextErrors.first(); 2429 GLenum error = m_lostContextErrors.first();
2421 m_lostContextErrors.remove(0); 2430 m_lostContextErrors.remove(0);
2422 return error; 2431 return error;
(...skipping 3570 matching lines...) Expand 10 before | Expand all | Expand 10 after
5993 6002
5994 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) 6003 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ()))
5995 return; 6004 return;
5996 6005
5997 // If the context was lost due to RealLostContext, we need to destroy the ol d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou gh. 6006 // If the context was lost due to RealLostContext, we need to destroy the ol d DrawingBuffer before creating new DrawingBuffer to ensure resource budget enou gh.
5998 if (drawingBuffer()) { 6007 if (drawingBuffer()) {
5999 m_drawingBuffer->beginDestruction(); 6008 m_drawingBuffer->beginDestruction();
6000 m_drawingBuffer.clear(); 6009 m_drawingBuffer.clear();
6001 } 6010 }
6002 6011
6003 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut es(m_requestedAttributes, canvas()->document().topDocument().url().getString(), settings, version()); 6012 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut es(m_requestedAttributes, canvas()->document().topDocument().url().getString(), version());
6004 Platform::GraphicsInfo glInfo; 6013 Platform::GraphicsInfo glInfo;
6005 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(attributes, 0, &glInfo)); 6014 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(attributes, 0, &glInfo));
6006 RefPtr<DrawingBuffer> buffer; 6015 RefPtr<DrawingBuffer> buffer;
6007 if (contextProvider) { 6016 if (contextProvider) {
6008 // Construct a new drawing buffer with the new WebGraphicsContext3D. 6017 // Construct a new drawing buffer with the new WebGraphicsContext3D.
6009 buffer = createDrawingBuffer(contextProvider.release()); 6018 buffer = createDrawingBuffer(contextProvider.release());
6010 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. 6019 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null.
6011 } 6020 }
6012 if (!buffer) { 6021 if (!buffer) {
6013 if (m_contextLostMode == RealLostContext) { 6022 if (m_contextLostMode == RealLostContext) {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
6344 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6353 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6345 } 6354 }
6346 6355
6347 void WebGLRenderingContextBase::restoreUnpackParameters() 6356 void WebGLRenderingContextBase::restoreUnpackParameters()
6348 { 6357 {
6349 if (m_unpackAlignment != 1) 6358 if (m_unpackAlignment != 1)
6350 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6359 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6351 } 6360 }
6352 6361
6353 } // namespace blink 6362 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698