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

Side by Side Diff: Source/core/html/canvas/WebGLRenderingContextBase.cpp

Issue 749653002: WebGL: clarify which Front or Back buffer is used by each API. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase to ToT Created 6 years 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 #include "platform/graphics/GraphicsContext.h" 84 #include "platform/graphics/GraphicsContext.h"
85 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 85 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
86 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" 86 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h"
87 #include "platform/graphics/gpu/DrawingBuffer.h" 87 #include "platform/graphics/gpu/DrawingBuffer.h"
88 #include "public/platform/Platform.h" 88 #include "public/platform/Platform.h"
89 #include "wtf/PassOwnPtr.h" 89 #include "wtf/PassOwnPtr.h"
90 #include "wtf/text/StringBuilder.h" 90 #include "wtf/text/StringBuilder.h"
91 91
92 namespace blink { 92 namespace blink {
93 93
94 namespace {
95
94 const double secondsBetweenRestoreAttempts = 1.0; 96 const double secondsBetweenRestoreAttempts = 1.0;
95 const int maxGLErrorsAllowedToConsole = 256; 97 const int maxGLErrorsAllowedToConsole = 256;
96 const unsigned maxGLActiveContexts = 16; 98 const unsigned maxGLActiveContexts = 16;
97 99
100 DrawingBuffer::SourceBuffer convertSourceBuffer(CanvasRenderingContext::SourceBu ffer sourceBuffer)
101 {
102 return static_cast<DrawingBuffer::SourceBuffer>(sourceBuffer);
103 }
104
105 } // namesapce
106
98 // FIXME: Oilpan: static vectors to heap allocated WebGLRenderingContextBase obj ects 107 // FIXME: Oilpan: static vectors to heap allocated WebGLRenderingContextBase obj ects
99 // are kept here. This relies on the WebGLRenderingContextBase finalization to 108 // are kept here. This relies on the WebGLRenderingContextBase finalization to
100 // explicitly retire themselves from these vectors, but it'd be preferable if 109 // explicitly retire themselves from these vectors, but it'd be preferable if
101 // the references were traced as per usual. 110 // the references were traced as per usual.
102 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::activeContexts() 111 Vector<WebGLRenderingContextBase*>& WebGLRenderingContextBase::activeContexts()
103 { 112 {
104 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, activeContexts, ()); 113 DEFINE_STATIC_LOCAL(Vector<WebGLRenderingContextBase*>, activeContexts, ());
105 return activeContexts; 114 return activeContexts;
106 } 115 }
107 116
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 if (canvas()->hasImageBuffer()) 917 if (canvas()->hasImageBuffer())
909 drawingBuffer()->paintRenderingResultsToCanvas(canvas()->buffer()); 918 drawingBuffer()->paintRenderingResultsToCanvas(canvas()->buffer());
910 } 919 }
911 920
912 if (m_framebufferBinding) 921 if (m_framebufferBinding)
913 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get())); 922 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get()));
914 else 923 else
915 drawingBuffer()->bind(); 924 drawingBuffer()->bind();
916 } 925 }
917 926
918 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul tsToImageData() 927 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul tsToImageData(SourceBuffer sourceBuffer)
919 { 928 {
920 if (isContextLost()) 929 if (isContextLost())
921 return nullptr; 930 return nullptr;
922 931
923 clearIfComposited(); 932 clearIfComposited();
924 drawingBuffer()->commit(); 933 drawingBuffer()->commit();
925 int width, height; 934 int width, height;
926 RefPtr<Uint8ClampedArray> imageDataPixels = drawingBuffer()->paintRenderingR esultsToImageData(width, height); 935 RefPtr<Uint8ClampedArray> imageDataPixels =
936 drawingBuffer()->paintRenderingResultsToImageData(width, height, convert SourceBuffer(sourceBuffer));
927 if (!imageDataPixels) 937 if (!imageDataPixels)
928 return nullptr; 938 return nullptr;
929 939
930 if (m_framebufferBinding) 940 if (m_framebufferBinding)
931 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get())); 941 webContext()->bindFramebuffer(GL_FRAMEBUFFER, objectOrZero(m_framebuffer Binding.get()));
932 else 942 else
933 drawingBuffer()->bind(); 943 drawingBuffer()->bind();
934 944
935 return ImageData::create(IntSize(width, height), imageDataPixels); 945 return ImageData::create(IntSize(width, height), imageDataPixels);
936 } 946 }
(...skipping 2613 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas-> renderingContext()); 3560 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas-> renderingContext());
3551 ScopedTexture2DRestorer restorer(gl); 3561 ScopedTexture2DRestorer restorer(gl);
3552 if (gl && gl->drawingBuffer()->copyToPlatformTexture(webContext(), t exture->object(), internalformat, type, 3562 if (gl && gl->drawingBuffer()->copyToPlatformTexture(webContext(), t exture->object(), internalformat, type,
3553 level, m_unpackPremultiplyAlpha, !m_unpackFlipY, DrawingBuffer:: Back)) { 3563 level, m_unpackPremultiplyAlpha, !m_unpackFlipY, DrawingBuffer:: Back)) {
3554 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type); 3564 texture->setLevelInfo(target, level, internalformat, canvas->wid th(), canvas->height(), type);
3555 return; 3565 return;
3556 } 3566 }
3557 } 3567 }
3558 } 3568 }
3559 3569
3560 RefPtrWillBeRawPtr<ImageData> imageData = canvas->getImageData(); 3570 texImage2DImpl(target, level, internalformat, format, type, canvas->copiedIm age(HTMLCanvasElement::Back), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY , m_unpackPremultiplyAlpha, exceptionState);
3561 if (imageData)
3562 texImage2D(target, level, internalformat, format, type, imageData.get(), exceptionState);
3563 else
3564 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremultip lyAlpha, exceptionState);
3565 } 3571 }
3566 3572
3567 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy) 3573 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy)
3568 { 3574 {
3569 IntSize size(video->videoWidth(), video->videoHeight()); 3575 IntSize size(video->videoWidth(), video->videoHeight());
3570 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size); 3576 ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
3571 if (!buf) { 3577 if (!buf) {
3572 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory"); 3578 synthesizeGLError(GL_OUT_OF_MEMORY, "texImage2D", "out of memory");
3573 return nullptr; 3579 return nullptr;
3574 } 3580 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha, exceptionState); 3794 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, imageForRen der.get(), WebGLImageConversion::HtmlDomImage, m_unpackFlipY, m_unpackPremultipl yAlpha, exceptionState);
3789 } 3795 }
3790 3796
3791 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 3797 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3792 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState) 3798 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep tionState)
3793 { 3799 {
3794 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 3800 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
3795 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset)) 3801 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, format, canvas->width(), canvas->height(), 0, format, type, xoffset, yoffset))
3796 return; 3802 return;
3797 3803
3798 RefPtrWillBeRawPtr<ImageData> imageData = canvas->getImageData(); 3804 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas->cop iedImage(HTMLCanvasElement::Back), WebGLImageConversion::HtmlDomCanvas, m_unpack FlipY, m_unpackPremultiplyAlpha, exceptionState);
3799 if (imageData)
3800 texSubImage2D(target, level, xoffset, yoffset, format, type, imageData.g et(), exceptionState);
3801 else
3802 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(), WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPrem ultiplyAlpha, exceptionState);
3803 } 3805 }
3804 3806
3805 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 3807 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
3806 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 3808 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
3807 { 3809 {
3808 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState) 3810 if (isContextLost() || !validateHTMLVideoElement("texSubImage2D", video, exc eptionState)
3809 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset)) 3811 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLVideoEleme nt, target, level, format, video->videoWidth(), video->videoHeight(), 0, format, type, xoffset, yoffset))
3810 return; 3812 return;
3811 3813
3812 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e()); 3814 RefPtr<Image> image = videoFrameToImage(video, ImageBuffer::fastCopyImageMod e());
(...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after
5806 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB uffer() : 0; 5808 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB uffer() : 0;
5807 } 5809 }
5808 #else 5810 #else
5809 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 5811 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
5810 { 5812 {
5811 return m_drawingBuffer.get(); 5813 return m_drawingBuffer.get();
5812 } 5814 }
5813 #endif 5815 #endif
5814 5816
5815 } // namespace blink 5817 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698