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

Side by Side Diff: Source/core/html/canvas/WebGLRenderingContext.cpp

Issue 169933002: WebGL: Don't destroy mailbox textures in the destructor until they're released. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context.")); 519 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Could not create a WebGL context."));
520 return nullptr; 520 return nullptr;
521 } 521 }
522 522
523 return renderingContext.release(); 523 return renderingContext.release();
524 } 524 }
525 525
526 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requested Attributes) 526 WebGLRenderingContext::WebGLRenderingContext(HTMLCanvasElement* passedCanvas, Pa ssOwnPtr<blink::WebGraphicsContext3D> context, WebGLContextAttributes* requested Attributes)
527 : CanvasRenderingContext(passedCanvas) 527 : CanvasRenderingContext(passedCanvas)
528 , ActiveDOMObject(&passedCanvas->document()) 528 , ActiveDOMObject(&passedCanvas->document())
529 , m_context(context) 529 , m_context(context.get())
530 , m_drawingBuffer(0) 530 , m_drawingBuffer(0)
531 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent) 531 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContext::dispatchCont extLostEvent)
532 , m_restoreAllowed(false) 532 , m_restoreAllowed(false)
533 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext) 533 , m_restoreTimer(this, &WebGLRenderingContext::maybeRestoreContext)
534 , m_generatedImageCache(4) 534 , m_generatedImageCache(4)
535 , m_contextLost(false) 535 , m_contextLost(false)
536 , m_contextLostMode(SyntheticLostContext) 536 , m_contextLostMode(SyntheticLostContext)
537 , m_requestedAttributes(requestedAttributes->clone()) 537 , m_requestedAttributes(requestedAttributes->clone())
538 , m_synthesizedErrorsToConsole(true) 538 , m_synthesizedErrorsToConsole(true)
539 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole) 539 , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
540 , m_multisamplingAllowed(false) 540 , m_multisamplingAllowed(false)
541 , m_multisamplingObserverRegistered(false) 541 , m_multisamplingObserverRegistered(false)
542 , m_onePlusMaxEnabledAttribIndex(0) 542 , m_onePlusMaxEnabledAttribIndex(0)
543 , m_onePlusMaxNonDefaultTextureUnit(0) 543 , m_onePlusMaxNonDefaultTextureUnit(0)
544 { 544 {
545 ASSERT(m_context); 545 ASSERT(m_context);
546 ScriptWrappable::init(this); 546 ScriptWrappable::init(this);
547 547
548 m_contextGroup = WebGLContextGroup::create(); 548 m_contextGroup = WebGLContextGroup::create();
549 m_contextGroup->addContext(this); 549 m_contextGroup->addContext(this);
550 550
551 m_maxViewportDims[0] = m_maxViewportDims[1] = 0; 551 m_maxViewportDims[0] = m_maxViewportDims[1] = 0;
552 m_context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims); 552 m_context->getIntegerv(GL_MAX_VIEWPORT_DIMS, m_maxViewportDims);
553 553
554 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager()); 554 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = adoptR ef(new WebGLRenderingContextEvictionManager());
555 555
556 // Create the DrawingBuffer and initialize the platform layer. 556 // Create the DrawingBuffer and initialize the platform layer.
557 DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 557 DrawingBuffer::PreserveDrawingBuffer preserve = requestedAttributes->preserv eDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
558 m_drawingBuffer = DrawingBuffer::create(m_context.get(), clampedCanvasSize() , preserve, contextEvictionManager.release()); 558 m_drawingBuffer = DrawingBuffer::create(context, clampedCanvasSize(), preser ve, contextEvictionManager.release());
559 if (!m_drawingBuffer) 559 if (!m_drawingBuffer)
560 return; 560 return;
561 561
562 m_drawingBuffer->bind(); 562 m_drawingBuffer->bind();
563 setupFlags(); 563 setupFlags();
564 initializeNewContext(); 564 initializeNewContext();
565 565
566 // Register extensions. 566 // Register extensions.
567 static const char* const webkitPrefix[] = { "WEBKIT_", 0, }; 567 static const char* const webkitPrefix[] = { "WEBKIT_", 0, };
568 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, }; 568 static const char* const bothPrefixes[] = { "", "WEBKIT_", 0, };
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 } 753 }
754 754
755 void WebGLRenderingContext::destroyContext() 755 void WebGLRenderingContext::destroyContext()
756 { 756 {
757 m_contextLost = true; 757 m_contextLost = true;
758 758
759 if (!m_context) { 759 if (!m_context) {
760 ASSERT(!m_drawingBuffer); 760 ASSERT(!m_drawingBuffer);
761 return; 761 return;
762 } 762 }
763 // The drawing buffer holds a context reference. It must also be destroyed
764 // in order for the context to be released.
765 ASSERT(m_drawingBuffer);
766 m_drawingBuffer.clear();
767 763
768 m_extensionsUtil.clear(); 764 m_extensionsUtil.clear();
769 765
770 m_context->setContextLostCallback(0); 766 m_context->setContextLostCallback(0);
771 m_context->setErrorMessageCallback(0); 767 m_context->setErrorMessageCallback(0);
772 m_context.clear(); 768 m_context = 0;
769
770 ASSERT(m_drawingBuffer);
771 m_drawingBuffer->releaseResources();
772 m_drawingBuffer.clear();
773 } 773 }
774 774
775 void WebGLRenderingContext::markContextChanged() 775 void WebGLRenderingContext::markContextChanged()
776 { 776 {
777 if (m_framebufferBinding || isContextLost()) 777 if (m_framebufferBinding || isContextLost())
778 return; 778 return;
779 779
780 m_drawingBuffer->markContentsChanged(); 780 m_drawingBuffer->markContentsChanged();
781 781
782 m_layerCleared = false; 782 m_layerCleared = false;
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1307
1308 void WebGLRenderingContext::clear(GLbitfield mask) 1308 void WebGLRenderingContext::clear(GLbitfield mask)
1309 { 1309 {
1310 if (isContextLost()) 1310 if (isContextLost())
1311 return; 1311 return;
1312 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) { 1312 if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_B IT)) {
1313 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask"); 1313 synthesizeGLError(GL_INVALID_VALUE, "clear", "invalid mask");
1314 return; 1314 return;
1315 } 1315 }
1316 const char* reason = "framebuffer incomplete"; 1316 const char* reason = "framebuffer incomplete";
1317 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1317 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reas on)) {
1318 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason); 1318 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "clear", reason);
1319 return; 1319 return;
1320 } 1320 }
1321 if (!clearIfComposited(mask)) 1321 if (!clearIfComposited(mask))
1322 m_context->clear(mask); 1322 m_context->clear(mask);
1323 markContextChanged(); 1323 markContextChanged();
1324 } 1324 }
1325 1325
1326 void WebGLRenderingContext::clearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) 1326 void WebGLRenderingContext::clearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
1327 { 1327 {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 return; 1461 return;
1462 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { 1462 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) {
1463 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "framebuffer i s incompatible format"); 1463 synthesizeGLError(GL_INVALID_OPERATION, "copyTexImage2D", "framebuffer i s incompatible format");
1464 return; 1464 return;
1465 } 1465 }
1466 if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) { 1466 if (!isGLES2NPOTStrict() && level && WebGLTexture::isNPOT(width, height)) {
1467 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2"); 1467 synthesizeGLError(GL_INVALID_VALUE, "copyTexImage2D", "level > 0 not pow er of 2");
1468 return; 1468 return;
1469 } 1469 }
1470 const char* reason = "framebuffer incomplete"; 1470 const char* reason = "framebuffer incomplete";
1471 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1471 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reas on)) {
1472 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason); 1472 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexImage2D", re ason);
1473 return; 1473 return;
1474 } 1474 }
1475 clearIfComposited(); 1475 clearIfComposited();
1476 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1476 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1477 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border); 1477 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height , border);
1478 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted. 1478 // FIXME: if the framebuffer is not complete, none of the below should be ex ecuted.
1479 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE); 1479 tex->setLevelInfo(target, level, internalformat, width, height, GL_UNSIGNED_ BYTE);
1480 } 1480 }
1481 1481
(...skipping 22 matching lines...) Expand all
1504 return; 1504 return;
1505 } 1505 }
1506 GLenum internalformat = tex->getInternalFormat(target, level); 1506 GLenum internalformat = tex->getInternalFormat(target, level);
1507 if (!validateSettableTexFormat("copyTexSubImage2D", internalformat)) 1507 if (!validateSettableTexFormat("copyTexSubImage2D", internalformat))
1508 return; 1508 return;
1509 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) { 1509 if (!isTexInternalFormatColorBufferCombinationValid(internalformat, boundFra mebufferColorFormat())) {
1510 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format"); 1510 synthesizeGLError(GL_INVALID_OPERATION, "copyTexSubImage2D", "framebuffe r is incompatible format");
1511 return; 1511 return;
1512 } 1512 }
1513 const char* reason = "framebuffer incomplete"; 1513 const char* reason = "framebuffer incomplete";
1514 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 1514 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reas on)) {
1515 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason); 1515 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "copyTexSubImage2D", reason);
1516 return; 1516 return;
1517 } 1517 }
1518 clearIfComposited(); 1518 clearIfComposited();
1519 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get()); 1519 ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding .get());
1520 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight); 1520 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, h eight);
1521 } 1521 }
1522 1522
1523 PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer() 1523 PassRefPtr<WebGLBuffer> WebGLRenderingContext::createBuffer()
1524 { 1524 {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 { 1611 {
1612 if (isContextLost() || !object) 1612 if (isContextLost() || !object)
1613 return false; 1613 return false;
1614 if (!object->validate(contextGroup(), this)) { 1614 if (!object->validate(contextGroup(), this)) {
1615 synthesizeGLError(GL_INVALID_OPERATION, "delete", "object does not belon g to this context"); 1615 synthesizeGLError(GL_INVALID_OPERATION, "delete", "object does not belon g to this context");
1616 return false; 1616 return false;
1617 } 1617 }
1618 if (object->object()) { 1618 if (object->object()) {
1619 // We need to pass in context here because we want 1619 // We need to pass in context here because we want
1620 // things in this context unbound. 1620 // things in this context unbound.
1621 object->deleteObject(m_context.get()); 1621 object->deleteObject(m_context);
1622 } 1622 }
1623 return true; 1623 return true;
1624 } 1624 }
1625 1625
1626 void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer) 1626 void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer)
1627 { 1627 {
1628 if (!deleteObject(buffer)) 1628 if (!deleteObject(buffer))
1629 return; 1629 return;
1630 if (m_boundArrayBuffer == buffer) 1630 if (m_boundArrayBuffer == buffer)
1631 m_boundArrayBuffer = 0; 1631 m_boundArrayBuffer = 0;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1724
1725 void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha der) 1725 void WebGLRenderingContext::detachShader(WebGLProgram* program, WebGLShader* sha der)
1726 { 1726 {
1727 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader)) 1727 if (isContextLost() || !validateWebGLObject("detachShader", program) || !val idateWebGLObject("detachShader", shader))
1728 return; 1728 return;
1729 if (!program->detachShader(shader)) { 1729 if (!program->detachShader(shader)) {
1730 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched"); 1730 synthesizeGLError(GL_INVALID_OPERATION, "detachShader", "shader not atta ched");
1731 return; 1731 return;
1732 } 1732 }
1733 m_context->detachShader(objectOrZero(program), objectOrZero(shader)); 1733 m_context->detachShader(objectOrZero(program), objectOrZero(shader));
1734 shader->onDetached(m_context.get()); 1734 shader->onDetached(m_context);
1735 } 1735 }
1736 1736
1737 void WebGLRenderingContext::disable(GLenum cap) 1737 void WebGLRenderingContext::disable(GLenum cap)
1738 { 1738 {
1739 if (isContextLost() || !validateCapability("disable", cap)) 1739 if (isContextLost() || !validateCapability("disable", cap))
1740 return; 1740 return;
1741 if (cap == GL_STENCIL_TEST) { 1741 if (cap == GL_STENCIL_TEST) {
1742 m_stencilEnabled = false; 1742 m_stencilEnabled = false;
1743 applyStencilTest(); 1743 applyStencilTest();
1744 return; 1744 return;
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 if (format != GL_RGBA || type != GL_UNSIGNED_BYTE) { 3065 if (format != GL_RGBA || type != GL_UNSIGNED_BYTE) {
3066 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "format not RGBA o r type not UNSIGNED_BYTE"); 3066 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "format not RGBA o r type not UNSIGNED_BYTE");
3067 return; 3067 return;
3068 } 3068 }
3069 // Validate array type against pixel type. 3069 // Validate array type against pixel type.
3070 if (pixels->type() != ArrayBufferView::TypeUint8) { 3070 if (pixels->type() != ArrayBufferView::TypeUint8) {
3071 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot Uint8Array"); 3071 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot Uint8Array");
3072 return; 3072 return;
3073 } 3073 }
3074 const char* reason = "framebuffer incomplete"; 3074 const char* reason = "framebuffer incomplete";
3075 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 3075 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reas on)) {
3076 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "readPixels", reason ); 3076 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, "readPixels", reason );
3077 return; 3077 return;
3078 } 3078 }
3079 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 3079 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3080 unsigned totalBytesRequired = 0; 3080 unsigned totalBytesRequired = 0;
3081 unsigned padding = 0; 3081 unsigned padding = 0;
3082 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); 3082 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding);
3083 if (error != GL_NO_ERROR) { 3083 if (error != GL_NO_ERROR) {
3084 synthesizeGLError(error, "readPixels", "invalid dimensions"); 3084 synthesizeGLError(error, "readPixels", "invalid dimensions");
3085 return; 3085 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 return; 3129 return;
3130 switch (internalformat) { 3130 switch (internalformat) {
3131 case GL_DEPTH_COMPONENT16: 3131 case GL_DEPTH_COMPONENT16:
3132 case GL_RGBA4: 3132 case GL_RGBA4:
3133 case GL_RGB5_A1: 3133 case GL_RGB5_A1:
3134 case GL_RGB565: 3134 case GL_RGB565:
3135 case GL_STENCIL_INDEX8: 3135 case GL_STENCIL_INDEX8:
3136 m_context->renderbufferStorage(target, internalformat, width, height); 3136 m_context->renderbufferStorage(target, internalformat, width, height);
3137 m_renderbufferBinding->setInternalFormat(internalformat); 3137 m_renderbufferBinding->setInternalFormat(internalformat);
3138 m_renderbufferBinding->setSize(width, height); 3138 m_renderbufferBinding->setSize(width, height);
3139 m_renderbufferBinding->deleteEmulatedStencilBuffer(m_context.get()); 3139 m_renderbufferBinding->deleteEmulatedStencilBuffer(m_context);
3140 break; 3140 break;
3141 case GL_DEPTH_STENCIL_OES: 3141 case GL_DEPTH_STENCIL_OES:
3142 if (isDepthStencilSupported()) { 3142 if (isDepthStencilSupported()) {
3143 m_context->renderbufferStorage(target, GL_DEPTH24_STENCIL8_OES, widt h, height); 3143 m_context->renderbufferStorage(target, GL_DEPTH24_STENCIL8_OES, widt h, height);
3144 } else { 3144 } else {
3145 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(target, m_renderbufferBinding.get()); 3145 WebGLRenderbuffer* emulatedStencilBuffer = ensureEmulatedStencilBuff er(target, m_renderbufferBinding.get());
3146 if (!emulatedStencilBuffer) { 3146 if (!emulatedStencilBuffer) {
3147 synthesizeGLError(GL_OUT_OF_MEMORY, "renderbufferStorage", "out of memory"); 3147 synthesizeGLError(GL_OUT_OF_MEMORY, "renderbufferStorage", "out of memory");
3148 return; 3148 return;
3149 } 3149 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3458 { 3458 {
3459 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo rmat, type, 0, 0)) 3459 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo rmat, type, 0, 0))
3460 return; 3460 return;
3461 3461
3462 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3462 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3463 // If possible, copy from the canvas element directly to the texture 3463 // If possible, copy from the canvas element directly to the texture
3464 // via the GPU, without a read-back to system memory. 3464 // via the GPU, without a read-back to system memory.
3465 if (GL_TEXTURE_2D == target && texture) { 3465 if (GL_TEXTURE_2D == target && texture) {
3466 if (!canvas->is3D()) { 3466 if (!canvas->is3D()) {
3467 ImageBuffer* buffer = canvas->buffer(); 3467 ImageBuffer* buffer = canvas->buffer();
3468 if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture ->object(), internalformat, type, 3468 if (buffer && buffer->copyToPlatformTexture(m_context, texture->obje ct(), internalformat, type,
3469 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3469 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3470 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3470 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3471 return; 3471 return;
3472 } 3472 }
3473 } else { 3473 } else {
3474 WebGLRenderingContext* gl = toWebGLRenderingContext(canvas->renderin gContext()); 3474 WebGLRenderingContext* gl = toWebGLRenderingContext(canvas->renderin gContext());
3475 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get() , texture->object(), internalformat, type, 3475 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context, text ure->object(), internalformat, type,
3476 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3476 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3477 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3477 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3478 return; 3478 return;
3479 } 3479 }
3480 } 3480 }
3481 } 3481 }
3482 3482
3483 RefPtr<ImageData> imageData = canvas->getImageData(); 3483 RefPtr<ImageData> imageData = canvas->getImageData();
3484 if (imageData) 3484 if (imageData)
3485 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState); 3485 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState);
(...skipping 19 matching lines...) Expand all
3505 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 3505 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
3506 { 3506 {
3507 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState) 3507 if (isContextLost() || !validateHTMLVideoElement("texImage2D", video, except ionState)
3508 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0)) 3508 || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLVideoEleme nt, target, level, internalformat, video->videoWidth(), video->videoHeight(), 0, format, type, 0, 0))
3509 return; 3509 return;
3510 3510
3511 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible. 3511 // Go through the fast path doing a GPU-GPU textures copy without a readback to system memory if possible.
3512 // Otherwise, it will fall back to the normal SW path. 3512 // Otherwise, it will fall back to the normal SW path.
3513 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 3513 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
3514 if (GL_TEXTURE_2D == target && texture) { 3514 if (GL_TEXTURE_2D == target && texture) {
3515 if (video->copyVideoTextureToPlatformTexture(m_context.get(), texture->o bject(), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 3515 if (video->copyVideoTextureToPlatformTexture(m_context, texture->object( ), level, type, internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
3516 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type); 3516 texture->setLevelInfo(target, level, internalformat, video->videoWid th(), video->videoHeight(), type);
3517 return; 3517 return;
3518 } 3518 }
3519 } 3519 }
3520 3520
3521 // Normal pure SW path. 3521 // Normal pure SW path.
3522 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3522 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
3523 if (!image) 3523 if (!image)
3524 return; 3524 return;
3525 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, except ionState); 3525 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha, except ionState);
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
3999 if (!checkObjectToBeBound("useProgram", program, deleted)) 3999 if (!checkObjectToBeBound("useProgram", program, deleted))
4000 return; 4000 return;
4001 if (deleted) 4001 if (deleted)
4002 program = 0; 4002 program = 0;
4003 if (program && !program->linkStatus()) { 4003 if (program && !program->linkStatus()) {
4004 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid "); 4004 synthesizeGLError(GL_INVALID_OPERATION, "useProgram", "program not valid ");
4005 return; 4005 return;
4006 } 4006 }
4007 if (m_currentProgram != program) { 4007 if (m_currentProgram != program) {
4008 if (m_currentProgram) 4008 if (m_currentProgram)
4009 m_currentProgram->onDetached(m_context.get()); 4009 m_currentProgram->onDetached(m_context);
4010 m_currentProgram = program; 4010 m_currentProgram = program;
4011 m_context->useProgram(objectOrZero(program)); 4011 m_context->useProgram(objectOrZero(program));
4012 if (program) 4012 if (program)
4013 program->onAttached(); 4013 program->onAttached();
4014 } 4014 }
4015 } 4015 }
4016 4016
4017 void WebGLRenderingContext::validateProgram(WebGLProgram* program) 4017 void WebGLRenderingContext::validateProgram(WebGLProgram* program)
4018 { 4018 {
4019 if (isContextLost() || !validateWebGLObject("validateProgram", program)) 4019 if (isContextLost() || !validateWebGLObject("validateProgram", program))
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
4219 } 4219 }
4220 4220
4221 blink::WebLayer* WebGLRenderingContext::platformLayer() const 4221 blink::WebLayer* WebGLRenderingContext::platformLayer() const
4222 { 4222 {
4223 return isContextLost() ? 0 : m_drawingBuffer->platformLayer(); 4223 return isContextLost() ? 0 : m_drawingBuffer->platformLayer();
4224 } 4224 }
4225 4225
4226 Extensions3DUtil* WebGLRenderingContext::extensionsUtil() 4226 Extensions3DUtil* WebGLRenderingContext::extensionsUtil()
4227 { 4227 {
4228 if (!m_extensionsUtil) 4228 if (!m_extensionsUtil)
4229 m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context.get())); 4229 m_extensionsUtil = adoptPtr(new Extensions3DUtil(m_context));
4230 return m_extensionsUtil.get(); 4230 return m_extensionsUtil.get();
4231 } 4231 }
4232 4232
4233 void WebGLRenderingContext::removeSharedObject(WebGLSharedObject* object) 4233 void WebGLRenderingContext::removeSharedObject(WebGLSharedObject* object)
4234 { 4234 {
4235 m_contextGroup->removeObject(object); 4235 m_contextGroup->removeObject(object);
4236 } 4236 }
4237 4237
4238 void WebGLRenderingContext::addSharedObject(WebGLSharedObject* object) 4238 void WebGLRenderingContext::addSharedObject(WebGLSharedObject* object)
4239 { 4239 {
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
5208 if (!count) { 5208 if (!count) {
5209 markContextChanged(); 5209 markContextChanged();
5210 return false; 5210 return false;
5211 } 5211 }
5212 5212
5213 if (!validateRenderingState(functionName)) { 5213 if (!validateRenderingState(functionName)) {
5214 return false; 5214 return false;
5215 } 5215 }
5216 5216
5217 const char* reason = "framebuffer incomplete"; 5217 const char* reason = "framebuffer incomplete";
5218 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 5218 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reas on)) {
5219 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason ); 5219 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason );
5220 return false; 5220 return false;
5221 } 5221 }
5222 5222
5223 return true; 5223 return true;
5224 } 5224 }
5225 5225
5226 bool WebGLRenderingContext::validateDrawElements(const char* functionName, GLenu m mode, GLsizei count, GLenum type, long long offset) 5226 bool WebGLRenderingContext::validateDrawElements(const char* functionName, GLenu m mode, GLsizei count, GLenum type, long long offset)
5227 { 5227 {
5228 if (isContextLost() || !validateDrawMode(functionName, mode)) 5228 if (isContextLost() || !validateDrawMode(functionName, mode))
(...skipping 29 matching lines...) Expand all
5258 if (!m_boundVertexArrayObject->boundElementArrayBuffer()) { 5258 if (!m_boundVertexArrayObject->boundElementArrayBuffer()) {
5259 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no ELEMENT_ARRAY_ BUFFER bound"); 5259 synthesizeGLError(GL_INVALID_OPERATION, functionName, "no ELEMENT_ARRAY_ BUFFER bound");
5260 return false; 5260 return false;
5261 } 5261 }
5262 5262
5263 if (!validateRenderingState(functionName)) { 5263 if (!validateRenderingState(functionName)) {
5264 return false; 5264 return false;
5265 } 5265 }
5266 5266
5267 const char* reason = "framebuffer incomplete"; 5267 const char* reason = "framebuffer incomplete";
5268 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context.get(), &reason)) { 5268 if (m_framebufferBinding && !m_framebufferBinding->onAccess(m_context, &reas on)) {
5269 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason ); 5269 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason );
5270 return false; 5270 return false;
5271 } 5271 }
5272 5272
5273 return true; 5273 return true;
5274 } 5274 }
5275 5275
5276 // Helper function to validate draw*Instanced calls 5276 // Helper function to validate draw*Instanced calls
5277 bool WebGLRenderingContext::validateDrawInstanced(const char* functionName, GLsi zei primcount) 5277 bool WebGLRenderingContext::validateDrawInstanced(const char* functionName, GLsi zei primcount)
5278 { 5278 {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
5398 return; 5398 return;
5399 5399
5400 Settings* settings = frame->settings(); 5400 Settings* settings = frame->settings();
5401 5401
5402 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) 5402 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ()))
5403 return; 5403 return;
5404 5404
5405 blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes-> attributes(canvas()->document().topDocument()->url().string(), settings); 5405 blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes-> attributes(canvas()->document().topDocument()->url().string(), settings);
5406 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes)); 5406 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(attributes));
5407 5407
5408 ASSERT(!m_drawingBuffer);
5408 if (context) { 5409 if (context) {
5409 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = ad optRef(new WebGLRenderingContextEvictionManager()); 5410 RefPtr<WebGLRenderingContextEvictionManager> contextEvictionManager = ad optRef(new WebGLRenderingContextEvictionManager());
5410 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes->p reserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; 5411 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes->p reserveDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard;
5411 m_drawingBuffer = DrawingBuffer::create(context.get(), clampedCanvasSize (), preserve, contextEvictionManager.release()); 5412 m_drawingBuffer = DrawingBuffer::create(context.release(), clampedCanvas Size(), preserve, contextEvictionManager.release());
5412 } 5413 }
5413 5414
5414 bool failToRestore = !context || !m_drawingBuffer; 5415 bool failToRestore = !m_drawingBuffer;
5415 if (failToRestore) { 5416 if (failToRestore) {
5416 if (m_contextLostMode == RealLostContext) { 5417 if (m_contextLostMode == RealLostContext) {
5417 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts); 5418 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts);
5418 } else { 5419 } else {
5419 // This likely shouldn't happen but is the best way to report it to the WebGL app. 5420 // This likely shouldn't happen but is the best way to report it to the WebGL app.
5420 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context "); 5421 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context ");
5421 } 5422 }
5422 return; 5423 return;
5423 } 5424 }
5424 5425
5425 m_drawingBuffer->bind(); 5426 m_drawingBuffer->bind();
5426 5427
5427 m_lostContextErrors.clear(); 5428 m_lostContextErrors.clear();
5428 5429
5429 m_context = context.release(); 5430 m_context = m_drawingBuffer->context();
5430 m_contextLost = false; 5431 m_contextLost = false;
5431 5432
5432 setupFlags(); 5433 setupFlags();
5433 initializeNewContext(); 5434 initializeNewContext();
5434 canvas()->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglconte xtrestored, false, true, "")); 5435 canvas()->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglconte xtrestored, false, true, ""));
5435 } 5436 }
5436 5437
5437 String WebGLRenderingContext::ensureNotNull(const String& text) const 5438 String WebGLRenderingContext::ensureNotNull(const String& text) const
5438 { 5439 {
5439 if (text.isNull()) 5440 if (text.isNull())
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
5621 if (m_textureUnits[i].m_texture2DBinding 5622 if (m_textureUnits[i].m_texture2DBinding
5622 || m_textureUnits[i].m_textureCubeMapBinding) { 5623 || m_textureUnits[i].m_textureCubeMapBinding) {
5623 m_onePlusMaxNonDefaultTextureUnit = i + 1; 5624 m_onePlusMaxNonDefaultTextureUnit = i + 1;
5624 return; 5625 return;
5625 } 5626 }
5626 } 5627 }
5627 m_onePlusMaxNonDefaultTextureUnit = 0; 5628 m_onePlusMaxNonDefaultTextureUnit = 0;
5628 } 5629 }
5629 5630
5630 } // namespace WebCore 5631 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698