BitmapCanvasLayerTextureUpdater.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "BitmapCanvasLayerTextureUpdater.h"
#include "LayerPainterChromium.h"
#include "PlatformColor.h"
#include "PlatformContextSkia.h"
namespace WebCore {
BitmapCanvasLayerTextureUpdater::Texture::Texture(BitmapCanvasLayerTextureUpdater* textureUpdater, PassOwnPtr<ManagedTexture> texture)
: LayerTextureUpdater::Texture(texture)
, m_textureUpdater(textureUpdater)
{
}
BitmapCanvasLayerTextureUpdater::Texture::~Texture()
{
}
void BitmapCanvasLayerTextureUpdater::Texture::updateRect(GraphicsContext3D* context, TextureAllocator* allocator, const IntRect& sourceRect, const IntRect& destRect)
{
textureUpdater()->updateTextureRect(context, allocator, texture(), sourceRect, destRect);
}
PassRefPtr<BitmapCanvasLayerTextureUpdater> BitmapCanvasLayerTextureUpdater::create(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSubImage)
{
return adoptRef(new BitmapCanvasLayerTextureUpdater(painter, useMapTexSubImage));
}
BitmapCanvasLayerTextureUpdater::BitmapCanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium> painter, bool useMapTexSubImage)
: CanvasLayerTextureUpdater(painter)
, m_texSubImage(useMapTexSubImage)
{
}
BitmapCanvasLayerTextureUpdater::~BitmapCanvasLayerTextureUpdater()
{
}
PassOwnPtr<LayerTextureUpdater::Texture> BitmapCanvasLayerTextureUpdater::createTexture(TextureManager* manager)
{
return adoptPtr(new Texture(this, ManagedTexture::create(manager)));
}
LayerTextureUpdater::SampledTexelFormat BitmapCanvasLayerTextureUpdater::sampledTexelFormat(GC3Denum textureFormat)
{
return PlatformColor::sameComponentOrder(textureFormat) ?
LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
}
void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect& resultingOpaqueRect)
{
m_texSubImage.setSubImageSize(tileSize);
bool layerIsOpaque = m_canvas.opaque();
m_canvas.resize(contentRect.size());
PlatformCanvas::Painter::TextOption textOption =
borderTexels ? PlatformCanvas::Painter::GrayscaleText : PlatformCanvas::Painter::SubpixelText;
PlatformCanvas::Painter canvasPainter(&m_canvas, textOption);
canvasPainter.skiaContext()->setTrackOpaqueRegion(!layerIsOpaque);
paintContents(*canvasPainter.context(), *canvasPainter.skiaContext(), contentRect, contentsScale, resultingOpaqueRect);
}
void BitmapCanvasLayerTextureUpdater::updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
PlatformCanvas::AutoLocker locker(&m_canvas);
texture->bindTexture(context, allocator);
m_texSubImage.upload(locker.pixels(), contentRect(), sourceRect, destRect, texture->format(), context);
}
void BitmapCanvasLayerTextureUpdater::setOpaque(bool opaque)
{
m_canvas.setOpaque(opaque);
}
} #endif // USE(ACCELERATED_COMPOSITING)