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

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: Address comments from Kent; merge. 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 3481 matching lines...) Expand 10 before | Expand all | Expand 10 after
4432 if (functionID == TexImage2D) { 4431 if (functionID == TexImage2D) {
4433 // Go through the fast path doing a GPU-GPU textures copy without a read back to system memory if possible. 4432 // Go through the fast path doing a GPU-GPU textures copy without a read back to system memory if possible.
4434 // Otherwise, it will fall back to the normal SW path. 4433 // Otherwise, it will fall back to the normal SW path.
4435 if (GL_TEXTURE_2D == target) { 4434 if (GL_TEXTURE_2D == target) {
4436 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalform at, type, level) 4435 if (Extensions3DUtil::canUseCopyTextureCHROMIUM(target, internalform at, type, level)
4437 && video->copyVideoTextureToPlatformTexture(contextGL(), texture ->object(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4436 && video->copyVideoTextureToPlatformTexture(contextGL(), texture ->object(), internalformat, type, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4438 return; 4437 return;
4439 } 4438 }
4440 4439
4441 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU. 4440 // Try using an accelerated image buffer, this allows YUV conversion to be done on the GPU.
4442 OwnPtr<ImageBufferSurface> surface = adoptPtr(new AcceleratedImageBu fferSurface(IntSize(video->videoWidth(), video->videoHeight()))); 4441 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new Acceler atedImageBufferSurface(IntSize(video->videoWidth(), video->videoHeight())));
4443 if (surface->isValid()) { 4442 if (surface->isValid()) {
4444 OwnPtr<ImageBuffer> imageBuffer(ImageBuffer::create(std::move(su rface))); 4443 std::unique_ptr<ImageBuffer> imageBuffer(ImageBuffer::create(std ::move(surface)));
4445 if (imageBuffer) { 4444 if (imageBuffer) {
4446 // The video element paints an RGBA frame into our surface h ere. By using an AcceleratedImageBufferSurface, 4445 // The video element paints an RGBA frame into our surface h ere. By using an AcceleratedImageBufferSurface,
4447 // we enable the WebMediaPlayer implementation to do any nec essary color space conversion on the GPU (though it 4446 // we enable the WebMediaPlayer implementation to do any nec essary color space conversion on the GPU (though it
4448 // may still do a CPU conversion and upload the results). 4447 // may still do a CPU conversion and upload the results).
4449 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0 , video->videoWidth(), video->videoHeight()), nullptr); 4448 video->paintCurrentFrame(imageBuffer->canvas(), IntRect(0, 0 , video->videoWidth(), video->videoHeight()), nullptr);
4450 4449
4451 // This is a straight GPU-GPU copy, any necessary color spac e conversion was handled in the paintCurrentFrameInContext() call. 4450 // This is a straight GPU-GPU copy, any necessary color spac e conversion was handled in the paintCurrentFrameInContext() call.
4452 if (imageBuffer->copyToPlatformTexture(contextGL(), texture- >object(), internalformat, type, 4451 if (imageBuffer->copyToPlatformTexture(contextGL(), texture- >object(), internalformat, type,
4453 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { 4452 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
4454 return; 4453 return;
(...skipping 29 matching lines...) Expand all
4484 TexImageFunctionType functionType; 4483 TexImageFunctionType functionType;
4485 if (functionID == TexImage2D) 4484 if (functionID == TexImage2D)
4486 functionType = TexImage; 4485 functionType = TexImage;
4487 else 4486 else
4488 functionType = TexSubImage; 4487 functionType = TexSubImage;
4489 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, leve l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse t, yoffset, zoffset)) 4488 if (!validateTexFunc(funcName, functionType, SourceImageBitmap, target, leve l, internalformat, bitmap->width(), bitmap->height(), 1, 0, format, type, xoffse t, yoffset, zoffset))
4490 return; 4489 return;
4491 ASSERT(bitmap->bitmapImage()); 4490 ASSERT(bitmap->bitmapImage());
4492 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame(); 4491 RefPtr<SkImage> skImage = bitmap->bitmapImage()->imageForCurrentFrame();
4493 SkPixmap pixmap; 4492 SkPixmap pixmap;
4494 OwnPtr<uint8_t[]> pixelData; 4493 std::unique_ptr<uint8_t[]> pixelData;
4495 uint8_t* pixelDataPtr = nullptr; 4494 uint8_t* pixelDataPtr = nullptr;
4496 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed 4495 // TODO(crbug.com/613411): peekPixels fails if the SkImage is texture-backed
4497 // Use texture mailbox in that case. 4496 // Use texture mailbox in that case.
4498 bool peekSucceed = skImage->peekPixels(&pixmap); 4497 bool peekSucceed = skImage->peekPixels(&pixmap);
4499 if (peekSucceed) { 4498 if (peekSucceed) {
4500 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); 4499 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr());
4501 } else if (skImage->isTextureBacked()) { 4500 } else if (skImage->isTextureBacked()) {
4502 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip lyAlpha : DontPremultiplyAlpha); 4501 pixelData = bitmap->copyBitmapData(bitmap->isPremultiplied() ? Premultip lyAlpha : DontPremultiplyAlpha);
4503 pixelDataPtr = pixelData.get(); 4502 pixelDataPtr = pixelData.get();
4504 } 4503 }
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
6094 return; 6093 return;
6095 6094
6096 // 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. 6095 // 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.
6097 if (drawingBuffer()) { 6096 if (drawingBuffer()) {
6098 m_drawingBuffer->beginDestruction(); 6097 m_drawingBuffer->beginDestruction();
6099 m_drawingBuffer.clear(); 6098 m_drawingBuffer.clear();
6100 } 6099 }
6101 6100
6102 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque stedAttributes, version()); 6101 Platform::ContextAttributes attributes = toPlatformContextAttributes(m_reque stedAttributes, version());
6103 Platform::GraphicsInfo glInfo; 6102 Platform::GraphicsInfo glInfo;
6104 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu rrent()->createOffscreenGraphicsContext3DProvider( 6103 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider = wrapUnique(P latform::current()->createOffscreenGraphicsContext3DProvider(
6105 attributes, canvas()->document().topDocument().url(), 0, &glInfo)); 6104 attributes, canvas()->document().topDocument().url(), 0, &glInfo));
6106 RefPtr<DrawingBuffer> buffer; 6105 RefPtr<DrawingBuffer> buffer;
6107 if (contextProvider->bindToCurrentThread()) { 6106 if (contextProvider->bindToCurrentThread()) {
6108 // Construct a new drawing buffer with the new GL context. 6107 // Construct a new drawing buffer with the new GL context.
6109 buffer = createDrawingBuffer(std::move(contextProvider)); 6108 buffer = createDrawingBuffer(std::move(contextProvider));
6110 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null. 6109 // If DrawingBuffer::create() fails to allocate a fbo, |drawingBuffer| i s set to null.
6111 } 6110 }
6112 if (!buffer) { 6111 if (!buffer) {
6113 if (m_contextLostMode == RealLostContext) { 6112 if (m_contextLostMode == RealLostContext) {
6114 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE); 6113 m_restoreTimer.startOneShot(secondsBetweenRestoreAttempts, BLINK_FRO M_HERE);
(...skipping 21 matching lines...) Expand all
6136 } 6135 }
6137 6136
6138 String WebGLRenderingContextBase::ensureNotNull(const String& text) const 6137 String WebGLRenderingContextBase::ensureNotNull(const String& text) const
6139 { 6138 {
6140 if (text.isNull()) 6139 if (text.isNull())
6141 return WTF::emptyString(); 6140 return WTF::emptyString();
6142 return text; 6141 return text;
6143 } 6142 }
6144 6143
6145 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity ) 6144 WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity )
6146 : m_buffers(adoptArrayPtr(new OwnPtr<ImageBuffer>[capacity])) 6145 : m_buffers(wrapArrayUnique(new std::unique_ptr<ImageBuffer>[capacity]))
6147 , m_capacity(capacity) 6146 , m_capacity(capacity)
6148 { 6147 {
6149 } 6148 }
6150 6149
6151 ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const I ntSize& size) 6150 ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const I ntSize& size)
6152 { 6151 {
6153 int i; 6152 int i;
6154 for (i = 0; i < m_capacity; ++i) { 6153 for (i = 0; i < m_capacity; ++i) {
6155 ImageBuffer* buf = m_buffers[i].get(); 6154 ImageBuffer* buf = m_buffers[i].get();
6156 if (!buf) 6155 if (!buf)
6157 break; 6156 break;
6158 if (buf->size() != size) 6157 if (buf->size() != size)
6159 continue; 6158 continue;
6160 bubbleToFront(i); 6159 bubbleToFront(i);
6161 return buf; 6160 return buf;
6162 } 6161 }
6163 6162
6164 OwnPtr<ImageBuffer> temp(ImageBuffer::create(size)); 6163 std::unique_ptr<ImageBuffer> temp(ImageBuffer::create(size));
6165 if (!temp) 6164 if (!temp)
6166 return nullptr; 6165 return nullptr;
6167 i = std::min(m_capacity - 1, i); 6166 i = std::min(m_capacity - 1, i);
6168 m_buffers[i] = std::move(temp); 6167 m_buffers[i] = std::move(temp);
6169 6168
6170 ImageBuffer* buf = m_buffers[i].get(); 6169 ImageBuffer* buf = m_buffers[i].get();
6171 bubbleToFront(i); 6170 bubbleToFront(i);
6172 return buf; 6171 return buf;
6173 } 6172 }
6174 6173
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
6435 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6434 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6436 } 6435 }
6437 6436
6438 void WebGLRenderingContextBase::restoreUnpackParameters() 6437 void WebGLRenderingContextBase::restoreUnpackParameters()
6439 { 6438 {
6440 if (m_unpackAlignment != 1) 6439 if (m_unpackAlignment != 1)
6441 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6440 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6442 } 6441 }
6443 6442
6444 } // namespace blink 6443 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698