NativeImageCairo.cpp [plain text]
#include "config.h"
#include "NativeImage.h"
#if USE(CAIRO)
#include "CairoUtilities.h"
#include "PlatformContextCairo.h"
#include <cairo.h>
namespace WebCore {
IntSize nativeImageSize(const NativeImagePtr& image)
{
return image ? cairoSurfaceSize(image.get()) : IntSize();
}
bool nativeImageHasAlpha(const NativeImagePtr& image)
{
return !image || cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
}
Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image)
{
if (!image || nativeImageSize(image) != IntSize(1, 1))
return Color();
if (cairo_surface_get_type(image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
return Color();
RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(image.get()));
return colorFromPremultipliedARGB(*pixel);
}
void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize&, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation)
{
context.save();
if (op == CompositeSourceOver && mode == BlendModeNormal && !nativeImageHasAlpha(image))
context.setCompositeOperation(CompositeCopy);
else
context.setCompositeOperation(op, mode);
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
IntSize scaledSize = nativeImageSize(image);
FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(srcRect, scaledSize);
#else
FloatRect adjustedSrcRect(srcRect);
#endif
FloatRect adjustedDestRect = destRect;
if (orientation != DefaultImageOrientation) {
context.translate(destRect.x(), destRect.y());
adjustedDestRect.setLocation(FloatPoint());
context.concatCTM(orientation.transformFromDefault(adjustedDestRect.size()));
if (orientation.usesWidthAsHeight()) {
adjustedDestRect.setSize(adjustedDestRect.size().transposedSize());
}
}
context.platformContext()->drawSurfaceToContext(image.get(), adjustedDestRect, adjustedSrcRect, context);
context.restore();
}
void clearNativeImageSubimages(const NativeImagePtr&)
{
}
}
#endif // USE(CAIRO)