ImageLayerChromium.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "ImageLayerChromium.h"
#include "cc/CCLayerImpl.h"
#include "Image.h"
#include "LayerRendererChromium.h"
#include "LayerTexture.h"
namespace WebCore {
PassRefPtr<ImageLayerChromium> ImageLayerChromium::create(GraphicsLayerChromium* owner)
{
return adoptRef(new ImageLayerChromium(owner));
}
ImageLayerChromium::ImageLayerChromium(GraphicsLayerChromium* owner)
: ContentLayerChromium(owner)
, m_imageForCurrentFrame(0)
, m_contents(0)
{
}
void ImageLayerChromium::setContents(Image* contents)
{
if ((m_contents == contents) && (m_contents->nativeImageForCurrentFrame() == m_imageForCurrentFrame))
return;
m_contents = contents;
m_imageForCurrentFrame = m_contents->nativeImageForCurrentFrame();
m_dirtyRect = IntRect(IntPoint(0, 0), bounds());
setNeedsDisplay();
}
void ImageLayerChromium::paintContentsIfDirty(const IntRect&)
{
ASSERT(layerRenderer());
if (!m_dirtyRect.isEmpty()) {
m_decodedImage.updateFromImage(m_contents->nativeImageForCurrentFrame());
updateLayerSize(m_decodedImage.size());
IntRect paintRect(IntPoint(0, 0), m_decodedImage.size());
if (!m_dirtyRect.isEmpty()) {
m_tiler->invalidateRect(paintRect);
m_dirtyRect = IntRect();
}
}
}
void ImageLayerChromium::updateCompositorResources()
{
IntRect paintRect(IntPoint(0, 0), m_decodedImage.size());
m_tiler->updateFromPixels(paintRect, paintRect, m_decodedImage.pixels());
}
IntRect ImageLayerChromium::layerBounds() const
{
return IntRect(IntPoint(0, 0), m_decodedImage.size());
}
TransformationMatrix ImageLayerChromium::tilingTransform()
{
TransformationMatrix transform = ccLayerImpl()->drawTransform();
const IntRect sourceRect = layerBounds();
const IntSize destSize = bounds();
transform.translate(-destSize.width() / 2.0, -destSize.height() / 2.0);
float scaleX = destSize.width() / static_cast<float>(sourceRect.size().width());
float scaleY = destSize.height() / static_cast<float>(sourceRect.size().height());
transform.scale3d(scaleX, scaleY, 1.0f);
return transform;
}
}
#endif // USE(ACCELERATED_COMPOSITING)