Modified: branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (283142 => 283143)
--- branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2021-09-27 22:30:45 UTC (rev 283142)
+++ branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2021-09-27 22:49:21 UTC (rev 283143)
@@ -4933,7 +4933,7 @@
}
// Fallback pure SW path.
- RefPtr<Image> image = videoFrameToImage(video.get(), DontCopyBackingStore, functionName);
+ RefPtr<Image> image = videoFrameToImage(video.get(), DontCopyBackingStore);
if (!image)
return { };
texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zoffset, format, type, image.get(), GraphicsContextGL::DOMSource::Video, m_unpackFlipY, m_unpackPremultiplyAlpha, false, inputSourceImageRect, depth, unpackImageHeight);
@@ -5767,44 +5767,18 @@
#if ENABLE(VIDEO)
-RefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy, const char* functionName)
+RefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video, BackingStoreCopy backingStoreCopy)
{
-#if USE(AVFOUNDATION)
- auto nativeImage = video->nativeImageForCurrentTime();
- // Currently we might be missing an image due to MSE not being able to provide the first requested frame.
- // https://bugs.webkit.org/show_bug.cgi?id=228997
- if (!nativeImage)
+ IntSize size(video->videoWidth(), video->videoHeight());
+ ImageBuffer* buf = m_generatedImageCache.imageBuffer(size);
+ if (!buf) {
+ synthesizeGLError(GraphicsContextGL::OUT_OF_MEMORY, "texImage2D", "out of memory");
return nullptr;
- IntSize imageSize = nativeImage->size();
- if (imageSize.isEmpty()) {
- synthesizeGLError(GraphicsContextGL::INVALID_VALUE, functionName, "video visible size is empty");
- return nullptr;
}
- FloatRect imageRect { { }, imageSize };
- ImageBuffer* imageBuffer = m_generatedImageCache.imageBuffer(imageSize, CompositeOperator::Copy);
- if (!imageBuffer) {
- synthesizeGLError(GraphicsContextGL::OUT_OF_MEMORY, functionName, "out of memory");
- return nullptr;
- }
- imageBuffer->context().drawNativeImage(*nativeImage, imageRect.size(), imageRect, imageRect, CompositeOperator::Copy);
-#else
- // This is a legacy code path that produces incompatible texture size when the
- // video visible size is different to the natural size. This should be removed
- // once all platforms implement nativeImageForCurrentTime().
- IntSize videoSize { static_cast<int>(video->videoWidth()), static_cast<int>(video->videoHeight()) };
- ImageBuffer* imageBuffer = m_generatedImageCache.imageBuffer(videoSize);
- if (!imageBuffer) {
- synthesizeGLError(GraphicsContextGL::OUT_OF_MEMORY, functionName, "out of memory");
- return nullptr;
- }
- video->paintCurrentFrameInContext(imageBuffer->context(), { { }, videoSize });
-#endif
- RefPtr<Image> image = imageBuffer->copyImage(backingStoreCopy);
- if (!image) {
- synthesizeGLError(GraphicsContextGL::OUT_OF_MEMORY, functionName, "out of memory");
- return nullptr;
- }
- return image;
+ FloatRect destRect(0, 0, size.width(), size.height());
+ // FIXME: Turn this into a GPU-GPU texture copy instead of CPU readback.
+ video->paintCurrentFrameInContext(buf->context(), destRect);
+ return buf->copyImage(backingStoreCopy);
}
#endif
@@ -7645,7 +7619,7 @@
{
}
-ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const IntSize& size, CompositeOperator fillOperator)
+ImageBuffer* WebGLRenderingContextBase::LRUImageBufferCache::imageBuffer(const IntSize& size)
{
size_t i;
for (i = 0; i < m_buffers.size(); ++i) {
@@ -7655,8 +7629,7 @@
if (buf->logicalSize() != size)
continue;
bubbleToFront(i);
- if (fillOperator != CompositeOperator::Copy && fillOperator != CompositeOperator::Clear)
- buf->context().clearRect({ { }, size });
+ buf->context().clearRect(FloatRect({ }, FloatSize(size)));
return buf;
}
Modified: branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (283142 => 283143)
--- branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h 2021-09-27 22:30:45 UTC (rev 283142)
+++ branches/safari-612-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.h 2021-09-27 22:49:21 UTC (rev 283143)
@@ -524,7 +524,7 @@
RefPtr<Image> drawImageIntoBuffer(Image&, int width, int height, int deviceScaleFactor, const char* functionName);
#if ENABLE(VIDEO)
- RefPtr<Image> videoFrameToImage(HTMLVideoElement*, BackingStoreCopy, const char* functionName);
+ RefPtr<Image> videoFrameToImage(HTMLVideoElement*, BackingStoreCopy);
#endif
WebGLTexture::TextureExtensionFlag textureExtensionFlags() const;
@@ -614,9 +614,8 @@
class LRUImageBufferCache {
public:
LRUImageBufferCache(int capacity);
- // Returns pointer to a cleared image buffer that is owned by the cache. The pointer is valid until next call.
- // Using fillOperator == CompositeOperator::Copy can be used to omit the clear of the buffer.
- ImageBuffer* imageBuffer(const IntSize&, CompositeOperator fillOperator = CompositeOperator::SourceOver);
+ // The pointer returned is owned by the image buffer map.
+ ImageBuffer* imageBuffer(const IntSize& size);
private:
void bubbleToFront(size_t idx);
Vector<RefPtr<ImageBuffer>> m_buffers;