TiledBackingStoreBackendCairo.cpp [plain text]
#include "config.h"
#include "TiledBackingStoreBackend.h"
#if USE(TILED_BACKING_STORE) && USE(CAIRO)
#include "CairoUtilities.h"
#include "PlatformContextCairo.h"
#include "TileCairo.h"
#include <cairo.h>
namespace WebCore {
PassRefPtr<Tile> TiledBackingStoreBackend::createTile(TiledBackingStore* backingStore, const Tile::Coordinate& tileCoordinate)
{
return TileCairo::create(backingStore, tileCoordinate);
}
static const unsigned checkerSize = 16;
static const unsigned checkerColorDarkGrey = 0xff555555;
static const unsigned checkerColorLightGrey = 0xffaaaaaa;
static cairo_surface_t* checkeredSurface()
{
static cairo_surface_t* surface = 0;
if (surface)
return surface;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, checkerSize, checkerSize);
RefPtr<cairo_t> cr = adoptRef(cairo_create(surface));
unsigned halfCheckerSize = checkerSize / 2;
setSourceRGBAFromColor(cr.get(), checkerColorLightGrey);
cairo_rectangle(cr.get(), 0, 0, halfCheckerSize, halfCheckerSize);
cairo_rectangle(cr.get(), halfCheckerSize, halfCheckerSize, halfCheckerSize, halfCheckerSize);
cairo_fill(cr.get());
setSourceRGBAFromColor(cr.get(), checkerColorDarkGrey);
cairo_rectangle(cr.get(), halfCheckerSize, 0, halfCheckerSize, halfCheckerSize);
cairo_rectangle(cr.get(), 0, halfCheckerSize, halfCheckerSize, halfCheckerSize);
cairo_fill(cr.get());
return surface;
}
void TiledBackingStoreBackend::paintCheckerPattern(GraphicsContext* context, const FloatRect& target)
{
PlatformContextCairo* platformContext = context->platformContext();
cairo_t* cr = platformContext->cr();
cairo_set_source_surface(cr, checkeredSurface(), 0, 0);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
cairo_rectangle(cr, target.x(), target.y(), target.width(), target.height());
cairo_fill(cr);
}
}
#endif