Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 2425113002: Fix the linear-rgb canvas color space so that it renders (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "platform/graphics/gpu/DrawingBuffer.h" 47 #include "platform/graphics/gpu/DrawingBuffer.h"
48 #include "platform/graphics/gpu/Extensions3DUtil.h" 48 #include "platform/graphics/gpu/Extensions3DUtil.h"
49 #include "platform/graphics/skia/SkiaUtils.h" 49 #include "platform/graphics/skia/SkiaUtils.h"
50 #include "platform/image-encoders/JPEGImageEncoder.h" 50 #include "platform/image-encoders/JPEGImageEncoder.h"
51 #include "platform/image-encoders/PNGImageEncoder.h" 51 #include "platform/image-encoders/PNGImageEncoder.h"
52 #include "platform/image-encoders/WEBPImageEncoder.h" 52 #include "platform/image-encoders/WEBPImageEncoder.h"
53 #include "public/platform/Platform.h" 53 #include "public/platform/Platform.h"
54 #include "public/platform/WebGraphicsContext3DProvider.h" 54 #include "public/platform/WebGraphicsContext3DProvider.h"
55 #include "skia/ext/texture_handle.h" 55 #include "skia/ext/texture_handle.h"
56 #include "third_party/skia/include/core/SkPicture.h" 56 #include "third_party/skia/include/core/SkPicture.h"
57 #include "third_party/skia/include/core/SkSwizzle.h"
57 #include "third_party/skia/include/gpu/GrContext.h" 58 #include "third_party/skia/include/gpu/GrContext.h"
58 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" 59 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
59 #include "wtf/CheckedNumeric.h" 60 #include "wtf/CheckedNumeric.h"
60 #include "wtf/MathExtras.h" 61 #include "wtf/MathExtras.h"
61 #include "wtf/PtrUtil.h" 62 #include "wtf/PtrUtil.h"
62 #include "wtf/Vector.h" 63 #include "wtf/Vector.h"
63 #include "wtf/text/Base64.h" 64 #include "wtf/text/Base64.h"
64 #include "wtf/text/WTFString.h" 65 #include "wtf/text/WTFString.h"
65 #include "wtf/typed_arrays/ArrayBufferContents.h" 66 #include "wtf/typed_arrays/ArrayBufferContents.h"
66 #include <memory> 67 #include <memory>
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy = 374 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy =
374 mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize 375 mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize
375 : WTF::ArrayBufferContents::DontInitialize; 376 : WTF::ArrayBufferContents::DontInitialize;
376 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, 377 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes,
377 initializationPolicy, data); 378 initializationPolicy, data);
378 if (!data) 379 if (!data)
379 return false; 380 return false;
380 WTF::ArrayBufferContents result(data, allocSizeInBytes, 381 WTF::ArrayBufferContents result(data, allocSizeInBytes,
381 WTF::ArrayBufferContents::NotShared); 382 WTF::ArrayBufferContents::NotShared);
382 383
383 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType 384 // Skia does not support unpremultiplied read with an F16 to 8888 conversion
384 : kUnpremul_SkAlphaType; 385 bool useF16Workaround = m_surface->colorType() == kRGBA_F16_SkColorType;
385 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), 386
386 kRGBA_8888_SkColorType, alphaType); 387 SkAlphaType alphaType = (multiplied == Premultiplied || useF16Workaround)
388 ? kPremul_SkAlphaType
389 : kUnpremul_SkAlphaType;
390 // The workaround path use a canvas draw under the hood, which can only
391 // use N32 at this time.
392 SkColorType colorType =
393 useF16Workaround ? kN32_SkColorType : kRGBA_8888_SkColorType;
394 SkImageInfo info =
395 SkImageInfo::Make(rect.width(), rect.height(), colorType, alphaType,
396 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
387 397
388 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), 398 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(),
389 rect.y()); 399 rect.y());
400
zakerinasab 2016/10/18 15:12:42 When creating the SkImageInfo the color space is s
Justin Novosad 2016/10/18 17:02:41 Right now, sRGB is the assumed color spece of Imag
401 if (useF16Workaround) {
402 uint32_t* pixel = (uint32_t*)result.data();
403 size_t pixelCount = allocSizeInBytes / sizeof(uint32_t);
404 // TODO(skbug.com/5853): make readPixels support RGBA output so that we no
405 // longer
406 // have to do this.
407 if (kN32_SkColorType == kBGRA_8888_SkColorType) {
408 // Convert BGRA to RGBA if necessary on this platform.
409 SkSwapRB(pixel, pixel, pixelCount);
410 }
411 // TODO(skbug.com/5853): We should really be doing the unpremultiply in
412 // linear space
413 // and skia should provide that service.
414 if (multiplied == Unmultiplied) {
415 for (; pixelCount; --pixelCount) {
416 *pixel = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(*pixel);
417 ++pixel;
418 }
419 }
420 }
421
390 result.transfer(contents); 422 result.transfer(contents);
391 return true; 423 return true;
392 } 424 }
393 425
394 void ImageBuffer::putByteArray(Multiply multiplied, 426 void ImageBuffer::putByteArray(Multiply multiplied,
395 const unsigned char* source, 427 const unsigned char* source,
396 const IntSize& sourceSize, 428 const IntSize& sourceSize,
397 const IntRect& sourceRect, 429 const IntRect& sourceRect,
398 const IntPoint& destPoint) { 430 const IntPoint& destPoint) {
399 if (!isSurfaceValid()) 431 if (!isSurfaceValid())
(...skipping 13 matching lines...) Expand all
413 int destY = destPoint.y() + sourceRect.y(); 445 int destY = destPoint.y() + sourceRect.y();
414 ASSERT(destY >= 0); 446 ASSERT(destY >= 0);
415 ASSERT(destY < m_surface->size().height()); 447 ASSERT(destY < m_surface->size().height());
416 ASSERT(originY >= 0); 448 ASSERT(originY >= 0);
417 ASSERT(originY < sourceRect.maxY()); 449 ASSERT(originY < sourceRect.maxY());
418 450
419 const size_t srcBytesPerRow = 4 * sourceSize.width(); 451 const size_t srcBytesPerRow = 4 * sourceSize.width();
420 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; 452 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4;
421 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType 453 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
422 : kUnpremul_SkAlphaType; 454 : kUnpremul_SkAlphaType;
423 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height(), 455 SkImageInfo info = SkImageInfo::Make(
424 kRGBA_8888_SkColorType, alphaType); 456 sourceRect.width(), sourceRect.height(), kRGBA_8888_SkColorType,
457 alphaType, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
458
425 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); 459 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
426 } 460 }
427 461
428 void ImageBuffer::updateGPUMemoryUsage() const { 462 void ImageBuffer::updateGPUMemoryUsage() const {
429 if (this->isAccelerated()) { 463 if (this->isAccelerated()) {
430 // If image buffer is accelerated, we should keep track of GPU memory usage. 464 // If image buffer is accelerated, we should keep track of GPU memory usage.
431 int gpuBufferCount = 2; 465 int gpuBufferCount = 2;
432 CheckedNumeric<intptr_t> checkedGPUUsage = 4 * gpuBufferCount; 466 CheckedNumeric<intptr_t> checkedGPUUsage = 4 * gpuBufferCount;
433 checkedGPUUsage *= this->size().width(); 467 checkedGPUUsage *= this->size().width();
434 checkedGPUUsage *= this->size().height(); 468 checkedGPUUsage *= this->size().height();
(...skipping 14 matching lines...) Expand all
449 m_gpuMemoryUsage = 0; 483 m_gpuMemoryUsage = 0;
450 } 484 }
451 } 485 }
452 486
453 class UnacceleratedSurfaceFactory 487 class UnacceleratedSurfaceFactory
454 : public RecordingImageBufferFallbackSurfaceFactory { 488 : public RecordingImageBufferFallbackSurfaceFactory {
455 public: 489 public:
456 virtual std::unique_ptr<ImageBufferSurface> createSurface( 490 virtual std::unique_ptr<ImageBufferSurface> createSurface(
457 const IntSize& size, 491 const IntSize& size,
458 OpacityMode opacityMode, 492 OpacityMode opacityMode,
459 sk_sp<SkColorSpace> colorSpace) { 493 sk_sp<SkColorSpace> colorSpace,
494 SkColorType colorType) {
460 return wrapUnique(new UnacceleratedImageBufferSurface( 495 return wrapUnique(new UnacceleratedImageBufferSurface(
461 size, opacityMode, InitializeImagePixels, colorSpace)); 496 size, opacityMode, InitializeImagePixels, std::move(colorSpace),
497 colorType));
462 } 498 }
463 499
464 virtual ~UnacceleratedSurfaceFactory() {} 500 virtual ~UnacceleratedSurfaceFactory() {}
465 }; 501 };
466 502
467 void ImageBuffer::disableAcceleration() { 503 void ImageBuffer::disableAcceleration() {
468 if (!isAccelerated()) 504 if (!isAccelerated())
469 return; 505 return;
470 506
471 sk_sp<SkImage> image = 507 sk_sp<SkImage> image =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 552 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
517 553
518 Vector<unsigned char> result; 554 Vector<unsigned char> result;
519 if (!encodeImage(mimeType, quality, &result)) 555 if (!encodeImage(mimeType, quality, &result))
520 return "data:,"; 556 return "data:,";
521 557
522 return "data:" + mimeType + ";base64," + base64Encode(result); 558 return "data:" + mimeType + ";base64," + base64Encode(result);
523 } 559 }
524 560
525 } // namespace blink 561 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698