OLD | NEW |
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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 448 } |
449 | 449 |
450 // Swallow all other characters. Unclear whether we may | 450 // Swallow all other characters. Unclear whether we may |
451 // want or need to just emit a space per character to try | 451 // want or need to just emit a space per character to try |
452 // to preserve column numbers for debugging purposes. | 452 // to preserve column numbers for debugging purposes. |
453 break; | 453 break; |
454 } | 454 } |
455 } | 455 } |
456 } // namespace anonymous | 456 } // namespace anonymous |
457 | 457 |
| 458 class ScopedTexture2DRestorer { |
| 459 public: |
| 460 ScopedTexture2DRestorer(WebGLRenderingContextBase* context) |
| 461 : m_context(context) |
| 462 { |
| 463 } |
| 464 |
| 465 ~ScopedTexture2DRestorer() |
| 466 { |
| 467 m_context->restoreCurrentTexture2D(); |
| 468 } |
| 469 |
| 470 private: |
| 471 WebGLRenderingContextBase* m_context; |
| 472 }; |
| 473 |
458 class WebGLRenderingContextLostCallback : public blink::WebGraphicsContext3D::We
bGraphicsContextLostCallback { | 474 class WebGLRenderingContextLostCallback : public blink::WebGraphicsContext3D::We
bGraphicsContextLostCallback { |
459 WTF_MAKE_FAST_ALLOCATED; | 475 WTF_MAKE_FAST_ALLOCATED; |
460 public: | 476 public: |
461 explicit WebGLRenderingContextLostCallback(WebGLRenderingContextBase* cb) :
m_context(cb) { } | 477 explicit WebGLRenderingContextLostCallback(WebGLRenderingContextBase* cb) :
m_context(cb) { } |
462 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon
textBase::RealLostContext); } | 478 virtual void onContextLost() { m_context->forceLostContext(WebGLRenderingCon
textBase::RealLostContext); } |
463 virtual ~WebGLRenderingContextLostCallback() {} | 479 virtual ~WebGLRenderingContextLostCallback() {} |
464 private: | 480 private: |
465 WebGLRenderingContextBase* m_context; | 481 WebGLRenderingContextBase* m_context; |
466 }; | 482 }; |
467 | 483 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } else | 840 } else |
825 canvas()->clearPresentationCopy(); | 841 canvas()->clearPresentationCopy(); |
826 clearIfComposited(); | 842 clearIfComposited(); |
827 | 843 |
828 if (!m_markedCanvasDirty && !m_layerCleared) | 844 if (!m_markedCanvasDirty && !m_layerCleared) |
829 return; | 845 return; |
830 | 846 |
831 canvas()->clearCopiedImage(); | 847 canvas()->clearCopiedImage(); |
832 m_markedCanvasDirty = false; | 848 m_markedCanvasDirty = false; |
833 | 849 |
| 850 ScopedTexture2DRestorer restorer(this); |
| 851 |
834 m_drawingBuffer->commit(); | 852 m_drawingBuffer->commit(); |
835 if (!(canvas()->buffer())->copyRenderingResultsFromDrawingBuffer(m_drawingBu
ffer.get())) { | 853 if (!(canvas()->buffer())->copyRenderingResultsFromDrawingBuffer(m_drawingBu
ffer.get())) { |
836 canvas()->ensureUnacceleratedImageBuffer(); | 854 canvas()->ensureUnacceleratedImageBuffer(); |
837 if (canvas()->hasImageBuffer()) | 855 if (canvas()->hasImageBuffer()) |
838 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer()); | 856 m_drawingBuffer->paintRenderingResultsToCanvas(canvas()->buffer()); |
839 } | 857 } |
840 | 858 |
841 if (m_framebufferBinding) | 859 if (m_framebufferBinding) |
842 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin
ding.get())); | 860 m_context->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebufferBin
ding.get())); |
843 else | 861 else |
(...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3399 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g
et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph
a, exceptionState); | 3417 texImage2DImpl(target, level, internalformat, format, type, imageForRender.g
et(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultiplyAlph
a, exceptionState); |
3400 } | 3418 } |
3401 | 3419 |
3402 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
ternalformat, | 3420 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLenum in
ternalformat, |
3403 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 3421 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
3404 { | 3422 { |
3405 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)) | 3423 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)) |
3406 return; | 3424 return; |
3407 | 3425 |
3408 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); | 3426 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); |
| 3427 |
3409 // If possible, copy from the canvas element directly to the texture | 3428 // If possible, copy from the canvas element directly to the texture |
3410 // via the GPU, without a read-back to system memory. | 3429 // via the GPU, without a read-back to system memory. |
3411 if (GL_TEXTURE_2D == target && texture) { | 3430 if (GL_TEXTURE_2D == target && texture) { |
| 3431 ScopedTexture2DRestorer restorer(this); |
| 3432 |
3412 if (!canvas->is3D()) { | 3433 if (!canvas->is3D()) { |
3413 ImageBuffer* buffer = canvas->buffer(); | 3434 ImageBuffer* buffer = canvas->buffer(); |
3414 if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture
->object(), internalformat, type, | 3435 if (buffer && buffer->copyToPlatformTexture(m_context.get(), texture
->object(), internalformat, type, |
3415 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 3436 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
3416 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3437 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
3417 return; | 3438 return; |
3418 } | 3439 } |
3419 } else { | 3440 } else { |
3420 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->
renderingContext()); | 3441 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->
renderingContext()); |
| 3442 ScopedTexture2DRestorer restorer(gl); |
3421 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get()
, texture->object(), internalformat, type, | 3443 if (gl && gl->m_drawingBuffer->copyToPlatformTexture(m_context.get()
, texture->object(), internalformat, type, |
3422 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 3444 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
3423 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); | 3445 texture->setLevelInfo(target, level, internalformat, canvas->wid
th(), canvas->height(), type); |
3424 return; | 3446 return; |
3425 } | 3447 } |
3426 } | 3448 } |
3427 } | 3449 } |
3428 | 3450 |
3429 RefPtr<ImageData> imageData = canvas->getImageData(); | 3451 RefPtr<ImageData> imageData = canvas->getImageData(); |
3430 if (imageData) | 3452 if (imageData) |
(...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5331 LocalFrame* frame = canvas()->document().frame(); | 5353 LocalFrame* frame = canvas()->document().frame(); |
5332 if (!frame) | 5354 if (!frame) |
5333 return; | 5355 return; |
5334 | 5356 |
5335 Settings* settings = frame->settings(); | 5357 Settings* settings = frame->settings(); |
5336 | 5358 |
5337 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled
())) | 5359 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled
())) |
5338 return; | 5360 return; |
5339 | 5361 |
5340 blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes->
attributes(canvas()->document().topDocument().url().string(), settings); | 5362 blink::WebGraphicsContext3D::Attributes attributes = m_requestedAttributes->
attributes(canvas()->document().topDocument().url().string(), settings); |
5341 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr
ent()->createOffscreenGraphicsContext3D(attributes)); | 5363 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr
ent()->createOffscreenGraphicsContext3D(attributes, 0)); |
5342 if (!context) { | 5364 if (!context) { |
5343 if (m_contextLostMode == RealLostContext) { | 5365 if (m_contextLostMode == RealLostContext) { |
5344 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, FROM_HERE
); | 5366 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, FROM_HERE
); |
5345 } else { | 5367 } else { |
5346 // This likely shouldn't happen but is the best way to report it to
the WebGL app. | 5368 // This likely shouldn't happen but is the best way to report it to
the WebGL app. |
5347 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context
"); | 5369 synthesizeGLError(GL_INVALID_OPERATION, "", "error restoring context
"); |
5348 } | 5370 } |
5349 return; | 5371 return; |
5350 } | 5372 } |
5351 | 5373 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5559 if (m_textureUnits[i].m_texture2DBinding | 5581 if (m_textureUnits[i].m_texture2DBinding |
5560 || m_textureUnits[i].m_textureCubeMapBinding) { | 5582 || m_textureUnits[i].m_textureCubeMapBinding) { |
5561 m_onePlusMaxNonDefaultTextureUnit = i + 1; | 5583 m_onePlusMaxNonDefaultTextureUnit = i + 1; |
5562 return; | 5584 return; |
5563 } | 5585 } |
5564 } | 5586 } |
5565 m_onePlusMaxNonDefaultTextureUnit = 0; | 5587 m_onePlusMaxNonDefaultTextureUnit = 0; |
5566 } | 5588 } |
5567 | 5589 |
5568 } // namespace WebCore | 5590 } // namespace WebCore |
OLD | NEW |