NativeImageDirect2D.cpp [plain text]
#include "config.h"
#include "NativeImage.h"
#include "Color.h"
#include "FloatRect.h"
#include "GeometryUtilities.h"
#include "GraphicsContext.h"
#include "IntSize.h"
#include "NotImplemented.h"
#include <d2d1.h>
namespace WebCore {
IntSize nativeImageSize(const NativeImagePtr& image)
{
return image ? IntSize(image->GetSize()) : IntSize();
}
bool nativeImageHasAlpha(const NativeImagePtr& image)
{
if (!image)
return false;
auto alphaMode = image->GetPixelFormat().alphaMode;
return (alphaMode >= D2D1_ALPHA_MODE_PREMULTIPLIED) && (alphaMode <= D2D1_ALPHA_MODE_STRAIGHT);
}
Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image)
{
if (!image || nativeImageSize(image) != IntSize(1, 1))
return Color();
notImplemented();
return Color();
}
void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize& srcSize, CompositeOperator compositeOp, BlendMode blendMode, const ImageOrientation& orientation)
{
auto platformContext = context.platformContext();
IntSize subsampledImageSize = nativeImageSize(image);
FloatRect adjustedSrcRect = srcRect;
if (subsampledImageSize != srcSize)
adjustedSrcRect = mapRect(srcRect, FloatRect({ }, srcSize), FloatRect({ }, subsampledImageSize));
float opacity = 1.0f;
platformContext->DrawBitmap(image.get(), destRect, opacity, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, adjustedSrcRect);
context.flush();
}
void clearNativeImageSubimages(const NativeImagePtr& image)
{
notImplemented();
#if CACHE_SUBIMAGES
if (image)
subimageCache().clearImage(image.get());
#endif
}
}