|
Lines 66-78
namespace WebCore {
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec1
|
| 66 |
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ImageBuffer); |
66 |
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ImageBuffer); |
| 67 |
DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ImageBuffer); |
67 |
DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ImageBuffer); |
| 68 |
|
68 |
|
| 69 |
static FloatSize scaleSizeToUserSpace(const FloatSize& logicalSize, const IntSize& backingStoreSize, const IntSize& internalSize) |
|
|
| 70 |
{ |
| 71 |
float xMagnification = static_cast<float>(backingStoreSize.width()) / internalSize.width(); |
| 72 |
float yMagnification = static_cast<float>(backingStoreSize.height()) / internalSize.height(); |
| 73 |
return FloatSize(logicalSize.width() * xMagnification, logicalSize.height() * yMagnification); |
| 74 |
} |
| 75 |
|
| 76 |
std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, const GraphicsContext& context) |
69 |
std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, const GraphicsContext& context) |
| 77 |
{ |
70 |
{ |
| 78 |
if (size.isEmpty()) |
71 |
if (size.isEmpty()) |
|
Lines 155-161
ImageBuffer::ImageBuffer(const FloatSize
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec2
|
| 155 |
RetainPtr<CGContextRef> cgContext; |
148 |
RetainPtr<CGContextRef> cgContext; |
| 156 |
if (accelerateRendering) { |
149 |
if (accelerateRendering) { |
| 157 |
#if USE(IOSURFACE_CANVAS_BACKING_STORE) |
150 |
#if USE(IOSURFACE_CANVAS_BACKING_STORE) |
| 158 |
FloatSize userBounds = sizeForDestinationSize(FloatSize(width.unsafeGet(), height.unsafeGet())); |
151 |
FloatSize userBounds = FloatSize(width.unsafeGet(), height.unsafeGet()); |
| 159 |
m_data.surface = IOSurface::create(m_data.backingStoreSize, IntSize(userBounds), colorSpace); |
152 |
m_data.surface = IOSurface::create(m_data.backingStoreSize, IntSize(userBounds), colorSpace); |
| 160 |
if (m_data.surface) { |
153 |
if (m_data.surface) { |
| 161 |
cgContext = m_data.surface->ensurePlatformContext(hostWindow); |
154 |
cgContext = m_data.surface->ensurePlatformContext(hostWindow); |
|
Lines 210-220
ImageBuffer::ImageBuffer(const FloatSize
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec3
|
| 210 |
|
203 |
|
| 211 |
ImageBuffer::~ImageBuffer() = default; |
204 |
ImageBuffer::~ImageBuffer() = default; |
| 212 |
|
205 |
|
| 213 |
FloatSize ImageBuffer::sizeForDestinationSize(FloatSize destinationSize) const |
|
|
| 214 |
{ |
| 215 |
return scaleSizeToUserSpace(destinationSize, m_data.backingStoreSize, internalSize()); |
| 216 |
} |
| 217 |
|
| 218 |
#if USE(IOSURFACE_CANVAS_BACKING_STORE) |
206 |
#if USE(IOSURFACE_CANVAS_BACKING_STORE) |
| 219 |
size_t ImageBuffer::memoryCost() const |
207 |
size_t ImageBuffer::memoryCost() const |
| 220 |
{ |
208 |
{ |
|
Lines 259-265
static RetainPtr<CGImageRef> createCropp
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec4
|
| 259 |
return image; |
247 |
return image; |
| 260 |
} |
248 |
} |
| 261 |
|
249 |
|
| 262 |
static RefPtr<Image> createBitmapImageAfterScalingIfNeeded(RetainPtr<CGImageRef>&& image, IntSize internalSize, IntSize logicalSize, IntSize backingStoreSize, float resolutionScale, PreserveResolution preserveResolution) |
250 |
static RefPtr<Image> createBitmapImageAfterScalingIfNeeded(RetainPtr<CGImageRef>&& image, IntSize logicalSize, IntSize internalSize, float resolutionScale, PreserveResolution preserveResolution) |
| 263 |
{ |
251 |
{ |
| 264 |
if (resolutionScale == 1 || preserveResolution == PreserveResolution::Yes) |
252 |
if (resolutionScale == 1 || preserveResolution == PreserveResolution::Yes) |
| 265 |
image = createCroppedImageIfNecessary(image.get(), internalSize); |
253 |
image = createCroppedImageIfNecessary(image.get(), internalSize); |
|
Lines 267-273
static RefPtr<Image> createBitmapImageAf
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec5
|
| 267 |
auto context = adoptCF(CGBitmapContextCreate(0, logicalSize.width(), logicalSize.height(), 8, 4 * logicalSize.width(), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast)); |
255 |
auto context = adoptCF(CGBitmapContextCreate(0, logicalSize.width(), logicalSize.height(), 8, 4 * logicalSize.width(), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast)); |
| 268 |
CGContextSetBlendMode(context.get(), kCGBlendModeCopy); |
256 |
CGContextSetBlendMode(context.get(), kCGBlendModeCopy); |
| 269 |
CGContextClipToRect(context.get(), FloatRect(FloatPoint::zero(), logicalSize)); |
257 |
CGContextClipToRect(context.get(), FloatRect(FloatPoint::zero(), logicalSize)); |
| 270 |
FloatSize imageSizeInUserSpace = scaleSizeToUserSpace(logicalSize, backingStoreSize, internalSize); |
258 |
FloatSize imageSizeInUserSpace = logicalSize; |
| 271 |
CGContextDrawImage(context.get(), FloatRect(FloatPoint::zero(), imageSizeInUserSpace), image.get()); |
259 |
CGContextDrawImage(context.get(), FloatRect(FloatPoint::zero(), imageSizeInUserSpace), image.get()); |
| 272 |
image = adoptCF(CGBitmapContextCreateImage(context.get())); |
260 |
image = adoptCF(CGBitmapContextCreateImage(context.get())); |
| 273 |
} |
261 |
} |
|
Lines 286-307
RefPtr<Image> ImageBuffer::copyImage(Bac
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec6
|
| 286 |
else |
274 |
else |
| 287 |
image = copyNativeImage(DontCopyBackingStore); |
275 |
image = copyNativeImage(DontCopyBackingStore); |
| 288 |
|
276 |
|
| 289 |
return createBitmapImageAfterScalingIfNeeded(WTFMove(image), internalSize(), logicalSize(), m_data.backingStoreSize, m_resolutionScale, preserveResolution); |
277 |
return createBitmapImageAfterScalingIfNeeded(WTFMove(image), logicalSize(), internalSize(), m_resolutionScale, preserveResolution); |
| 290 |
} |
278 |
} |
| 291 |
|
279 |
|
| 292 |
RefPtr<Image> ImageBuffer::sinkIntoImage(std::unique_ptr<ImageBuffer> imageBuffer, PreserveResolution preserveResolution) |
280 |
RefPtr<Image> ImageBuffer::sinkIntoImage(std::unique_ptr<ImageBuffer> imageBuffer, PreserveResolution preserveResolution) |
| 293 |
{ |
281 |
{ |
| 294 |
IntSize internalSize = imageBuffer->internalSize(); |
282 |
IntSize internalSize = imageBuffer->internalSize(); |
| 295 |
IntSize logicalSize = imageBuffer->logicalSize(); |
283 |
IntSize logicalSize = imageBuffer->logicalSize(); |
| 296 |
IntSize backingStoreSize = imageBuffer->m_data.backingStoreSize; |
|
|
| 297 |
float resolutionScale = imageBuffer->m_resolutionScale; |
284 |
float resolutionScale = imageBuffer->m_resolutionScale; |
| 298 |
|
285 |
|
| 299 |
return createBitmapImageAfterScalingIfNeeded(sinkIntoNativeImage(WTFMove(imageBuffer)), internalSize, logicalSize, backingStoreSize, resolutionScale, preserveResolution); |
286 |
return createBitmapImageAfterScalingIfNeeded(sinkIntoNativeImage(WTFMove(imageBuffer)), logicalSize, internalSize, resolutionScale, preserveResolution); |
| 300 |
} |
|
|
| 301 |
|
| 302 |
BackingStoreCopy ImageBuffer::fastCopyImageMode() |
| 303 |
{ |
| 304 |
return DontCopyBackingStore; |
| 305 |
} |
287 |
} |
| 306 |
|
288 |
|
| 307 |
RetainPtr<CGImageRef> ImageBuffer::sinkIntoNativeImage(std::unique_ptr<ImageBuffer> imageBuffer) |
289 |
RetainPtr<CGImageRef> ImageBuffer::sinkIntoNativeImage(std::unique_ptr<ImageBuffer> imageBuffer) |
|
Lines 493-499
RetainPtr<CFDataRef> ImageBuffer::toCFDa
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp_sec7
|
| 493 |
auto context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast)); |
475 |
auto context = adoptCF(CGBitmapContextCreate(0, logicalSize().width(), logicalSize().height(), 8, 4 * logicalSize().width(), sRGBColorSpaceRef(), kCGImageAlphaPremultipliedLast)); |
| 494 |
CGContextSetBlendMode(context.get(), kCGBlendModeCopy); |
476 |
CGContextSetBlendMode(context.get(), kCGBlendModeCopy); |
| 495 |
CGContextClipToRect(context.get(), CGRectMake(0, 0, logicalSize().width(), logicalSize().height())); |
477 |
CGContextClipToRect(context.get(), CGRectMake(0, 0, logicalSize().width(), logicalSize().height())); |
| 496 |
FloatSize imageSizeInUserSpace = sizeForDestinationSize(logicalSize()); |
478 |
FloatSize imageSizeInUserSpace = logicalSize(); |
| 497 |
CGContextDrawImage(context.get(), CGRectMake(0, 0, imageSizeInUserSpace.width(), imageSizeInUserSpace.height()), image.get()); |
479 |
CGContextDrawImage(context.get(), CGRectMake(0, 0, imageSizeInUserSpace.width(), imageSizeInUserSpace.height()), image.get()); |
| 498 |
image = adoptCF(CGBitmapContextCreateImage(context.get())); |
480 |
image = adoptCF(CGBitmapContextCreateImage(context.get())); |
| 499 |
} |
481 |
} |