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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp

Issue 2039983002: Change code path for structured cloning ImageBitmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/ScriptValueSerializer.h" 5 #include "bindings/core/v8/ScriptValueSerializer.h"
6 6
7 #include "bindings/core/v8/Transferables.h" 7 #include "bindings/core/v8/Transferables.h"
8 #include "bindings/core/v8/V8ArrayBuffer.h" 8 #include "bindings/core/v8/V8ArrayBuffer.h"
9 #include "bindings/core/v8/V8ArrayBufferView.h" 9 #include "bindings/core/v8/V8ArrayBufferView.h"
10 #include "bindings/core/v8/V8Blob.h" 10 #include "bindings/core/v8/V8Blob.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 doWriteUint32(pixelDataLength); 320 doWriteUint32(pixelDataLength);
321 append(pixelData, pixelDataLength); 321 append(pixelData, pixelDataLength);
322 } 322 }
323 323
324 void SerializedScriptValueWriter::writeImageData(uint32_t width, uint32_t height , const uint8_t* pixelData, uint32_t pixelDataLength) 324 void SerializedScriptValueWriter::writeImageData(uint32_t width, uint32_t height , const uint8_t* pixelData, uint32_t pixelDataLength)
325 { 325 {
326 append(ImageDataTag); 326 append(ImageDataTag);
327 doWriteImageData(width, height, pixelData, pixelDataLength); 327 doWriteImageData(width, height, pixelData, pixelDataLength);
328 } 328 }
329 329
330 void SerializedScriptValueWriter::writeImageBitmap(uint32_t width, uint32_t heig ht, uint32_t isOriginClean, const uint8_t* pixelData, uint32_t pixelDataLength) 330 void SerializedScriptValueWriter::writeImageBitmap(uint32_t width, uint32_t heig ht, uint32_t isOriginClean, uint32_t isPremultiplied, const uint8_t* pixelData, uint32_t pixelDataLength)
331 { 331 {
332 append(ImageBitmapTag); 332 append(ImageBitmapTag);
333 append(isOriginClean); 333 append(isOriginClean);
334 append(isPremultiplied);
334 doWriteImageData(width, height, pixelData, pixelDataLength); 335 doWriteImageData(width, height, pixelData, pixelDataLength);
335 } 336 }
336 337
337 void SerializedScriptValueWriter::writeRegExp(v8::Local<v8::String> pattern, v8: :RegExp::Flags flags) 338 void SerializedScriptValueWriter::writeRegExp(v8::Local<v8::String> pattern, v8: :RegExp::Flags flags)
338 { 339 {
339 append(RegExpTag); 340 append(RegExpTag);
340 v8::String::Utf8Value patternUtf8Value(pattern); 341 v8::String::Utf8Value patternUtf8Value(pattern);
341 doWriteString(*patternUtf8Value, patternUtf8Value.length()); 342 doWriteString(*patternUtf8Value, patternUtf8Value.length());
342 doWriteUint32(static_cast<uint32_t>(flags)); 343 doWriteUint32(static_cast<uint32_t>(flags));
343 } 344 }
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 if (!imageBitmap) 1101 if (!imageBitmap)
1101 return nullptr; 1102 return nullptr;
1102 if (imageBitmap->isNeutered()) 1103 if (imageBitmap->isNeutered())
1103 return handleError(Status::DataCloneError, "An ImageBitmap is detached a nd could not be cloned.", next); 1104 return handleError(Status::DataCloneError, "An ImageBitmap is detached a nd could not be cloned.", next);
1104 1105
1105 uint32_t index; 1106 uint32_t index;
1106 if (m_transferredImageBitmaps.tryGet(object, &index)) { 1107 if (m_transferredImageBitmaps.tryGet(object, &index)) {
1107 m_writer.writeTransferredImageBitmap(index); 1108 m_writer.writeTransferredImageBitmap(index);
1108 } else { 1109 } else {
1109 greyObject(object); 1110 greyObject(object);
1110 std::unique_ptr<uint8_t[]> pixelData = imageBitmap->copyBitmapData(Premu ltiplyAlpha); 1111 std::unique_ptr<uint8_t[]> pixelData = imageBitmap->copyBitmapData(image Bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha, N32ColorTyp e);
1111 m_writer.writeImageBitmap(imageBitmap->width(), imageBitmap->height(), s tatic_cast<uint32_t>(imageBitmap->originClean()), pixelData.get(), imageBitmap-> width() * imageBitmap->height() * 4); 1112 m_writer.writeImageBitmap(imageBitmap->width(), imageBitmap->height(), s tatic_cast<uint32_t>(imageBitmap->originClean()), static_cast<uint32_t>(imageBit map->isPremultiplied()), pixelData.get(), imageBitmap->width() * imageBitmap->he ight() * 4);
1112 } 1113 }
1113 return nullptr; 1114 return nullptr;
1114 } 1115 }
1115 1116
1116 void ScriptValueSerializer::writeRegExp(v8::Local<v8::Value> value) 1117 void ScriptValueSerializer::writeRegExp(v8::Local<v8::Value> value)
1117 { 1118 {
1118 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); 1119 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>();
1119 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); 1120 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags());
1120 } 1121 }
1121 1122
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 1705
1705 bool SerializedScriptValueReader::readNumberObject(v8::Local<v8::Value>* value) 1706 bool SerializedScriptValueReader::readNumberObject(v8::Local<v8::Value>* value)
1706 { 1707 {
1707 double number; 1708 double number;
1708 if (!doReadNumber(&number)) 1709 if (!doReadNumber(&number))
1709 return false; 1710 return false;
1710 *value = v8::NumberObject::New(isolate(), number); 1711 *value = v8::NumberObject::New(isolate(), number);
1711 return true; 1712 return true;
1712 } 1713 }
1713 1714
1714 // Helper function shared by readImageData and readImageBitmap 1715 // Helper function used by readImageData and readImageBitmap.
1715 ImageData* SerializedScriptValueReader::doReadImageData() 1716 bool SerializedScriptValueReader::doReadImageDataProperties(uint32_t* width, uin t32_t* height, uint32_t* pixelDataLength)
1717 {
1718 if (!doReadUint32(width))
1719 return false;
1720 if (!doReadUint32(height))
1721 return false;
1722 if (!doReadUint32(pixelDataLength))
1723 return false;
1724 if (m_length - m_position < *pixelDataLength)
1725 return false;
1726 return true;
1727 }
1728
1729 bool SerializedScriptValueReader::readImageData(v8::Local<v8::Value>* value)
1716 { 1730 {
1717 uint32_t width; 1731 uint32_t width;
1718 uint32_t height; 1732 uint32_t height;
1719 uint32_t pixelDataLength; 1733 uint32_t pixelDataLength;
1720 if (!doReadUint32(&width)) 1734 if (!doReadImageDataProperties(&width, &height, &pixelDataLength))
1721 return nullptr; 1735 return false;
1722 if (!doReadUint32(&height))
1723 return nullptr;
1724 if (!doReadUint32(&pixelDataLength))
1725 return nullptr;
1726 if (m_position + pixelDataLength > m_length)
1727 return nullptr;
1728 ImageData* imageData = ImageData::create(IntSize(width, height)); 1736 ImageData* imageData = ImageData::create(IntSize(width, height));
1729 DOMUint8ClampedArray* pixelArray = imageData->data(); 1737 DOMUint8ClampedArray* pixelArray = imageData->data();
1730 ASSERT(pixelArray); 1738 ASSERT(pixelArray);
1731 ASSERT(pixelArray->length() >= pixelDataLength); 1739 ASSERT(pixelArray->length() >= pixelDataLength);
1732 memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength); 1740 memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength);
1733 m_position += pixelDataLength; 1741 m_position += pixelDataLength;
1734 return imageData;
1735 }
1736
1737 bool SerializedScriptValueReader::readImageData(v8::Local<v8::Value>* value)
1738 {
1739 ImageData* imageData = doReadImageData();
1740 if (!imageData) 1742 if (!imageData)
1741 return false; 1743 return false;
1742 *value = toV8(imageData, m_scriptState->context()->Global(), isolate()); 1744 *value = toV8(imageData, m_scriptState->context()->Global(), isolate());
1743 return !value->IsEmpty(); 1745 return !value->IsEmpty();
1744 } 1746 }
1745 1747
1746 bool SerializedScriptValueReader::readImageBitmap(v8::Local<v8::Value>* value) 1748 bool SerializedScriptValueReader::readImageBitmap(v8::Local<v8::Value>* value)
1747 { 1749 {
1748 uint32_t isOriginClean; 1750 uint32_t isOriginClean;
1749 if (!doReadUint32(&isOriginClean)) 1751 if (!doReadUint32(&isOriginClean))
1750 return false; 1752 return false;
1751 ImageData* imageData = doReadImageData(); 1753 uint32_t isPremultiplied;
1752 if (!imageData) 1754 if (!doReadUint32(&isPremultiplied))
1753 return false; 1755 return false;
1754 ImageBitmapOptions options; 1756 uint32_t width;
1755 options.setPremultiplyAlpha("none"); 1757 uint32_t height;
1756 ImageBitmap* imageBitmap = ImageBitmap::create(imageData, IntRect(0, 0, imag eData->width(), imageData->height()), options, true, isOriginClean); 1758 uint32_t pixelDataLength;
1759 if (!doReadImageDataProperties(&width, &height, &pixelDataLength))
1760 return false;
1761 std::unique_ptr<uint8_t[]> pixelData = wrapArrayUnique(new uint8_t[pixelData Length]);
1762 memcpy(pixelData.get(), m_buffer + m_position, pixelDataLength);
1763 m_position += pixelDataLength;
1764 ImageBitmap* imageBitmap = ImageBitmap::create(std::move(pixelData), width, height, isPremultiplied, isOriginClean);
1757 if (!imageBitmap) 1765 if (!imageBitmap)
1758 return false; 1766 return false;
1759 *value = toV8(imageBitmap, m_scriptState->context()->Global(), isolate()); 1767 *value = toV8(imageBitmap, m_scriptState->context()->Global(), isolate());
1760 return !value->IsEmpty(); 1768 return !value->IsEmpty();
1761 } 1769 }
1762 1770
1763 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu e) 1771 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu e)
1764 { 1772 {
1765 uint32_t attributes; 1773 uint32_t attributes;
1766 uint64_t element; 1774 uint64_t element;
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 return false; 2413 return false;
2406 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; 2414 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1];
2407 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); 2415 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1);
2408 if (objectReference >= m_objectPool.size()) 2416 if (objectReference >= m_objectPool.size())
2409 return false; 2417 return false;
2410 *object = m_objectPool[objectReference]; 2418 *object = m_objectPool[objectReference];
2411 return true; 2419 return true;
2412 } 2420 }
2413 2421
2414 } // namespace blink 2422 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698