示例#1
0
bool GraphicsContext::isCompatibleWithBuffer(ImageBuffer* buffer) const
{
    AffineTransform localTransform = getCTM();
    AffineTransform bufferTransform = buffer->context()->getCTM();

    if (localTransform.xScale() != bufferTransform.xScale() || localTransform.yScale() != bufferTransform.yScale())
        return false;

    if (isAcceleratedContext() != buffer->context()->isAcceleratedContext())
        return false;

    return true;
}
示例#2
0
bool GraphicsContext::isCompatibleWithBuffer(ImageBuffer& buffer) const
{
    GraphicsContext& bufferContext = buffer.context();

    return scalesMatch(getCTM(), bufferContext.getCTM()) && isAcceleratedContext() == bufferContext.isAcceleratedContext();
}
PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& size) const
{
    // Make the buffer larger if the context's transform is scaling it so we need a higher
    // resolution than one pixel per unit. Also set up a corresponding scale factor on the
    // graphics context.

    AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale);
    IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())), static_cast<int>(ceil(size.height() * transform.yScale())));

    OwnPtr<ImageBuffer> buffer = ImageBuffer::create(scaledSize, 1, ColorSpaceDeviceRGB, isAcceleratedContext() ? Accelerated : Unaccelerated);
    if (!buffer)
        return nullptr;

    buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) / size.width(),
        static_cast<float>(scaledSize.height()) / size.height()));

    return buffer.release();
}