diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/chromium/cc')
10 files changed, 613 insertions, 15 deletions
diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp new file mode 100644 index 0000000..649d049 --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2011 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 "cc/CCCanvasLayerImpl.h" + +#include "CanvasLayerChromium.h" +#include "GraphicsContext3D.h" +#include "LayerRendererChromium.h" +#include <wtf/text/WTFString.h> + +namespace WebCore { + +CCCanvasLayerImpl::CCCanvasLayerImpl(LayerChromium* owner) + : CCLayerImpl(owner) + , m_textureId(0) + , m_premultipliedAlpha(true) +{ +} + +CCCanvasLayerImpl::~CCCanvasLayerImpl() +{ +} + +void CCCanvasLayerImpl::draw() +{ + ASSERT(layerRenderer()); + const CCCanvasLayerImpl::Program* program = layerRenderer()->canvasLayerProgram(); + ASSERT(program && program->initialized()); + GraphicsContext3D* context = layerRenderer()->context(); + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); + GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId)); + GC3Denum sfactor = m_premultipliedAlpha ? GraphicsContext3D::ONE : GraphicsContext3D::SRC_ALPHA; + GLC(context, context->blendFunc(sfactor, GraphicsContext3D::ONE_MINUS_SRC_ALPHA)); + layerRenderer()->useShader(program->program()); + GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); + LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(), + bounds().width(), bounds().height(), drawOpacity(), + program->vertexShader().matrixLocation(), + program->fragmentShader().alphaLocation()); + +} + + +void CCCanvasLayerImpl::dumpLayerProperties(TextStream& ts, int indent) const +{ + writeIndent(ts, indent); + ts << "canvas layer texture id: " << m_textureId << " premultiplied: " << m_premultipliedAlpha << "\n"; + CCLayerImpl::dumpLayerProperties(ts, indent); +} + +} + +#endif // USE(ACCELERATED_COMPOSITING) + diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.h b/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.h new file mode 100644 index 0000000..8cbf8d1 --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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. + */ + +#ifndef CCCanvasLayerImpl_h +#define CCCanvasLayerImpl_h + +#include "ProgramBinding.h" +#include "ShaderChromium.h" +#include "cc/CCLayerImpl.h" + +namespace WebCore { + +class CCCanvasLayerImpl : public CCLayerImpl { +public: + static PassRefPtr<CCCanvasLayerImpl> create(LayerChromium* owner) + { + return adoptRef(new CCCanvasLayerImpl(owner)); + } + virtual ~CCCanvasLayerImpl(); + + typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexFlipAlpha> Program; + + virtual void draw(); + + virtual void dumpLayerProperties(TextStream&, int indent) const; + + void setTextureId(unsigned id) { m_textureId = id; } + void setPremultipliedAlpha(bool premultipliedAlpha) { m_premultipliedAlpha = premultipliedAlpha; } +private: + explicit CCCanvasLayerImpl(LayerChromium*); + + unsigned m_textureId; + bool m_premultipliedAlpha; +}; + +} + +#endif // CCCanvasLayerImpl_h + diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp index 604ef61..404944b 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp +++ b/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp @@ -66,8 +66,8 @@ void CCHeadsUpDisplay::draw() // Use a fullscreen texture only if we need to... IntSize hudSize; if (m_showPlatformLayerTree) { - hudSize.setWidth(min(2048, m_layerRenderer->visibleRectSize().width())); - hudSize.setHeight(min(2048, m_layerRenderer->visibleRectSize().height())); + hudSize.setWidth(min(2048, m_layerRenderer->viewportSize().width())); + hudSize.setHeight(min(2048, m_layerRenderer->viewportSize().height())); } else { hudSize.setWidth(512); hudSize.setHeight(128); diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h b/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h index dbac22a..d56f8ab 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h +++ b/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplay.h @@ -53,7 +53,7 @@ public: void setShowPlatformLayerTree(bool enable) { m_showPlatformLayerTree = enable; } bool showPlatformLayerTree() const { return m_showPlatformLayerTree; } - bool enabled() const { return true || m_showPlatformLayerTree || m_showFPSCounter; } + bool enabled() const { return m_showPlatformLayerTree || m_showFPSCounter; } void draw(); private: diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp index a0ad0fb..9411e5a 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp @@ -62,13 +62,18 @@ namespace WebCore { CCLayerImpl::CCLayerImpl(LayerChromium* owner) : m_owner(owner) + , m_anchorPoint(0.5, 0.5) + , m_anchorPointZ(0) + , m_doubleSided(true) + , m_masksToBounds(false) + , m_opacity(1.0) + , m_preserves3D(false) #ifndef NDEBUG , m_debugID(owner->debugID()) #endif , m_targetRenderSurface(0) , m_drawDepth(0) , m_drawOpacity(0) - , m_doubleSided(true) , m_debugBorderColor(0, 0, 0, 0) , m_debugBorderWidth(0) , m_renderSurface(0) @@ -107,7 +112,18 @@ RenderSurfaceChromium* CCLayerImpl::createRenderSurface() return m_renderSurface.get(); } -// These belong on CCLayerImpl, but should be subclased by each type and not defer to the LayerChromium subtypes. +bool CCLayerImpl::descendantsDrawsContent() +{ + const Vector<RefPtr<LayerChromium> >& sublayers = m_owner->getSublayers(); + for (size_t i = 0; i < sublayers.size(); ++i) { + sublayers[i]->createCCLayerImplIfNeeded(); + if (sublayers[i]->ccLayerImpl()->drawsContent() || sublayers[i]->ccLayerImpl()->descendantsDrawsContent()) + return true; + } + return false; +} + +// These belong on CCLayerImpl, but should be overridden by each type and not defer to the LayerChromium subtypes. bool CCLayerImpl::drawsContent() const { return m_owner->drawsContent(); @@ -118,6 +134,11 @@ void CCLayerImpl::draw() return m_owner->draw(); } +void CCLayerImpl::updateCompositorResources() +{ + return m_owner->updateCompositorResources(); +} + void CCLayerImpl::unreserveContentsTexture() { m_owner->unreserveContentsTexture(); @@ -167,7 +188,7 @@ void CCLayerImpl::drawDebugBorder() GLC(context, context->drawElements(GraphicsContext3D::LINE_LOOP, 4, GraphicsContext3D::UNSIGNED_SHORT, 6 * sizeof(unsigned short))); } -static void writeIndent(TextStream& ts, int indent) +void CCLayerImpl::writeIndent(TextStream& ts, int indent) { for (int i = 0; i != indent; ++i) ts << " "; diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h b/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h index 6892976..96c4f1b 100644 --- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h +++ b/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h @@ -49,7 +49,7 @@ public: return adoptRef(new CCLayerImpl(owner)); } // When this class gets subclasses, remember to add 'virtual' here. - ~CCLayerImpl(); + virtual ~CCLayerImpl(); #ifndef NDEBUG int debugID() const { return m_debugID; } @@ -59,13 +59,43 @@ public: CCLayerImpl* maskLayer() const; CCLayerImpl* replicaLayer() const; - void draw(); - bool drawsContent() const; + virtual void draw(); + virtual void updateCompositorResources(); void unreserveContentsTexture(); void bindContentsTexture(); + // Returns true if this layer has content to draw. + virtual bool drawsContent() const; + + // Returns true if any of the layer's descendants has content to draw. + bool descendantsDrawsContent(); + void cleanupResources(); + void setAnchorPoint(const FloatPoint& anchorPoint) { m_anchorPoint = anchorPoint; } + const FloatPoint& anchorPoint() const { return m_anchorPoint; } + + void setAnchorPointZ(float anchorPointZ) { m_anchorPointZ = anchorPointZ; } + float anchorPointZ() const { return m_anchorPointZ; } + + void setMasksToBounds(bool masksToBounds) { m_masksToBounds = masksToBounds; } + bool masksToBounds() const { return m_masksToBounds; } + + void setOpacity(float opacity) { m_opacity = opacity; } + float opacity() const { return m_opacity; } + + void setPosition(const FloatPoint& position) { m_position = position; } + const FloatPoint& position() const { return m_position; } + + void setPreserves3D(bool preserves3D) { m_preserves3D = preserves3D; } + bool preserves3D() const { return m_preserves3D; } + + void setSublayerTransform(const TransformationMatrix& sublayerTransform) { m_sublayerTransform = sublayerTransform; } + const TransformationMatrix& sublayerTransform() const { return m_sublayerTransform; } + + void setTransform(const TransformationMatrix& transform) { m_transform = transform; } + const TransformationMatrix& transform() const { return m_transform; } + void setName(const String& name) { m_name = name; } const String& name() const { return m_name; } @@ -108,11 +138,30 @@ public: virtual void dumpLayerProperties(TextStream&, int indent) const; -private: +protected: // For now, CCLayers are owned directly by a LayerChromium. LayerChromium* m_owner; explicit CCLayerImpl(LayerChromium*); + static void writeIndent(TextStream&, int indent); + +private: + // Properties synchronized from the associated LayerChromium. + FloatPoint m_anchorPoint; + float m_anchorPointZ; + IntSize m_bounds; + + // Whether the "back" of this layer should draw. + bool m_doubleSided; + + bool m_masksToBounds; + float m_opacity; + FloatPoint m_position; + bool m_preserves3D; + TransformationMatrix m_sublayerTransform; + TransformationMatrix m_transform; + + // Properties owned exclusively by this CCLayerImpl. // Debugging. #ifndef NDEBUG int m_debugID; @@ -131,17 +180,12 @@ private: float m_drawDepth; float m_drawOpacity; - // Whether the "back" of this layer should draw. - bool m_doubleSided; - // Debug borders. Color m_debugBorderColor; float m_debugBorderWidth; TransformationMatrix m_drawTransform; - IntSize m_bounds; - // The scissor rectangle that should be used when this layer is drawn. // Inherited by the parent layer and further restricted if this layer masks // to bounds. diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.cpp new file mode 100644 index 0000000..4aef639 --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2011 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 "cc/CCPluginLayerImpl.h" + +#include "GraphicsContext3D.h" +#include "LayerRendererChromium.h" +#include "PluginLayerChromium.h" +#include <wtf/text/WTFString.h> + +namespace WebCore { + +CCPluginLayerImpl::CCPluginLayerImpl(LayerChromium* owner) + : CCLayerImpl(owner) + , m_textureId(0) +{ +} + +CCPluginLayerImpl::~CCPluginLayerImpl() +{ +} + +void CCPluginLayerImpl::draw() +{ + ASSERT(layerRenderer()); + const CCPluginLayerImpl::Program* program = layerRenderer()->pluginLayerProgram(); + ASSERT(program && program->initialized()); + GraphicsContext3D* context = layerRenderer()->context(); + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); + GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId)); + + // FIXME: setting the texture parameters every time is redundant. Move this code somewhere + // where it will only happen once per texture. + GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); + GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); + GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); + GLC(context, context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); + + layerRenderer()->useShader(program->program()); + GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); + LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(), + bounds().width(), bounds().height(), drawOpacity(), + program->vertexShader().matrixLocation(), + program->fragmentShader().alphaLocation()); +} + + +void CCPluginLayerImpl::dumpLayerProperties(TextStream& ts, int indent) const +{ + writeIndent(ts, indent); + ts << "plugin layer texture id: " << m_textureId << "\n"; + CCLayerImpl::dumpLayerProperties(ts, indent); +} + +} + +#endif // USE(ACCELERATED_COMPOSITING) + diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.h b/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.h new file mode 100644 index 0000000..65eb5b7 --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCPluginLayerImpl.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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. + */ + +#ifndef CCPluginLayerImpl_h +#define CCPluginLayerImpl_h + +#include "ProgramBinding.h" +#include "ShaderChromium.h" +#include "cc/CCLayerImpl.h" + +namespace WebCore { + +class CCPluginLayerImpl : public CCLayerImpl { +public: + static PassRefPtr<CCPluginLayerImpl> create(LayerChromium* owner) + { + return adoptRef(new CCPluginLayerImpl(owner)); + } + virtual ~CCPluginLayerImpl(); + + typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexFlipAlpha> Program; + + virtual void draw(); + + virtual void dumpLayerProperties(TextStream&, int indent) const; + + void setTextureId(unsigned id) { m_textureId = id; } + +private: + explicit CCPluginLayerImpl(LayerChromium*); + + unsigned m_textureId; +}; + +} + +#endif // CCPluginLayerImpl_h + diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp b/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp new file mode 100644 index 0000000..eb3612b --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2011 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 "cc/CCVideoLayerImpl.h" + +#include "GraphicsContext3D.h" +#include "LayerRendererChromium.h" +#include "NotImplemented.h" +#include "VideoLayerChromium.h" +#include <wtf/text/WTFString.h> + +namespace WebCore { + +// These values are magic numbers that are used in the transformation +// from YUV to RGB color values. +// They are taken from the following webpage: +// http://www.fourcc.org/fccyvrgb.php +const float CCVideoLayerImpl::yuv2RGB[9] = { + 1.164f, 1.164f, 1.164f, + 0.f, -.391f, 2.018f, + 1.596f, -.813f, 0.f, +}; + +// These values map to 16, 128, and 128 respectively, and are computed +// as a fraction over 256 (e.g. 16 / 256 = 0.0625). +// They are used in the YUV to RGBA conversion formula: +// Y - 16 : Gives 16 values of head and footroom for overshooting +// U - 128 : Turns unsigned U into signed U [-128,127] +// V - 128 : Turns unsigned V into signed V [-128,127] +const float CCVideoLayerImpl::yuvAdjust[3] = { + -0.0625f, + -0.5f, + -0.5f, +}; + +CCVideoLayerImpl::CCVideoLayerImpl(LayerChromium* owner) + : CCLayerImpl(owner) +{ +} + +CCVideoLayerImpl::~CCVideoLayerImpl() +{ + cleanupResources(); +} + +void CCVideoLayerImpl::setTexture(size_t i, VideoLayerChromium::Texture texture) +{ + ASSERT(i < 3); + m_textures[i] = texture; +} + +void CCVideoLayerImpl::draw() +{ + if (m_skipsDraw) + return; + + ASSERT(layerRenderer()); + const RGBAProgram* rgbaProgram = layerRenderer()->videoLayerRGBAProgram(); + ASSERT(rgbaProgram && rgbaProgram->initialized()); + const YUVProgram* yuvProgram = layerRenderer()->videoLayerYUVProgram(); + ASSERT(yuvProgram && yuvProgram->initialized()); + + switch (m_frameFormat) { + case VideoFrameChromium::YV12: + case VideoFrameChromium::YV16: + drawYUV(yuvProgram); + break; + case VideoFrameChromium::RGBA: + drawRGBA(rgbaProgram); + break; + default: + // FIXME: Implement other paths. + notImplemented(); + break; + } +} + +void CCVideoLayerImpl::drawYUV(const CCVideoLayerImpl::YUVProgram* program) const +{ + GraphicsContext3D* context = layerRenderer()->context(); + VideoLayerChromium::Texture yTexture = m_textures[VideoFrameChromium::yPlane]; + VideoLayerChromium::Texture uTexture = m_textures[VideoFrameChromium::uPlane]; + VideoLayerChromium::Texture vTexture = m_textures[VideoFrameChromium::vPlane]; + + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE1)); + GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, yTexture.id)); + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE2)); + GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, uTexture.id)); + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE3)); + GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, vTexture.id)); + + layerRenderer()->useShader(program->program()); + + float yWidthScaleFactor = static_cast<float>(yTexture.visibleSize.width()) / yTexture.size.width(); + // Arbitrarily take the u sizes because u and v dimensions are identical. + float uvWidthScaleFactor = static_cast<float>(uTexture.visibleSize.width()) / uTexture.size.width(); + GLC(context, context->uniform1f(program->vertexShader().yWidthScaleFactorLocation(), yWidthScaleFactor)); + GLC(context, context->uniform1f(program->vertexShader().uvWidthScaleFactorLocation(), uvWidthScaleFactor)); + + GLC(context, context->uniform1i(program->fragmentShader().yTextureLocation(), 1)); + GLC(context, context->uniform1i(program->fragmentShader().uTextureLocation(), 2)); + GLC(context, context->uniform1i(program->fragmentShader().vTextureLocation(), 3)); + + GLC(context, context->uniformMatrix3fv(program->fragmentShader().ccMatrixLocation(), 0, const_cast<float*>(yuv2RGB), 1)); + GLC(context, context->uniform3fv(program->fragmentShader().yuvAdjLocation(), const_cast<float*>(yuvAdjust), 1)); + + LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(), + bounds().width(), bounds().height(), drawOpacity(), + program->vertexShader().matrixLocation(), + program->fragmentShader().alphaLocation()); + + // Reset active texture back to texture 0. + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); +} + +void CCVideoLayerImpl::drawRGBA(const CCVideoLayerImpl::RGBAProgram* program) const +{ + GraphicsContext3D* context = layerRenderer()->context(); + VideoLayerChromium::Texture texture = m_textures[VideoFrameChromium::rgbPlane]; + + GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); + GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, texture.id)); + + layerRenderer()->useShader(program->program()); + float widthScaleFactor = static_cast<float>(texture.visibleSize.width()) / texture.size.width(); + GLC(context, context->uniform4f(program->vertexShader().texTransformLocation(), 0, 0, widthScaleFactor, 1)); + + GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); + + LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(), + bounds().width(), bounds().height(), drawOpacity(), + program->vertexShader().matrixLocation(), + program->fragmentShader().alphaLocation()); +} + + +void CCVideoLayerImpl::dumpLayerProperties(TextStream& ts, int indent) const +{ + writeIndent(ts, indent); + ts << "video layer\n"; + CCLayerImpl::dumpLayerProperties(ts, indent); +} + +} + +#endif // USE(ACCELERATED_COMPOSITING) + diff --git a/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h b/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h new file mode 100644 index 0000000..62f8778 --- /dev/null +++ b/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2011 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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. + */ + +#ifndef CCVideoLayerImpl_h +#define CCVideoLayerImpl_h + +#include "ProgramBinding.h" +#include "ShaderChromium.h" +#include "VideoFrameChromium.h" +#include "VideoLayerChromium.h" +#include "cc/CCLayerImpl.h" + +namespace WebCore { + +class VideoFrameProvider; + +class CCVideoLayerImpl : public CCLayerImpl { +public: + static PassRefPtr<CCVideoLayerImpl> create(LayerChromium* owner) + { + return adoptRef(new CCVideoLayerImpl(owner)); + } + virtual ~CCVideoLayerImpl(); + + typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFlipAlpha> RGBAProgram; + typedef ProgramBinding<VertexShaderPosTexYUVStretch, FragmentShaderYUVVideo> YUVProgram; + + virtual void draw(); + + virtual void dumpLayerProperties(TextStream&, int indent) const; + + void setSkipsDraw(bool skipsDraw) { m_skipsDraw = skipsDraw; } + void setFrameFormat(VideoFrameChromium::Format format) { m_frameFormat = format; } + void setTexture(size_t, VideoLayerChromium::Texture); + +private: + explicit CCVideoLayerImpl(LayerChromium*); + + void drawYUV(const YUVProgram*) const; + void drawRGBA(const RGBAProgram*) const; + + static const float yuv2RGB[9]; + static const float yuvAdjust[3]; + + bool m_skipsDraw; + VideoFrameChromium::Format m_frameFormat; + VideoLayerChromium::Texture m_textures[3]; +}; + +} + +#endif // CCVideoLayerImpl_h + |