| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 #include "wtf/text/StringUTF8Adaptor.h" | 104 #include "wtf/text/StringUTF8Adaptor.h" |
| 105 | 105 |
| 106 namespace blink { | 106 namespace blink { |
| 107 | 107 |
| 108 namespace { | 108 namespace { |
| 109 | 109 |
| 110 const double secondsBetweenRestoreAttempts = 1.0; | 110 const double secondsBetweenRestoreAttempts = 1.0; |
| 111 const int maxGLErrorsAllowedToConsole = 256; | 111 const int maxGLErrorsAllowedToConsole = 256; |
| 112 const unsigned maxGLActiveContexts = 16; | 112 const unsigned maxGLActiveContexts = 16; |
| 113 | 113 |
| 114 using WebGLRenderingContextBaseSet = WillBePersistentHeapHashSet<RawPtrWillBeWea
kMember<WebGLRenderingContextBase>>; | 114 using WebGLRenderingContextBaseSet = PersistentHeapHashSet<WeakMember<WebGLRende
ringContextBase>>; |
| 115 WebGLRenderingContextBaseSet& activeContexts() | 115 WebGLRenderingContextBaseSet& activeContexts() |
| 116 { | 116 { |
| 117 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseSet, activeContexts, ()); | 117 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseSet, activeContexts, ()); |
| 118 return activeContexts; | 118 return activeContexts; |
| 119 } | 119 } |
| 120 | 120 |
| 121 using WebGLRenderingContextBaseMap = WillBePersistentHeapHashMap<RawPtrWillBeWea
kMember<WebGLRenderingContextBase>, int>; | 121 using WebGLRenderingContextBaseMap = PersistentHeapHashMap<WeakMember<WebGLRende
ringContextBase>, int>; |
| 122 WebGLRenderingContextBaseMap& forciblyEvictedContexts() | 122 WebGLRenderingContextBaseMap& forciblyEvictedContexts() |
| 123 { | 123 { |
| 124 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseMap, forciblyEvictedContexts, (
)); | 124 DEFINE_STATIC_LOCAL(WebGLRenderingContextBaseMap, forciblyEvictedContexts, (
)); |
| 125 return forciblyEvictedContexts; | 125 return forciblyEvictedContexts; |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace | 128 } // namespace |
| 129 | 129 |
| 130 void WebGLRenderingContextBase::forciblyLoseOldestContext(const String& reason) | 130 void WebGLRenderingContextBase::forciblyLoseOldestContext(const String& reason) |
| 131 { | 131 { |
| 132 WebGLRenderingContextBase* candidate = oldestContext(); | 132 WebGLRenderingContextBase* candidate = oldestContext(); |
| 133 if (!candidate) | 133 if (!candidate) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 // This context could belong to a dead page and the last JavaScript referenc
e has already | 136 // This context could belong to a dead page and the last JavaScript referenc
e has already |
| 137 // been lost. Garbage collection might be triggered in the middle of this fu
nction, for | 137 // been lost. Garbage collection might be triggered in the middle of this fu
nction, for |
| 138 // example, printWarningToConsole() causes an upcall to JavaScript. | 138 // example, printWarningToConsole() causes an upcall to JavaScript. |
| 139 // Must make sure that the context is not deleted until the call stack unwin
ds. | 139 // Must make sure that the context is not deleted until the call stack unwin
ds. |
| 140 RefPtrWillBeRawPtr<WebGLRenderingContextBase> protect(candidate); | 140 RawPtr<WebGLRenderingContextBase> protect(candidate); |
| 141 | 141 |
| 142 candidate->printWarningToConsole(reason); | 142 candidate->printWarningToConsole(reason); |
| 143 InspectorInstrumentation::didFireWebGLWarning(candidate->canvas()); | 143 InspectorInstrumentation::didFireWebGLWarning(candidate->canvas()); |
| 144 | 144 |
| 145 // This will call deactivateContext once the context has actually been lost. | 145 // This will call deactivateContext once the context has actually been lost. |
| 146 candidate->forceLostContext(WebGLRenderingContextBase::SyntheticLostContext,
WebGLRenderingContextBase::WhenAvailable); | 146 candidate->forceLostContext(WebGLRenderingContextBase::SyntheticLostContext,
WebGLRenderingContextBase::WhenAvailable); |
| 147 } | 147 } |
| 148 | 148 |
| 149 WebGLRenderingContextBase* WebGLRenderingContextBase::oldestContext() | 149 WebGLRenderingContextBase* WebGLRenderingContextBase::oldestContext() |
| 150 { | 150 { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 : m_context(context) | 466 : m_context(context) |
| 467 { | 467 { |
| 468 } | 468 } |
| 469 | 469 |
| 470 ~ScopedTexture2DRestorer() | 470 ~ScopedTexture2DRestorer() |
| 471 { | 471 { |
| 472 m_context->restoreCurrentTexture2D(); | 472 m_context->restoreCurrentTexture2D(); |
| 473 } | 473 } |
| 474 | 474 |
| 475 private: | 475 private: |
| 476 RawPtrWillBeMember<WebGLRenderingContextBase> m_context; | 476 Member<WebGLRenderingContextBase> m_context; |
| 477 }; | 477 }; |
| 478 | 478 |
| 479 class ScopedFramebufferRestorer { | 479 class ScopedFramebufferRestorer { |
| 480 STACK_ALLOCATED(); | 480 STACK_ALLOCATED(); |
| 481 public: | 481 public: |
| 482 explicit ScopedFramebufferRestorer(WebGLRenderingContextBase* context) | 482 explicit ScopedFramebufferRestorer(WebGLRenderingContextBase* context) |
| 483 : m_context(context) | 483 : m_context(context) |
| 484 { | 484 { |
| 485 } | 485 } |
| 486 | 486 |
| 487 ~ScopedFramebufferRestorer() | 487 ~ScopedFramebufferRestorer() |
| 488 { | 488 { |
| 489 m_context->restoreCurrentFramebuffer(); | 489 m_context->restoreCurrentFramebuffer(); |
| 490 } | 490 } |
| 491 | 491 |
| 492 private: | 492 private: |
| 493 RawPtrWillBeMember<WebGLRenderingContextBase> m_context; | 493 Member<WebGLRenderingContextBase> m_context; |
| 494 }; | 494 }; |
| 495 | 495 |
| 496 class WebGLRenderingContextErrorMessageCallback final : public GarbageCollectedF
inalized<WebGLRenderingContextErrorMessageCallback>, public WebGraphicsContext3D
::WebGraphicsErrorMessageCallback { | 496 class WebGLRenderingContextErrorMessageCallback final : public GarbageCollectedF
inalized<WebGLRenderingContextErrorMessageCallback>, public WebGraphicsContext3D
::WebGraphicsErrorMessageCallback { |
| 497 public: | 497 public: |
| 498 static WebGLRenderingContextErrorMessageCallback* create(WebGLRenderingConte
xtBase* context) | 498 static WebGLRenderingContextErrorMessageCallback* create(WebGLRenderingConte
xtBase* context) |
| 499 { | 499 { |
| 500 return new WebGLRenderingContextErrorMessageCallback(context); | 500 return new WebGLRenderingContextErrorMessageCallback(context); |
| 501 } | 501 } |
| 502 | 502 |
| 503 ~WebGLRenderingContextErrorMessageCallback() override { } | 503 ~WebGLRenderingContextErrorMessageCallback() override { } |
| 504 | 504 |
| 505 virtual void onErrorMessage(const WebString& message, GLint) | 505 virtual void onErrorMessage(const WebString& message, GLint) |
| 506 { | 506 { |
| 507 if (m_context->m_synthesizedErrorsToConsole) | 507 if (m_context->m_synthesizedErrorsToConsole) |
| 508 m_context->printGLErrorToConsole(message); | 508 m_context->printGLErrorToConsole(message); |
| 509 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas()
, message); | 509 InspectorInstrumentation::didFireWebGLErrorOrWarning(m_context->canvas()
, message); |
| 510 } | 510 } |
| 511 | 511 |
| 512 DEFINE_INLINE_TRACE() | 512 DEFINE_INLINE_TRACE() |
| 513 { | 513 { |
| 514 visitor->trace(m_context); | 514 visitor->trace(m_context); |
| 515 } | 515 } |
| 516 | 516 |
| 517 private: | 517 private: |
| 518 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase
* context) | 518 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase
* context) |
| 519 : m_context(context) { } | 519 : m_context(context) { } |
| 520 | 520 |
| 521 RawPtrWillBeMember<WebGLRenderingContextBase> m_context; | 521 Member<WebGLRenderingContextBase> m_context; |
| 522 }; | 522 }; |
| 523 | 523 |
| 524 static void formatWebGLStatusString(const String& glInfo, const String& infostri
ng, String& statusMessage) | 524 static void formatWebGLStatusString(const String& glInfo, const String& infostri
ng, String& statusMessage) |
| 525 { | 525 { |
| 526 if (!infostring.isEmpty()) | 526 if (!infostring.isEmpty()) |
| 527 statusMessage.append(", " + glInfo + " = " + infostring); | 527 statusMessage.append(", " + glInfo + " = " + infostring); |
| 528 } | 528 } |
| 529 | 529 |
| 530 static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
o) | 530 static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
o) |
| 531 { | 531 { |
| (...skipping 3709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4241 } | 4241 } |
| 4242 | 4242 |
| 4243 // Normal pure SW path. | 4243 // Normal pure SW path. |
| 4244 RefPtr<Image> image = videoFrameToImage(video); | 4244 RefPtr<Image> image = videoFrameToImage(video); |
| 4245 if (!image) | 4245 if (!image) |
| 4246 return; | 4246 return; |
| 4247 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web
GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4247 texImage2DImpl(target, level, internalformat, format, type, image.get(), Web
GLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4248 } | 4248 } |
| 4249 | 4249 |
| 4250 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4250 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
| 4251 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap, Exce
ptionState& exceptionState) | 4251 GLenum format, GLenum type, RawPtr<ImageBitmap> bitmap, ExceptionState& exce
ptionState) |
| 4252 { | 4252 { |
| 4253 if (isContextLost()) | 4253 if (isContextLost()) |
| 4254 return; | 4254 return; |
| 4255 if (!validateImageBitmap("texImage2D", bitmap.get(), exceptionState)) | 4255 if (!validateImageBitmap("texImage2D", bitmap.get(), exceptionState)) |
| 4256 return; | 4256 return; |
| 4257 if (!validateTexture2DBinding("texImage2D", target)) | 4257 if (!validateTexture2DBinding("texImage2D", target)) |
| 4258 return; | 4258 return; |
| 4259 if (!validateTexFunc("texImage2D", TexImage, SourceImageBitmap, target, leve
l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0,
0)) | 4259 if (!validateTexFunc("texImage2D", TexImage, SourceImageBitmap, target, leve
l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0,
0)) |
| 4260 return; | 4260 return; |
| 4261 ASSERT(bitmap->bitmapImage()); | 4261 ASSERT(bitmap->bitmapImage()); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4507 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceHTMLVideoElement, t
arget, level, 0, video->videoWidth(), video->videoHeight(), 1, 0, format, type,
xoffset, yoffset, 0)) | 4507 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceHTMLVideoElement, t
arget, level, 0, video->videoWidth(), video->videoHeight(), 1, 0, format, type,
xoffset, yoffset, 0)) |
| 4508 return; | 4508 return; |
| 4509 | 4509 |
| 4510 RefPtr<Image> image = videoFrameToImage(video); | 4510 RefPtr<Image> image = videoFrameToImage(video); |
| 4511 if (!image) | 4511 if (!image) |
| 4512 return; | 4512 return; |
| 4513 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); | 4513 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, image.get()
, WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, m_unpackPremultiplyAlpha); |
| 4514 } | 4514 } |
| 4515 | 4515 |
| 4516 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, | 4516 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint
xoffset, GLint yoffset, |
| 4517 GLenum format, GLenum type, PassRefPtrWillBeRawPtr<ImageBitmap> bitmap, Exce
ptionState& exceptionState) | 4517 GLenum format, GLenum type, RawPtr<ImageBitmap> bitmap, ExceptionState& exce
ptionState) |
| 4518 { | 4518 { |
| 4519 if (isContextLost()) | 4519 if (isContextLost()) |
| 4520 return; | 4520 return; |
| 4521 if (!validateImageBitmap("texSubImage2D", bitmap.get(), exceptionState)) | 4521 if (!validateImageBitmap("texSubImage2D", bitmap.get(), exceptionState)) |
| 4522 return; | 4522 return; |
| 4523 if (!validateTexture2DBinding("texSubImage2D", target)) | 4523 if (!validateTexture2DBinding("texSubImage2D", target)) |
| 4524 return; | 4524 return; |
| 4525 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceImageBitmap, target
, level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0)) | 4525 if (!validateTexFunc("texSubImage2D", TexSubImage, SourceImageBitmap, target
, level, 0, bitmap->width(), bitmap->height(), 1, 0, format, type, 0, 0, 0)) |
| 4526 return; | 4526 return; |
| 4527 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 4527 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5956 if (m_framebufferBinding && m_framebufferBinding->checkDepthStencilStatus(&r
eason) != GL_FRAMEBUFFER_COMPLETE) { | 5956 if (m_framebufferBinding && m_framebufferBinding->checkDepthStencilStatus(&r
eason) != GL_FRAMEBUFFER_COMPLETE) { |
| 5957 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason
); | 5957 synthesizeGLError(GL_INVALID_FRAMEBUFFER_OPERATION, functionName, reason
); |
| 5958 return false; | 5958 return false; |
| 5959 } | 5959 } |
| 5960 | 5960 |
| 5961 return true; | 5961 return true; |
| 5962 } | 5962 } |
| 5963 | 5963 |
| 5964 void WebGLRenderingContextBase::dispatchContextLostEvent(Timer<WebGLRenderingCon
textBase>*) | 5964 void WebGLRenderingContextBase::dispatchContextLostEvent(Timer<WebGLRenderingCon
textBase>*) |
| 5965 { | 5965 { |
| 5966 RefPtrWillBeRawPtr<WebGLContextEvent> event = WebGLContextEvent::create(Even
tTypeNames::webglcontextlost, false, true, ""); | 5966 RawPtr<WebGLContextEvent> event = WebGLContextEvent::create(EventTypeNames::
webglcontextlost, false, true, ""); |
| 5967 canvas()->dispatchEvent(event); | 5967 canvas()->dispatchEvent(event); |
| 5968 m_restoreAllowed = event->defaultPrevented(); | 5968 m_restoreAllowed = event->defaultPrevented(); |
| 5969 if (m_restoreAllowed && !m_isHidden) { | 5969 if (m_restoreAllowed && !m_isHidden) { |
| 5970 if (m_autoRecoveryMethod == Auto) | 5970 if (m_autoRecoveryMethod == Auto) |
| 5971 m_restoreTimer.startOneShot(0, BLINK_FROM_HERE); | 5971 m_restoreTimer.startOneShot(0, BLINK_FROM_HERE); |
| 5972 } | 5972 } |
| 5973 } | 5973 } |
| 5974 | 5974 |
| 5975 void WebGLRenderingContextBase::maybeRestoreContext(Timer<WebGLRenderingContextB
ase>*) | 5975 void WebGLRenderingContextBase::maybeRestoreContext(Timer<WebGLRenderingContextB
ase>*) |
| 5976 { | 5976 { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6344 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6344 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6345 } | 6345 } |
| 6346 | 6346 |
| 6347 void WebGLRenderingContextBase::restoreUnpackParameters() | 6347 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6348 { | 6348 { |
| 6349 if (m_unpackAlignment != 1) | 6349 if (m_unpackAlignment != 1) |
| 6350 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6350 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6351 } | 6351 } |
| 6352 | 6352 |
| 6353 } // namespace blink | 6353 } // namespace blink |
| OLD | NEW |