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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

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

Powered by Google App Engine
This is Rietveld 408576698