| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 #include "platform/RuntimeEnabledFeatures.h" | 86 #include "platform/RuntimeEnabledFeatures.h" |
| 87 #include "platform/ThreadSafeFunctional.h" | 87 #include "platform/ThreadSafeFunctional.h" |
| 88 #include "platform/WaitableEvent.h" | 88 #include "platform/WaitableEvent.h" |
| 89 #include "platform/geometry/IntSize.h" | 89 #include "platform/geometry/IntSize.h" |
| 90 #include "platform/graphics/GraphicsContext.h" | 90 #include "platform/graphics/GraphicsContext.h" |
| 91 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 91 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 92 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 92 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| 93 #include "public/platform/Platform.h" | 93 #include "public/platform/Platform.h" |
| 94 #include "public/platform/functional/WebFunction.h" | 94 #include "public/platform/functional/WebFunction.h" |
| 95 #include "wtf/Functional.h" | 95 #include "wtf/Functional.h" |
| 96 #include "wtf/PtrUtil.h" | 96 #include "wtf/PassOwnPtr.h" |
| 97 #include "wtf/text/StringBuilder.h" | 97 #include "wtf/text/StringBuilder.h" |
| 98 #include "wtf/text/StringUTF8Adaptor.h" | 98 #include "wtf/text/StringUTF8Adaptor.h" |
| 99 #include "wtf/typed_arrays/ArrayBufferContents.h" | 99 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| 100 |
| 100 #include <memory> | 101 #include <memory> |
| 101 | 102 |
| 102 namespace blink { | 103 namespace blink { |
| 103 | 104 |
| 104 namespace { | 105 namespace { |
| 105 | 106 |
| 106 const double secondsBetweenRestoreAttempts = 1.0; | 107 const double secondsBetweenRestoreAttempts = 1.0; |
| 107 const int maxGLErrorsAllowedToConsole = 256; | 108 const int maxGLErrorsAllowedToConsole = 256; |
| 108 const unsigned maxGLActiveContexts = 16; | 109 const unsigned maxGLActiveContexts = 16; |
| 109 const unsigned maxGLActiveContextsOnWorker = 4; | 110 const unsigned maxGLActiveContextsOnWorker = 4; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 statusMessage.append("."); | 530 statusMessage.append("."); |
| 530 return statusMessage; | 531 return statusMessage; |
| 531 } | 532 } |
| 532 | 533 |
| 533 struct ContextProviderCreationInfo { | 534 struct ContextProviderCreationInfo { |
| 534 // Inputs. | 535 // Inputs. |
| 535 Platform::ContextAttributes contextAttributes; | 536 Platform::ContextAttributes contextAttributes; |
| 536 Platform::GraphicsInfo* glInfo; | 537 Platform::GraphicsInfo* glInfo; |
| 537 ScriptState* scriptState; | 538 ScriptState* scriptState; |
| 538 // Outputs. | 539 // Outputs. |
| 539 std::unique_ptr<WebGraphicsContext3DProvider> createdContextProvider; | 540 OwnPtr<WebGraphicsContext3DProvider> createdContextProvider; |
| 540 }; | 541 }; |
| 541 | 542 |
| 542 static void createContextProviderOnMainThread(ContextProviderCreationInfo* creat
ionInfo, WaitableEvent* waitableEvent) | 543 static void createContextProviderOnMainThread(ContextProviderCreationInfo* creat
ionInfo, WaitableEvent* waitableEvent) |
| 543 { | 544 { |
| 544 ASSERT(isMainThread()); | 545 ASSERT(isMainThread()); |
| 545 creationInfo->createdContextProvider = wrapUnique(Platform::current()->creat
eOffscreenGraphicsContext3DProvider( | 546 creationInfo->createdContextProvider = adoptPtr(Platform::current()->createO
ffscreenGraphicsContext3DProvider( |
| 546 creationInfo->contextAttributes, creationInfo->scriptState->getExecution
Context()->url(), 0, creationInfo->glInfo)); | 547 creationInfo->contextAttributes, creationInfo->scriptState->getExecution
Context()->url(), 0, creationInfo->glInfo)); |
| 547 waitableEvent->signal(); | 548 waitableEvent->signal(); |
| 548 } | 549 } |
| 549 | 550 |
| 550 static std::unique_ptr<WebGraphicsContext3DProvider> createContextProviderOnWork
erThread(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo*
glInfo, ScriptState* scriptState) | 551 static PassOwnPtr<WebGraphicsContext3DProvider> createContextProviderOnWorkerThr
ead(Platform::ContextAttributes contextAttributes, Platform::GraphicsInfo* glInf
o, ScriptState* scriptState) |
| 551 { | 552 { |
| 552 WaitableEvent waitableEvent; | 553 WaitableEvent waitableEvent; |
| 553 ContextProviderCreationInfo creationInfo; | 554 ContextProviderCreationInfo creationInfo; |
| 554 creationInfo.contextAttributes = contextAttributes; | 555 creationInfo.contextAttributes = contextAttributes; |
| 555 creationInfo.glInfo = glInfo; | 556 creationInfo.glInfo = glInfo; |
| 556 creationInfo.scriptState = scriptState; | 557 creationInfo.scriptState = scriptState; |
| 557 WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRun
ner(); | 558 WebTaskRunner* taskRunner = Platform::current()->mainThread()->getWebTaskRun
ner(); |
| 558 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderO
nMainThread, AllowCrossThreadAccess(&creationInfo), AllowCrossThreadAccess(&wait
ableEvent))); | 559 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&createContextProviderO
nMainThread, AllowCrossThreadAccess(&creationInfo), AllowCrossThreadAccess(&wait
ableEvent))); |
| 559 waitableEvent.wait(); | 560 waitableEvent.wait(); |
| 560 return std::move(creationInfo.createdContextProvider); | 561 return std::move(creationInfo.createdContextProvider); |
| 561 } | 562 } |
| 562 | 563 |
| 563 std::unique_ptr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createC
ontextProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebG
LContextAttributes attributes, unsigned webGLVersion) | 564 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createContex
tProviderInternal(HTMLCanvasElement* canvas, ScriptState* scriptState, WebGLCont
extAttributes attributes, unsigned webGLVersion) |
| 564 { | 565 { |
| 565 // Exactly one of these must be provided. | 566 // Exactly one of these must be provided. |
| 566 DCHECK_EQ(!canvas, !!scriptState); | 567 DCHECK_EQ(!canvas, !!scriptState); |
| 567 // The canvas is only given on the main thread. | 568 // The canvas is only given on the main thread. |
| 568 DCHECK(!canvas || isMainThread()); | 569 DCHECK(!canvas || isMainThread()); |
| 569 | 570 |
| 570 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(
attributes, webGLVersion); | 571 Platform::ContextAttributes contextAttributes = toPlatformContextAttributes(
attributes, webGLVersion); |
| 571 Platform::GraphicsInfo glInfo; | 572 Platform::GraphicsInfo glInfo; |
| 572 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider; | 573 OwnPtr<WebGraphicsContext3DProvider> contextProvider; |
| 573 if (isMainThread()) { | 574 if (isMainThread()) { |
| 574 const auto& url = canvas ? canvas->document().topDocument().url() : scri
ptState->getExecutionContext()->url(); | 575 const auto& url = canvas ? canvas->document().topDocument().url() : scri
ptState->getExecutionContext()->url(); |
| 575 contextProvider = wrapUnique(Platform::current()->createOffscreenGraphic
sContext3DProvider( | 576 contextProvider = adoptPtr(Platform::current()->createOffscreenGraphicsC
ontext3DProvider( |
| 576 contextAttributes, url, 0, &glInfo)); | 577 contextAttributes, url, 0, &glInfo)); |
| 577 } else { | 578 } else { |
| 578 contextProvider = createContextProviderOnWorkerThread(contextAttributes,
&glInfo, scriptState); | 579 contextProvider = createContextProviderOnWorkerThread(contextAttributes,
&glInfo, scriptState); |
| 579 } | 580 } |
| 580 if (contextProvider && !contextProvider->bindToCurrentThread()) { | 581 if (contextProvider && !contextProvider->bindToCurrentThread()) { |
| 581 contextProvider = nullptr; | 582 contextProvider = nullptr; |
| 582 String errorString(glInfo.errorMessage.utf8().data()); | 583 String errorString(glInfo.errorMessage.utf8().data()); |
| 583 errorString.insert("bindToCurrentThread failed: ", 0); | 584 errorString.insert("bindToCurrentThread failed: ", 0); |
| 584 glInfo.errorMessage = errorString; | 585 glInfo.errorMessage = errorString; |
| 585 } | 586 } |
| 586 if (!contextProvider || shouldFailContextCreationForTesting) { | 587 if (!contextProvider || shouldFailContextCreationForTesting) { |
| 587 shouldFailContextCreationForTesting = false; | 588 shouldFailContextCreationForTesting = false; |
| 588 if (canvas) | 589 if (canvas) |
| 589 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg
lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); | 590 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg
lcontextcreationerror, false, true, extractWebGLContextCreationError(glInfo))); |
| 590 return nullptr; | 591 return nullptr; |
| 591 } | 592 } |
| 592 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); | 593 gpu::gles2::GLES2Interface* gl = contextProvider->contextGL(); |
| 593 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten
cil")) { | 594 if (!String(gl->GetString(GL_EXTENSIONS)).contains("GL_OES_packed_depth_sten
cil")) { |
| 594 if (canvas) | 595 if (canvas) |
| 595 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg
lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require
d.")); | 596 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webg
lcontextcreationerror, false, true, "OES_packed_depth_stencil support is require
d.")); |
| 596 return nullptr; | 597 return nullptr; |
| 597 } | 598 } |
| 598 return contextProvider; | 599 return contextProvider; |
| 599 } | 600 } |
| 600 | 601 |
| 601 std::unique_ptr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createW
ebGraphicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes at
tributes, unsigned webGLVersion) | 602 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra
phicsContext3DProvider(HTMLCanvasElement* canvas, WebGLContextAttributes attribu
tes, unsigned webGLVersion) |
| 602 { | 603 { |
| 603 Document& document = canvas->document(); | 604 Document& document = canvas->document(); |
| 604 LocalFrame* frame = document.frame(); | 605 LocalFrame* frame = document.frame(); |
| 605 if (!frame) { | 606 if (!frame) { |
| 606 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Web page was not allowed to create a WebGL cont
ext.")); | 607 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Web page was not allowed to create a WebGL cont
ext.")); |
| 607 return nullptr; | 608 return nullptr; |
| 608 } | 609 } |
| 609 Settings* settings = frame->settings(); | 610 Settings* settings = frame->settings(); |
| 610 | 611 |
| 611 // The FrameLoaderClient might block creation of a new WebGL context despite
the page settings; in | 612 // The FrameLoaderClient might block creation of a new WebGL context despite
the page settings; in |
| 612 // particular, if WebGL contexts were lost one or more times via the GL_ARB_
robustness extension. | 613 // particular, if WebGL contexts were lost one or more times via the GL_ARB_
robustness extension. |
| 613 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled
())) { | 614 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled
())) { |
| 614 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Web page was not allowed to create a WebGL cont
ext.")); | 615 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon
textcreationerror, false, true, "Web page was not allowed to create a WebGL cont
ext.")); |
| 615 return nullptr; | 616 return nullptr; |
| 616 } | 617 } |
| 617 | 618 |
| 618 return createContextProviderInternal(canvas, nullptr, attributes, webGLVersi
on); | 619 return createContextProviderInternal(canvas, nullptr, attributes, webGLVersi
on); |
| 619 } | 620 } |
| 620 | 621 |
| 621 std::unique_ptr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createW
ebGraphicsContext3DProvider(ScriptState* scriptState, WebGLContextAttributes att
ributes, unsigned webGLVersion) | 622 PassOwnPtr<WebGraphicsContext3DProvider> WebGLRenderingContextBase::createWebGra
phicsContext3DProvider(ScriptState* scriptState, WebGLContextAttributes attribut
es, unsigned webGLVersion) |
| 622 { | 623 { |
| 623 return createContextProviderInternal(nullptr, scriptState, attributes, webGL
Version); | 624 return createContextProviderInternal(nullptr, scriptState, attributes, webGL
Version); |
| 624 } | 625 } |
| 625 | 626 |
| 626 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() | 627 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail() |
| 627 { | 628 { |
| 628 shouldFailContextCreationForTesting = true; | 629 shouldFailContextCreationForTesting = true; |
| 629 } | 630 } |
| 630 | 631 |
| 631 ImageBitmap* WebGLRenderingContextBase::transferToImageBitmapBase() | 632 ImageBitmap* WebGLRenderingContextBase::transferToImageBitmapBase() |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 case GL_SRGB8: | 871 case GL_SRGB8: |
| 871 case GL_SRGB8_ALPHA8: | 872 case GL_SRGB8_ALPHA8: |
| 872 return true; | 873 return true; |
| 873 default: | 874 default: |
| 874 return false; | 875 return false; |
| 875 } | 876 } |
| 876 } | 877 } |
| 877 | 878 |
| 878 } // namespace | 879 } // namespace |
| 879 | 880 |
| 880 WebGLRenderingContextBase::WebGLRenderingContextBase(OffscreenCanvas* passedOffs
creenCanvas, std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, cons
t WebGLContextAttributes& requestedAttributes) | 881 WebGLRenderingContextBase::WebGLRenderingContextBase(OffscreenCanvas* passedOffs
creenCanvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const Web
GLContextAttributes& requestedAttributes) |
| 881 : WebGLRenderingContextBase(nullptr, passedOffscreenCanvas, std::move(contex
tProvider), requestedAttributes) | 882 : WebGLRenderingContextBase(nullptr, passedOffscreenCanvas, std::move(contex
tProvider), requestedAttributes) |
| 882 { } | 883 { } |
| 883 | 884 |
| 884 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
nvas, std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, const WebGL
ContextAttributes& requestedAttributes) | 885 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
nvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLConte
xtAttributes& requestedAttributes) |
| 885 : WebGLRenderingContextBase(passedCanvas, nullptr, std::move(contextProvider
), requestedAttributes) | 886 : WebGLRenderingContextBase(passedCanvas, nullptr, std::move(contextProvider
), requestedAttributes) |
| 886 { } | 887 { } |
| 887 | 888 |
| 888 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
nvas, OffscreenCanvas* passedOffscreenCanvas, std::unique_ptr<WebGraphicsContext
3DProvider> contextProvider, const WebGLContextAttributes& requestedAttributes) | 889 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa
nvas, OffscreenCanvas* passedOffscreenCanvas, PassOwnPtr<WebGraphicsContext3DPro
vider> contextProvider, const WebGLContextAttributes& requestedAttributes) |
| 889 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas) | 890 : CanvasRenderingContext(passedCanvas, passedOffscreenCanvas) |
| 890 , m_isHidden(false) | 891 , m_isHidden(false) |
| 891 , m_contextLostMode(NotLostContext) | 892 , m_contextLostMode(NotLostContext) |
| 892 , m_autoRecoveryMethod(Manual) | 893 , m_autoRecoveryMethod(Manual) |
| 893 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch
ContextLostEvent) | 894 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch
ContextLostEvent) |
| 894 , m_restoreAllowed(false) | 895 , m_restoreAllowed(false) |
| 895 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) | 896 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) |
| 896 , m_preservedDefaultVAOObjectWrapper(false) | 897 , m_preservedDefaultVAOObjectWrapper(false) |
| 897 , m_generatedImageCache(4) | 898 , m_generatedImageCache(4) |
| 898 , m_requestedAttributes(requestedAttributes) | 899 , m_requestedAttributes(requestedAttributes) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 929 for (size_t i = 0; i < WTF_ARRAY_LENGTH(values); ++i) { \ | 930 for (size_t i = 0; i < WTF_ARRAY_LENGTH(values); ++i) { \ |
| 930 set.insert(values[i]); \ | 931 set.insert(values[i]); \ |
| 931 } | 932 } |
| 932 | 933 |
| 933 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); | 934 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); |
| 934 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal
FormatsES2); | 935 ADD_VALUES_TO_SET(m_supportedInternalFormatsCopyTexImage, kSupportedInternal
FormatsES2); |
| 935 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); | 936 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); |
| 936 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); | 937 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); |
| 937 } | 938 } |
| 938 | 939 |
| 939 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(std::un
ique_ptr<WebGraphicsContext3DProvider> contextProvider) | 940 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn
Ptr<WebGraphicsContext3DProvider> contextProvider) |
| 940 { | 941 { |
| 941 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha(); | 942 bool premultipliedAlpha = m_requestedAttributes.premultipliedAlpha(); |
| 942 bool wantAlphaChannel = m_requestedAttributes.alpha(); | 943 bool wantAlphaChannel = m_requestedAttributes.alpha(); |
| 943 bool wantDepthBuffer = m_requestedAttributes.depth(); | 944 bool wantDepthBuffer = m_requestedAttributes.depth(); |
| 944 bool wantStencilBuffer = m_requestedAttributes.stencil(); | 945 bool wantStencilBuffer = m_requestedAttributes.stencil(); |
| 945 bool wantAntialiasing = m_requestedAttributes.antialias(); | 946 bool wantAntialiasing = m_requestedAttributes.antialias(); |
| 946 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser
veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; | 947 DrawingBuffer::PreserveDrawingBuffer preserve = m_requestedAttributes.preser
veDrawingBuffer() ? DrawingBuffer::Preserve : DrawingBuffer::Discard; |
| 947 return DrawingBuffer::create( | 948 return DrawingBuffer::create( |
| 948 std::move(contextProvider), | 949 std::move(contextProvider), |
| 949 clampedCanvasSize(), | 950 clampedCanvasSize(), |
| (...skipping 3476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4426 if (functionID == TexImage2D) { | 4427 if (functionID == TexImage2D) { |
| 4427 // Go through the fast path doing a GPU-GPU textures copy without a read
back to system memory if possible. | 4428 // Go through the fast path doing a GPU-GPU textures copy without a read
back to system memory if possible. |
| 4428 // Otherwise, it will fall back to the normal SW path. | 4429 // Otherwise, it will fall back to the normal SW path. |
| 4429 if (GL_TEXTURE_2D == target) { | 4430 if (GL_TEXTURE_2D == target) { |
| 4430 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalform
at, type, level) | 4431 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalform
at, type, level) |
| 4431 && video->copyVideoTextureToPlatformTexture(contextGL(), texture
->object(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4432 && video->copyVideoTextureToPlatformTexture(contextGL(), texture
->object(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4432 return; | 4433 return; |
| 4433 } | 4434 } |
| 4434 | 4435 |
| 4435 // Try using an accelerated image buffer, this allows YUV conversion
to be done on the GPU. | 4436 // Try using an accelerated image buffer, this allows YUV conversion
to be done on the GPU. |
| 4436 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Acceler
atedImageBufferSurface(IntSize(video->videoWidth(), video->videoHeight()))); | 4437 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBu
fferSurface(IntSize(video->videoWidth(), video->videoHeight()))); |
| 4437 if (surface->isValid()) { | 4438 if (surface->isValid()) { |
| 4438 std::unique_ptr<ImageBuffer> imageBuffer(ImageBuffer::create(std
::move(surface))); | 4439 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(std::move(su
rface))); |
| 4439 if (imageBuffer) { | 4440 if (imageBuffer) { |
| 4440 // The video element paints an RGBA frame into our surface h
ere. By using an AcceleratedImageBufferSurface, | 4441 // The video element paints an RGBA frame into our surface h
ere. By using an AcceleratedImageBufferSurface, |
| 4441 // we enable the WebMediaPlayer implementation to do any nec
essary color space conversion on the GPU (though it | 4442 // we enable the WebMediaPlayer implementation to do any nec
essary color space conversion on the GPU (though it |
| 4442 // may still do a CPU conversion and upload the results). | 4443 // may still do a CPU conversion and upload the results). |
| 4443 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0
, video->videoWidth(), video->videoHeight()), nullptr); | 4444 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0
, video->videoWidth(), video->videoHeight()), nullptr); |
| 4444 | 4445 |
| 4445 // This is a straight GPU-GPU copy, any necessary color spac
e conversion was handled in the paintCurrentFrameInContext() call. | 4446 // This is a straight GPU-GPU copy, any necessary color spac
e conversion was handled in the paintCurrentFrameInContext() call. |
| 4446 if (imageBuffer->copyToPlatformTexture(contextGL(), texture-
>object(), internalformat, type, | 4447 if (imageBuffer->copyToPlatformTexture(contextGL(), texture-
>object(), internalformat, type, |
| 4447 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4448 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4448 return; | 4449 return; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4478 TexImageFunctionType functionType; | 4479 TexImageFunctionType functionType; |
| 4479 if (functionID == TexImage2D) | 4480 if (functionID == TexImage2D) |
| 4480 functionType = TexImage; | 4481 functionType = TexImage; |
| 4481 else | 4482 else |
| 4482 functionType = TexSubImage; | 4483 functionType = TexSubImage; |
| 4483 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, leve
l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse
t, yoffset, zoffset)) | 4484 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, leve
l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse
t, yoffset, zoffset)) |
| 4484 return; | 4485 return; |
| 4485 ASSERT(bitmap->bitmapImage()); | 4486 ASSERT(bitmap->bitmapImage()); |
| 4486 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); | 4487 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); |
| 4487 SkPixmap pixmap; | 4488 SkPixmap pixmap; |
| 4488 std::unique_ptr<uint8_t[]> pixelData; | 4489 OwnPtr<uint8_t[]> pixelData; |
| 4489 uint8_t* pixelDataPtr = nullptr; | 4490 uint8_t* pixelDataPtr = nullptr; |
| 4490 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed | 4491 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed |
| 4491 // Use texture mailbox in that case. | 4492 // Use texture mailbox in that case. |
| 4492 bool peekSucceed = skImage->peekPixels(&pixmap); | 4493 bool peekSucceed = skImage->peekPixels(&pixmap); |
| 4493 if (peekSucceed) { | 4494 if (peekSucceed) { |
| 4494 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | 4495 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 4495 } else if (skImage->isTextureBacked()) { | 4496 } else if (skImage->isTextureBacked()) { |
| 4496 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip
lyAlpha : DontPremultiplyAlpha); | 4497 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip
lyAlpha : DontPremultiplyAlpha); |
| 4497 pixelDataPtr = pixelData.get(); | 4498 pixelDataPtr = pixelData.get(); |
| 4498 } | 4499 } |
| (...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6083 return; | 6084 return; |
| 6084 | 6085 |
| 6085 // 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. | 6086 // 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. |
| 6086 if (drawingBuffer()) { | 6087 if (drawingBuffer()) { |
| 6087 m_drawingBuffer->beginDestruction(); | 6088 m_drawingBuffer->beginDestruction(); |
| 6088 m_drawingBuffer.clear(); | 6089 m_drawingBuffer.clear(); |
| 6089 } | 6090 } |
| 6090 | 6091 |
| 6091 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque
stedAttributes, version()); | 6092 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque
stedAttributes, version()); |
| 6092 Platform::GraphicsInfo glInfo; | 6093 Platform::GraphicsInfo glInfo; |
| 6093 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = wrapUnique(P
latform::current()->createOffscreenGraphicsContext3DProvider( | 6094 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu
rrent()->createOffscreenGraphicsContext3DProvider( |
| 6094 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); | 6095 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); |
| 6095 RefPtr<DrawingBuffer> buffer; | 6096 RefPtr<DrawingBuffer> buffer; |
| 6096 if (contextProvider->bindToCurrentThread()) { | 6097 if (contextProvider->bindToCurrentThread()) { |
| 6097 // Construct a new drawing buffer with the new GL context. | 6098 // Construct a new drawing buffer with the new GL context. |
| 6098 buffer = createDrawingBuffer(std::move(contextProvider)); | 6099 buffer = createDrawingBuffer(std::move(contextProvider)); |
| 6099 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i
s set to null. | 6100 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i
s set to null. |
| 6100 } | 6101 } |
| 6101 if (!buffer) { | 6102 if (!buffer) { |
| 6102 if (m_contextLostMode == RealLostContext) { | 6103 if (m_contextLostMode == RealLostContext) { |
| 6103 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO
M_HERE); | 6104 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO
M_HERE); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6125 } | 6126 } |
| 6126 | 6127 |
| 6127 String WebGLRenderingContextBase::ensureNotNull(const String& text) const | 6128 String WebGLRenderingContextBase::ensureNotNull(const String& text) const |
| 6128 { | 6129 { |
| 6129 if (text.isNull()) | 6130 if (text.isNull()) |
| 6130 return WTF::emptyString(); | 6131 return WTF::emptyString(); |
| 6131 return text; | 6132 return text; |
| 6132 } | 6133 } |
| 6133 | 6134 |
| 6134 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity
) | 6135 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity
) |
| 6135 : m_buffers(wrapArrayUnique(new std::unique_ptr<ImageBuffer>[capacity])) | 6136 : m_buffers(adoptArrayPtr(new OwnPtr<ImageBuffer>[capacity])) |
| 6136 , m_capacity(capacity) | 6137 , m_capacity(capacity) |
| 6137 { | 6138 { |
| 6138 } | 6139 } |
| 6139 | 6140 |
| 6140 ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const I
ntSize& size) | 6141 ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const I
ntSize& size) |
| 6141 { | 6142 { |
| 6142 int i; | 6143 int i; |
| 6143 for (i = 0; i < m_capacity; ++i) { | 6144 for (i = 0; i < m_capacity; ++i) { |
| 6144 ImageBuffer* buf = m_buffers[i].get(); | 6145 ImageBuffer* buf = m_buffers[i].get(); |
| 6145 if (!buf) | 6146 if (!buf) |
| 6146 break; | 6147 break; |
| 6147 if (buf->size() != size) | 6148 if (buf->size() != size) |
| 6148 continue; | 6149 continue; |
| 6149 bubbleToFront(i); | 6150 bubbleToFront(i); |
| 6150 return buf; | 6151 return buf; |
| 6151 } | 6152 } |
| 6152 | 6153 |
| 6153 std::unique_ptr<ImageBuffer> temp(ImageBuffer::create(size)); | 6154 OwnPtr<ImageBuffer> temp(ImageBuffer::create(size)); |
| 6154 if (!temp) | 6155 if (!temp) |
| 6155 return nullptr; | 6156 return nullptr; |
| 6156 i = std::min(m_capacity - 1, i); | 6157 i = std::min(m_capacity - 1, i); |
| 6157 m_buffers[i] = std::move(temp); | 6158 m_buffers[i] = std::move(temp); |
| 6158 | 6159 |
| 6159 ImageBuffer* buf = m_buffers[i].get(); | 6160 ImageBuffer* buf = m_buffers[i].get(); |
| 6160 bubbleToFront(i); | 6161 bubbleToFront(i); |
| 6161 return buf; | 6162 return buf; |
| 6162 } | 6163 } |
| 6163 | 6164 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6424 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6425 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6425 } | 6426 } |
| 6426 | 6427 |
| 6427 void WebGLRenderingContextBase::restoreUnpackParameters() | 6428 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6428 { | 6429 { |
| 6429 if (m_unpackAlignment != 1) | 6430 if (m_unpackAlignment != 1) |
| 6430 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6431 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6431 } | 6432 } |
| 6432 | 6433 |
| 6433 } // namespace blink | 6434 } // namespace blink |
| OLD | NEW |