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

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: rm-alphadepthetc: renamevar 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 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(wgc3dAttributes, 0, &glInfo)); 567 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(wgc3dAttributes, 0, &glInfo));
568 if (!contextProvider || shouldFailContextCreationForTesting) { 568 if (!contextProvider || shouldFailContextCreationForTesting) {
569 shouldFailContextCreationForTesting = false; 569 shouldFailContextCreationForTesting = false;
570 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo))); 570 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, extractWebGLContextCreationError(glInfo)));
571 return nullptr; 571 return nullptr;
572 } 572 }
573 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); 573 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL();
574 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) { 574 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten cil")) {
575 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "OES_packed_depth_stencil support is required.") ); 575 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "OES_packed_depth_stencil support is required.") );
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 } 872 }
873 873
874 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); 874 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
875 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2); 875 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal FormatsES2);
876 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 876 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
877 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 877 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
878 } 878 }
879 879
880 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3DProvider> contextProvider) 880 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3DProvider> contextProvider)
881 { 881 {
882 WebGraphicsContext3D::Attributes attrs;
883 attrs.alpha = m_requestedAttributes.alpha();
884 attrs.depth = m_requestedAttributes.depth();
885 attrs.stencil = m_requestedAttributes.stencil();
886 attrs.antialias = m_requestedAttributes.antialias();
887 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha(); 882 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha();
883 bool wantAlphaChannel = m_requestedAttributes.alpha();
884 bool wantDepthBuffer = m_requestedAttributes.depth();
885 bool wantStencilBuffer = m_requestedAttributes.stencil();
886 bool wantAntialiasing = m_requestedAttributes.antialias();
888 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 887 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
889 return DrawingBuffer::create(contextProvider, clampedCanvasSize(), premultip liedAlpha, preserve, attrs); 888 return DrawingBuffer::create(
889 contextProvider,
890 clampedCanvasSize(),
891 premultipliedAlpha,
892 wantAlphaChannel,
893 wantDepthBuffer,
894 wantStencilBuffer,
895 wantAntialiasing,
896 preserve);
890 } 897 }
891 898
892 void WebGLRenderingContextBase::initializeNewContext() 899 void WebGLRenderingContextBase::initializeNewContext()
893 { 900 {
894 ASSERT(!isContextLost()); 901 ASSERT(!isContextLost());
895 ASSERT(drawingBuffer()); 902 ASSERT(drawingBuffer());
896 903
897 m_markedCanvasDirty = false; 904 m_markedCanvasDirty = false;
898 m_activeTextureUnit = 0; 905 m_activeTextureUnit = 0;
899 m_packAlignment = 4; 906 m_packAlignment = 4;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 int currentArea = width * height; 1298 int currentArea = width * height;
1292 if (currentArea > maxArea) { 1299 if (currentArea > maxArea) {
1293 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits. 1300 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits.
1294 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea)); 1301 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea));
1295 width = std::max(1, static_cast<int>(width * scaleFactor)); 1302 width = std::max(1, static_cast<int>(width * scaleFactor));
1296 height = std::max(1, static_cast<int>(height * scaleFactor)); 1303 height = std::max(1, static_cast<int>(height * scaleFactor));
1297 } 1304 }
1298 1305
1299 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 1306 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
1300 // clear (and this matches what reshape will do). 1307 // clear (and this matches what reshape will do).
1301 drawingBuffer()->reset(IntSize(width, height)); 1308 bool wantDepthOrStencilBuffer = m_requestedAttributes.depth() || m_requested Attributes.stencil();
1309 drawingBuffer()->reset(IntSize(width, height), wantDepthOrStencilBuffer);
1302 restoreStateAfterClear(); 1310 restoreStateAfterClear();
1303 1311
1304 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get())); 1312 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get()));
1305 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get())); 1313 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get()));
1306 drawingBuffer()->restoreFramebufferBindings(); 1314 drawingBuffer()->restoreFramebufferBindings();
1307 } 1315 }
1308 1316
1309 int WebGLRenderingContextBase::drawingBufferWidth() const 1317 int WebGLRenderingContextBase::drawingBufferWidth() const
1310 { 1318 {
1311 return isContextLost() ? 0 : drawingBuffer()->size().width(); 1319 return isContextLost() ? 0 : drawingBuffer()->size().width();
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 } 2406 }
2399 } 2407 }
2400 2408
2401 void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttrib utes>& result) 2409 void WebGLRenderingContextBase::getContextAttributes(Nullable<WebGLContextAttrib utes>& result)
2402 { 2410 {
2403 if (isContextLost()) 2411 if (isContextLost())
2404 return; 2412 return;
2405 result.set(m_requestedAttributes); 2413 result.set(m_requestedAttributes);
2406 // Some requested attributes may not be honored, so we need to query the und erlying 2414 // Some requested attributes may not be honored, so we need to query the und erlying
2407 // context/drawing buffer and adjust accordingly. 2415 // context/drawing buffer and adjust accordingly.
2408 WebGraphicsContext3D::Attributes attrs = drawingBuffer()->getActualAttribute s(); 2416 if (m_requestedAttributes.depth() && !drawingBuffer()->hasDepthBuffer())
2409 if (m_requestedAttributes.depth() && !attrs.depth)
2410 result.get().setDepth(false); 2417 result.get().setDepth(false);
2411 if (m_requestedAttributes.stencil() && !attrs.stencil) 2418 if (m_requestedAttributes.stencil() && !drawingBuffer()->hasStencilBuffer())
2412 result.get().setStencil(false); 2419 result.get().setStencil(false);
2413 result.get().setAntialias(drawingBuffer()->multisample()); 2420 result.get().setAntialias(drawingBuffer()->multisample());
2414 } 2421 }
2415 2422
2416 GLenum WebGLRenderingContextBase::getError() 2423 GLenum WebGLRenderingContextBase::getError()
2417 { 2424 {
2418 if (!m_lostContextErrors.isEmpty()) { 2425 if (!m_lostContextErrors.isEmpty()) {
2419 GLenum error = m_lostContextErrors.first(); 2426 GLenum error = m_lostContextErrors.first();
2420 m_lostContextErrors.remove(0); 2427 m_lostContextErrors.remove(0);
2421 return error; 2428 return error;
(...skipping 3570 matching lines...) Expand 10 before | Expand all | Expand 10 after
5992 5999
5993 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) 6000 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ()))
5994 return; 6001 return;
5995 6002
5996 // 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. 6003 // 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.
5997 if (drawingBuffer()) { 6004 if (drawingBuffer()) {
5998 m_drawingBuffer->beginDestruction(); 6005 m_drawingBuffer->beginDestruction();
5999 m_drawingBuffer.clear(); 6006 m_drawingBuffer.clear();
6000 } 6007 }
6001 6008
6002 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut es(m_requestedAttributes, canvas()->document().topDocument().url().getString(), settings, version()); 6009 WebGraphicsContext3D::Attributes attributes = toWebGraphicsContext3DAttribut es(m_requestedAttributes, canvas()->document().topDocument().url().getString(), version());
6003 Platform::GraphicsInfo glInfo; 6010 Platform::GraphicsInfo glInfo;
6004 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(attributes, 0, &glInfo)); 6011 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider(attributes, 0, &glInfo));
6005 RefPtr<DrawingBuffer> buffer; 6012 RefPtr<DrawingBuffer> buffer;
6006 if (contextProvider) { 6013 if (contextProvider) {
6007 // Construct a new drawing buffer with the new WebGraphicsContext3D. 6014 // Construct a new drawing buffer with the new WebGraphicsContext3D.
6008 buffer = createDrawingBuffer(contextProvider.release()); 6015 buffer = createDrawingBuffer(contextProvider.release());
6009 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. 6016 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null.
6010 } 6017 }
6011 if (!buffer) { 6018 if (!buffer) {
6012 if (m_contextLostMode == RealLostContext) { 6019 if (m_contextLostMode == RealLostContext) {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
6343 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6350 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6344 } 6351 }
6345 6352
6346 void WebGLRenderingContextBase::restoreUnpackParameters() 6353 void WebGLRenderingContextBase::restoreUnpackParameters()
6347 { 6354 {
6348 if (m_unpackAlignment != 1) 6355 if (m_unpackAlignment != 1)
6349 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6356 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6350 } 6357 }
6351 6358
6352 } // namespace blink 6359 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698