Chromium Code Reviews| Index: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp |
| diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp |
| index 15e865745b7ee9132c25e35a5e7ef7e1f0fef61d..4ceada226b4acdee72db4c5734bfa47316c1c7cf 100644 |
| --- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp |
| +++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp |
| @@ -1526,7 +1526,29 @@ ImageData* BaseRenderingContext2D::createImageData( |
| if (size.height() < 1) |
| size.setHeight(1); |
| - ImageData* result = ImageData::create(size); |
| + ImageData* result = nullptr; |
| + if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && |
| + RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| + ImageDataColorSettings colorSettings; |
| + colorSettings.setColorSpace(renderingContext()->colorSpaceAsString()); |
|
Justin Novosad
2017/03/27 19:43:48
Hmmm... so createImageData inherits the setting fr
zakerinasab
2017/03/30 17:56:11
I'll do.
|
| + switch (renderingContext()->pixelFormat()) { |
| + case kRGBA8CanvasPixelFormat: |
| + colorSettings.setStorageFormat(kUint8ClampedArrayStorageFormatName); |
| + break; |
| + case kF16CanvasPixelFormat: |
| + colorSettings.setStorageFormat(kFloat32ArrayStorageFormatName); |
| + break; |
| + case kRGB10A2CanvasPixelFormat: |
| + case kRGBA12CanvasPixelFormat: |
| + default: |
| + NOTREACHED(); |
| + } |
| + LOG(ERROR) << "In createImageData: " << colorSettings.colorSpace() << ", " |
| + << colorSettings.storageFormat(); |
| + result = ImageData::create(size, &colorSettings); |
| + } else { |
| + result = ImageData::create(size); |
| + } |
| if (!result) |
| exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| return result; |
| @@ -1538,6 +1560,8 @@ ImageData* BaseRenderingContext2D::getImageData( |
| double sw, |
| double sh, |
| ExceptionState& exceptionState) const { |
| + LOG(ERROR) << renderingContext()->colorSpaceAsString(); |
| + LOG(ERROR) << renderingContext()->pixelFormatAsString(); |
|
Justin Novosad
2017/03/27 19:43:48
I See a lot of error logging in this file that loo
zakerinasab
2017/03/30 17:56:11
This was a work in progress. Removed now.
|
| m_usageCounters.numGetImageDataCalls++; |
| m_usageCounters.areaGetImageDataCalls += sw * sh; |
| if (!originClean()) |
| @@ -1589,10 +1613,38 @@ ImageData* BaseRenderingContext2D::getImageData( |
| timer.emplace(scopedUsCounterCPU); |
| } |
| + ImageDataColorSettings colorSettings; |
| + LOG(ERROR) << "Default: " << colorSettings.colorSpace() << ", " |
| + << colorSettings.storageFormat(); |
| + bool canvasIsColorManaged = |
| + RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && |
| + RuntimeEnabledFeatures::colorCorrectRenderingEnabled(); |
| + if (canvasIsColorManaged) { |
| + colorSettings.setColorSpace(renderingContext()->colorSpaceAsString()); |
| + switch (renderingContext()->pixelFormat()) { |
| + case kRGBA8CanvasPixelFormat: |
| + colorSettings.setStorageFormat(kUint8ClampedArrayStorageFormatName); |
| + break; |
| + case kF16CanvasPixelFormat: |
| + colorSettings.setStorageFormat(kFloat32ArrayStorageFormatName); |
| + break; |
| + case kRGB10A2CanvasPixelFormat: |
| + case kRGBA12CanvasPixelFormat: |
| + default: |
| + NOTREACHED(); |
| + } |
| + LOG(ERROR) << "Set: " << colorSettings.colorSpace() << ", " |
| + << colorSettings.storageFormat(); |
| + } |
| + |
| IntRect imageDataRect = enclosingIntRect(logicalRect); |
| ImageBuffer* buffer = imageBuffer(); |
| if (!buffer || isContextLost()) { |
| - ImageData* result = ImageData::create(imageDataRect.size()); |
| + ImageData* result = nullptr; |
| + if (canvasIsColorManaged) |
| + result = ImageData::create(imageDataRect.size(), &colorSettings); |
| + else |
| + result = ImageData::create(imageDataRect.size()); |
| if (!result) |
| exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| return result; |
| @@ -1604,7 +1656,46 @@ ImageData* BaseRenderingContext2D::getImageData( |
| return nullptr; |
| } |
| - DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents); |
| + DOMArrayBuffer* arrayBuffer = nullptr; |
| + DOMArrayBufferView* arrayBufferView = nullptr; |
| + DOMFloat32Array* dataArray = nullptr; |
| + |
| + LOG(ERROR) << "HERE"; |
| + if (canvasIsColorManaged) { |
| + LOG(ERROR) << "Canvas is color managed"; |
| + ImageDataStorageFormat storageFormat = |
| + ImageData::getImageDataStorageFormat(colorSettings.storageFormat()); |
| + switch (storageFormat) { |
| + case kUint8ClampedArrayStorageFormat: |
| + arrayBuffer = DOMArrayBuffer::create(contents); |
| + return ImageData::create( |
| + imageDataRect.size(), |
| + DOMUint8ClampedArray::create(arrayBuffer, 0, |
| + arrayBuffer->byteLength())); |
| + break; |
| + case kUint16ArrayStorageFormat: |
| + NOTREACHED(); |
| + break; |
| + case kFloat32ArrayStorageFormat: |
| + LOG(ERROR) << "kFloat32ArrayStorageFormat"; |
| + arrayBufferView = ImageData:: |
| + convertPixelsFromCanvasPixelFormatToImageDataStorageFormat( |
| + contents, renderingContext()->pixelFormat(), storageFormat); |
| + LOG(ERROR) << (void*)(arrayBufferView); |
| + LOG(ERROR) << arrayBufferView->byteLength(); |
| + LOG(ERROR) << arrayBufferView->typeSize(); |
| + dataArray = const_cast<DOMFloat32Array*>( |
| + static_cast<const DOMFloat32Array*>(arrayBufferView)); |
| + return ImageData::create(imageDataRect.size(), arrayBufferView, |
| + &colorSettings); |
| + default: |
| + NOTREACHED(); |
| + } |
| + return nullptr; |
| + } |
| + LOG(ERROR) << "NOT color managed canvas"; |
| + |
| + arrayBuffer = DOMArrayBuffer::create(contents); |
| return ImageData::create( |
| imageDataRect.size(), |
| DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())); |
| @@ -1683,10 +1774,16 @@ void BaseRenderingContext2D::putImageData(ImageData* data, |
| checkOverdraw(destRect, 0, CanvasRenderingContext2DState::NoImage, |
| UntransformedUnclippedFill); |
| - buffer->putByteArray(Unmultiplied, data->data()->data(), |
| - IntSize(data->width(), data->height()), sourceRect, |
| - IntPoint(destOffset)); |
| - |
| + unsigned char* source = data->data()->data(); |
| + if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && |
| + RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| + source = data->getImageDataInCanvasColorSettings( |
| + renderingContext()->colorSpace(), renderingContext()->pixelFormat()); |
| + } else { |
| + buffer->putByteArray(Unmultiplied, source, |
| + IntSize(data->width(), data->height()), sourceRect, |
| + IntPoint(destOffset)); |
| + } |
| didDraw(destRect); |
| } |