Index: third_party/WebKit/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp |
diff --git a/third_party/WebKit/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp b/third_party/WebKit/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1bc53047088689d73685fc4c40909e8bfaf6e357 |
--- /dev/null |
+++ b/third_party/WebKit/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp |
@@ -0,0 +1,132 @@ |
+/* |
+ * Copyright (C) 2010 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+ |
+#if USE(ACCELERATED_COMPOSITING) |
+#include "VideoLayerChromium.h" |
+ |
+#include "RenderLayerBacking.h" |
+#include "VideoFrameChromium.h" |
+#include "VideoFrameProvider.h" |
+ |
+#include <GLES2/gl2.h> |
+#define GL_GLEXT_PROTOTYPES |
+#include <GLES2/gl2ext.h> |
+ |
+namespace WebCore { |
+ |
+PassRefPtr<VideoLayerChromium> VideoLayerChromium::create(GraphicsLayerChromium* owner, |
+ VideoFrameProvider* provider) |
+{ |
+ return adoptRef(new VideoLayerChromium(owner, provider)); |
+} |
+ |
+VideoLayerChromium::VideoLayerChromium(GraphicsLayerChromium* owner, VideoFrameProvider* provider) |
+ : LayerChromium(owner) |
+ , m_allocatedTextureId(0) |
+ , m_provider(provider) |
+{ |
+} |
+ |
+void VideoLayerChromium::updateTextureContents(unsigned textureId) |
+{ |
+ RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->client()); |
+ if (!backing || backing->paintingGoesToWindow()) |
+ return; |
+ |
+ ASSERT(drawsContent()); |
+ |
+ VideoFrameChromium* frame = 0; |
+ IntRect dirtyRect(m_dirtyRect); |
+ IntSize requiredTextureSize; |
+ |
+ requiredTextureSize = m_bounds; |
+ IntRect boundsRect(IntPoint(0, 0), m_bounds); |
+ |
+ // If the texture needs to be reallocated, then we must redraw the entire |
+ // contents of the layer. |
+ if (requiredTextureSize != m_allocatedTextureSize) |
+ dirtyRect = boundsRect; |
+ else { |
+ // Clip the dirtyRect to the size of the layer to avoid drawing outside |
+ // the bounds of the backing texture. |
+ dirtyRect.intersect(boundsRect); |
+ } |
+ |
+ m_provider->getCurrentFrame(&frame); |
+ if (frame) { |
+ // If the texture id or size changed since last time, then we need to tell GL |
+ // to re-allocate a texture. |
+ if (m_allocatedTextureId != textureId || requiredTextureSize != m_allocatedTextureSize) |
+ createTextureRect(frame, requiredTextureSize, dirtyRect, textureId); |
+ else |
+ updateTextureRect(frame, dirtyRect, textureId); |
+ } |
+ m_provider->putCurrentFrame(frame); |
+} |
+ |
+void VideoLayerChromium::createTextureRect(VideoFrameChromium* frame, const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId) |
+{ |
+ ASSERT(frame); |
+ void* pixels = frame->data(VideoFrameChromium::kYPlane); |
+ IntSize bitmapSize; |
+ bitmapSize = IntSize(frame->width(), frame->height()); |
+ ASSERT(bitmapSize == requiredTextureSize); |
+ |
+ glBindTexture(GL_TEXTURE_2D, textureId); |
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, frame->width(), frame->height(), 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); |
+ |
+ m_allocatedTextureId = textureId; |
+ m_allocatedTextureSize = requiredTextureSize; |
+ |
+ updateCompleted(); |
+} |
+ |
+void VideoLayerChromium::updateTextureRect(VideoFrameChromium* frame, const IntRect& updateRect, unsigned textureId) |
+{ |
+ ASSERT(frame); |
+ |
+ glBindTexture(GL_TEXTURE_2D, textureId); |
+ void* mem = glMapTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_WRITE_ONLY); |
+ memcpy(mem, frame->data(VideoFrameChromium::kYPlane), frame->height() * frame->width()); |
+ glUnmapTexSubImage2D(mem); |
+ |
+ updateCompleted(); |
+} |
+ |
+void VideoLayerChromium::updateCompleted() |
+{ |
+ m_dirtyRect.setSize(FloatSize()); |
+ m_contentsDirty = false; |
+} |
+ |
+} |
+#endif // USE(ACCELERATED_COMPOSITING) |