FrameBufferSkPictureCanvasLayerTextureUpdater.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "FrameBufferSkPictureCanvasLayerTextureUpdater.h"
#include "LayerPainterChromium.h"
#include "SkCanvas.h"
#include "SkGpuDevice.h"
namespace WebCore {
static PassOwnPtr<SkCanvas> createAcceleratedCanvas(GraphicsContext3D* context,
TextureAllocator* allocator,
ManagedTexture* texture)
{
texture->allocate(allocator);
GrContext* grContext = context->grContext();
IntSize canvasSize = texture->size();
GrPlatformTextureDesc textureDesc;
textureDesc.fFlags = kRenderTarget_GrPlatformTextureFlag;
textureDesc.fWidth = canvasSize.width();
textureDesc.fHeight = canvasSize.height();
textureDesc.fConfig = kSkia8888_PM_GrPixelConfig;
textureDesc.fTextureHandle = texture->textureId();
SkAutoTUnref<GrTexture> target(grContext->createPlatformTexture(textureDesc));
SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get()));
return adoptPtr(new SkCanvas(device.get()));
}
FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::Texture(FrameBufferSkPictureCanvasLayerTextureUpdater* textureUpdater, PassOwnPtr<ManagedTexture> texture)
: LayerTextureUpdater::Texture(texture)
, m_textureUpdater(textureUpdater)
{
}
FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::~Texture()
{
}
void FrameBufferSkPictureCanvasLayerTextureUpdater::Texture::updateRect(GraphicsContext3D* context, TextureAllocator* allocator, const IntRect& sourceRect, const IntRect& destRect)
{
textureUpdater()->updateTextureRect(context, allocator, texture(), sourceRect, destRect);
}
PassRefPtr<FrameBufferSkPictureCanvasLayerTextureUpdater> FrameBufferSkPictureCanvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter)
{
return adoptRef(new FrameBufferSkPictureCanvasLayerTextureUpdater(painter));
}
FrameBufferSkPictureCanvasLayerTextureUpdater::FrameBufferSkPictureCanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium> painter)
: SkPictureCanvasLayerTextureUpdater(painter)
{
}
FrameBufferSkPictureCanvasLayerTextureUpdater::~FrameBufferSkPictureCanvasLayerTextureUpdater()
{
}
PassOwnPtr<LayerTextureUpdater::Texture> FrameBufferSkPictureCanvasLayerTextureUpdater::createTexture(TextureManager* manager)
{
return adoptPtr(new Texture(this, ManagedTexture::create(manager)));
}
LayerTextureUpdater::SampledTexelFormat FrameBufferSkPictureCanvasLayerTextureUpdater::sampledTexelFormat(GC3Denum textureFormat)
{
return LayerTextureUpdater::SampledTexelFormatRGBA;
}
void FrameBufferSkPictureCanvasLayerTextureUpdater::updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
context->makeContextCurrent();
context->grContext()->resetContext();
OwnPtr<SkCanvas> canvas = createAcceleratedCanvas(context, allocator, texture);
canvas->translate(0.0, texture->size().height());
canvas->scale(1.0, -1.0);
canvas->clipRect(SkRect(destRect));
canvas->translate(contentRect().x() - sourceRect.x() + destRect.x(),
contentRect().y() - sourceRect.y() + destRect.y());
drawPicture(canvas.get());
context->grContext()->flush();
}
} #endif // USE(ACCELERATED_COMPOSITING)