/* * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved. * Copyright (C) 2010 Google Inc. All rights reserved. * Copyright (C) 2007, 2008, 2009 Apple 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 "LayerCompositingThread.h" #include "LayerMessage.h" #include "LayerRenderer.h" #include "LayerWebKitThread.h" #if ENABLE(VIDEO) #include "MediaPlayer.h" #include "MediaPlayerPrivateBlackBerry.h" #endif #include "PluginView.h" #include "TextureCacheCompositingThread.h" #include #include #include #define DEBUG_VIDEO_CLIPPING 0 namespace WebCore { PassRefPtr LayerCompositingThread::create(LayerType type, PassRefPtr tiler) { return adoptRef(new LayerCompositingThread(type, tiler)); } LayerCompositingThread::LayerCompositingThread(LayerType type, PassRefPtr tiler) : LayerData(type) , m_layerRenderer(0) , m_superlayer(0) , m_pluginBuffer(0) , m_drawOpacity(0) , m_visible(false) , m_commitScheduled(false) , m_tiler(tiler) { } LayerCompositingThread::~LayerCompositingThread() { ASSERT(isCompositingThread()); m_tiler->layerCompositingThreadDestroyed(); ASSERT(!superlayer()); // Remove the superlayer reference from all sublayers. while (m_sublayers.size()) m_sublayers[0]->removeFromSuperlayer(); // Delete all allocated textures deleteTextures(); // We just deleted all our textures, no need for the // layer renderer to track us anymore if (m_layerRenderer) m_layerRenderer->removeLayer(this); } void LayerCompositingThread::setLayerRenderer(LayerRenderer* renderer) { // It's not expected that layers will ever switch renderers. ASSERT(!renderer || !m_layerRenderer || renderer == m_layerRenderer); m_layerRenderer = renderer; if (m_layerRenderer) m_layerRenderer->addLayer(this); } void LayerCompositingThread::deleteTextures() { releaseTextureResources(); m_tiler->deleteTextures(); } void LayerCompositingThread::setDrawTransform(const TransformationMatrix& matrix) { m_drawTransform = matrix; float bx = m_bounds.width() / 2.0; float by = m_bounds.height() / 2.0; m_transformedBounds.setP1(matrix.mapPoint(FloatPoint(-bx, -by))); m_transformedBounds.setP2(matrix.mapPoint(FloatPoint(-bx, by))); m_transformedBounds.setP3(matrix.mapPoint(FloatPoint(bx, by))); m_transformedBounds.setP4(matrix.mapPoint(FloatPoint(bx, -by))); m_drawRect = m_transformedBounds.boundingBox(); } static FloatQuad getTransformedRect(const IntSize& bounds, const IntRect& rect, const TransformationMatrix& drawTransform) { float x = -bounds.width() / 2.0 + rect.x(); float y = -bounds.height() / 2.0 + rect.y(); float w = rect.width(); float h = rect.height(); FloatQuad result; result.setP1(drawTransform.mapPoint(FloatPoint(x, y))); result.setP2(drawTransform.mapPoint(FloatPoint(x, y + h))); result.setP3(drawTransform.mapPoint(FloatPoint(x + w, y + h))); result.setP4(drawTransform.mapPoint(FloatPoint(x + w, y))); return result; } FloatQuad LayerCompositingThread::getTransformedHolePunchRect() const { // FIXME: the following line disables clipping a video in an iframe i.e. the fix associated with PR 99638. // Some revised test case (e.g. video-iframe.html) show that the original fix works correctly when scrolling // the contents of the frame, but fails to clip correctly if the page (main frame) is scrolled. static bool enableVideoClipping = false; if (!mediaPlayer() || !enableVideoClipping) { // m_holePunchClipRect is valid only when there's a media player. return getTransformedRect(m_bounds, m_holePunchRect, m_drawTransform); } // The hole punch rectangle may need to be clipped, // e.g. if the