Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 doWriteUint32(pixelDataLength); | 305 doWriteUint32(pixelDataLength); |
| 306 append(pixelData, pixelDataLength); | 306 append(pixelData, pixelDataLength); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void SerializedScriptValueWriter::writeImageData(uint32_t width, uint32_t height , const uint8_t* pixelData, uint32_t pixelDataLength) | 309 void SerializedScriptValueWriter::writeImageData(uint32_t width, uint32_t height , const uint8_t* pixelData, uint32_t pixelDataLength) |
| 310 { | 310 { |
| 311 append(ImageDataTag); | 311 append(ImageDataTag); |
| 312 doWriteImageData(width, height, pixelData, pixelDataLength); | 312 doWriteImageData(width, height, pixelData, pixelDataLength); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void SerializedScriptValueWriter::writeImageBitmap(uint32_t width, uint32_t heig ht, uint32_t isOriginClean, const uint8_t* pixelData, uint32_t pixelDataLength) | 315 void SerializedScriptValueWriter::writeImageBitmap(uint32_t width, uint32_t heig ht, uint32_t isOriginClean, uint32_t isPremultiplied, const uint8_t* pixelData, uint32_t pixelDataLength) |
| 316 { | 316 { |
| 317 append(ImageBitmapTag); | 317 append(ImageBitmapTag); |
| 318 append(isOriginClean); | 318 append(isOriginClean); |
| 319 append(isPremultiplied); | |
| 319 doWriteImageData(width, height, pixelData, pixelDataLength); | 320 doWriteImageData(width, height, pixelData, pixelDataLength); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void SerializedScriptValueWriter::writeRegExp(v8::Local<v8::String> pattern, v8: :RegExp::Flags flags) | 323 void SerializedScriptValueWriter::writeRegExp(v8::Local<v8::String> pattern, v8: :RegExp::Flags flags) |
| 323 { | 324 { |
| 324 append(RegExpTag); | 325 append(RegExpTag); |
| 325 v8::String::Utf8Value patternUtf8Value(pattern); | 326 v8::String::Utf8Value patternUtf8Value(pattern); |
| 326 doWriteString(*patternUtf8Value, patternUtf8Value.length()); | 327 doWriteString(*patternUtf8Value, patternUtf8Value.length()); |
| 327 doWriteUint32(static_cast<uint32_t>(flags)); | 328 doWriteUint32(static_cast<uint32_t>(flags)); |
| 328 } | 329 } |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 if (!imageBitmap) | 1139 if (!imageBitmap) |
| 1139 return nullptr; | 1140 return nullptr; |
| 1140 if (imageBitmap->isNeutered()) | 1141 if (imageBitmap->isNeutered()) |
| 1141 return handleError(Status::DataCloneError, "An ImageBitmap is detached a nd could not be cloned.", next); | 1142 return handleError(Status::DataCloneError, "An ImageBitmap is detached a nd could not be cloned.", next); |
| 1142 | 1143 |
| 1143 uint32_t index; | 1144 uint32_t index; |
| 1144 if (m_transferredImageBitmaps.tryGet(object, &index)) { | 1145 if (m_transferredImageBitmaps.tryGet(object, &index)) { |
| 1145 m_writer.writeTransferredImageBitmap(index); | 1146 m_writer.writeTransferredImageBitmap(index); |
| 1146 } else { | 1147 } else { |
| 1147 greyObject(object); | 1148 greyObject(object); |
| 1148 std::unique_ptr<uint8_t[]> pixelData = imageBitmap->copyBitmapData(Premu ltiplyAlpha); | 1149 std::unique_ptr<uint8_t[]> pixelData = imageBitmap->copyBitmapData(image Bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); |
| 1149 m_writer.writeImageBitmap(imageBitmap->width(), imageBitmap->height(), s tatic_cast<uint32_t>(imageBitmap->originClean()), pixelData.get(), imageBitmap-> width() * imageBitmap->height() * 4); | 1150 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); |
| 1150 } | 1151 } |
| 1151 return nullptr; | 1152 return nullptr; |
| 1152 } | 1153 } |
| 1153 | 1154 |
| 1154 void ScriptValueSerializer::writeRegExp(v8::Local<v8::Value> value) | 1155 void ScriptValueSerializer::writeRegExp(v8::Local<v8::Value> value) |
| 1155 { | 1156 { |
| 1156 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); | 1157 v8::Local<v8::RegExp> regExp = value.As<v8::RegExp>(); |
| 1157 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); | 1158 m_writer.writeRegExp(regExp->GetSource(), regExp->GetFlags()); |
| 1158 } | 1159 } |
| 1159 | 1160 |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1741 | 1742 |
| 1742 bool SerializedScriptValueReader::readNumberObject(v8::Local<v8::Value>* value) | 1743 bool SerializedScriptValueReader::readNumberObject(v8::Local<v8::Value>* value) |
| 1743 { | 1744 { |
| 1744 double number; | 1745 double number; |
| 1745 if (!doReadNumber(&number)) | 1746 if (!doReadNumber(&number)) |
| 1746 return false; | 1747 return false; |
| 1747 *value = v8::NumberObject::New(isolate(), number); | 1748 *value = v8::NumberObject::New(isolate(), number); |
| 1748 return true; | 1749 return true; |
| 1749 } | 1750 } |
| 1750 | 1751 |
| 1751 // Helper function shared by readImageData and readImageBitmap | 1752 // Helper function used by readImageData and readImageBitmap. |
| 1752 ImageData* SerializedScriptValueReader::doReadImageData() | 1753 bool SerializedScriptValueReader::doReadImageDataProperties(uint32_t* width, uin t32_t* height, uint32_t* pixelDataLength) |
| 1754 { | |
| 1755 if (!doReadUint32(width)) | |
| 1756 return false; | |
| 1757 if (!doReadUint32(height)) | |
| 1758 return false; | |
| 1759 if (!doReadUint32(pixelDataLength)) | |
| 1760 return false; | |
| 1761 if (m_position + *pixelDataLength > m_length) | |
|
jbroman
2016/06/28 18:50:22
nit: Not introduced in this CL, but beware of over
xidachen
2016/06/29 12:58:35
Done.
| |
| 1762 return false; | |
| 1763 return true; | |
| 1764 } | |
| 1765 | |
| 1766 bool SerializedScriptValueReader::readImageData(v8::Local<v8::Value>* value) | |
| 1753 { | 1767 { |
| 1754 uint32_t width; | 1768 uint32_t width; |
| 1755 uint32_t height; | 1769 uint32_t height; |
| 1756 uint32_t pixelDataLength; | 1770 uint32_t pixelDataLength; |
| 1757 if (!doReadUint32(&width)) | 1771 if (!doReadImageDataProperties(&width, &height, &pixelDataLength)) |
| 1758 return nullptr; | 1772 return false; |
| 1759 if (!doReadUint32(&height)) | |
| 1760 return nullptr; | |
| 1761 if (!doReadUint32(&pixelDataLength)) | |
| 1762 return nullptr; | |
| 1763 if (m_position + pixelDataLength > m_length) | |
| 1764 return nullptr; | |
| 1765 ImageData* imageData = ImageData::create(IntSize(width, height)); | 1773 ImageData* imageData = ImageData::create(IntSize(width, height)); |
| 1766 DOMUint8ClampedArray* pixelArray = imageData->data(); | 1774 DOMUint8ClampedArray* pixelArray = imageData->data(); |
| 1767 ASSERT(pixelArray); | 1775 ASSERT(pixelArray); |
| 1768 ASSERT(pixelArray->length() >= pixelDataLength); | 1776 ASSERT(pixelArray->length() >= pixelDataLength); |
| 1769 memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength); | 1777 memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength); |
| 1770 m_position += pixelDataLength; | 1778 m_position += pixelDataLength; |
| 1771 return imageData; | |
| 1772 } | |
| 1773 | |
| 1774 bool SerializedScriptValueReader::readImageData(v8::Local<v8::Value>* value) | |
| 1775 { | |
| 1776 ImageData* imageData = doReadImageData(); | |
| 1777 if (!imageData) | 1779 if (!imageData) |
| 1778 return false; | 1780 return false; |
| 1779 *value = toV8(imageData, m_scriptState->context()->Global(), isolate()); | 1781 *value = toV8(imageData, m_scriptState->context()->Global(), isolate()); |
| 1780 return !value->IsEmpty(); | 1782 return !value->IsEmpty(); |
| 1781 } | 1783 } |
| 1782 | 1784 |
| 1783 bool SerializedScriptValueReader::readImageBitmap(v8::Local<v8::Value>* value) | 1785 bool SerializedScriptValueReader::readImageBitmap(v8::Local<v8::Value>* value) |
| 1784 { | 1786 { |
| 1785 uint32_t isOriginClean; | 1787 uint32_t isOriginClean; |
| 1786 if (!doReadUint32(&isOriginClean)) | 1788 if (!doReadUint32(&isOriginClean)) |
| 1787 return false; | 1789 return false; |
| 1788 ImageData* imageData = doReadImageData(); | 1790 uint32_t isPremultiplied; |
| 1789 if (!imageData) | 1791 if (!doReadUint32(&isPremultiplied)) |
| 1790 return false; | 1792 return false; |
| 1791 ImageBitmapOptions options; | 1793 uint32_t width; |
| 1792 options.setPremultiplyAlpha("none"); | 1794 uint32_t height; |
| 1793 ImageBitmap* imageBitmap = ImageBitmap::create(imageData, IntRect(0, 0, imag eData->width(), imageData->height()), options, true, isOriginClean); | 1795 uint32_t pixelDataLength; |
| 1796 if (!doReadImageDataProperties(&width, &height, &pixelDataLength)) | |
| 1797 return false; | |
| 1798 std::unique_ptr<uint8_t[]> pixelData = wrapArrayUnique(new uint8_t[pixelData Length]); | |
| 1799 DCHECK(pixelData); | |
|
jbroman
2016/06/28 18:50:21
DCHECK isn't necessary here; the renderer will cra
xidachen
2016/06/29 12:58:35
Done.
| |
| 1800 memcpy(pixelData.get(), m_buffer + m_position, pixelDataLength); | |
| 1801 m_position += pixelDataLength; | |
| 1802 ImageBitmap* imageBitmap = ImageBitmap::create(std::move(pixelData), width, height, isPremultiplied, isOriginClean); | |
| 1794 if (!imageBitmap) | 1803 if (!imageBitmap) |
| 1795 return false; | 1804 return false; |
| 1796 *value = toV8(imageBitmap, m_scriptState->context()->Global(), isolate()); | 1805 *value = toV8(imageBitmap, m_scriptState->context()->Global(), isolate()); |
| 1797 return !value->IsEmpty(); | 1806 return !value->IsEmpty(); |
| 1798 } | 1807 } |
| 1799 | 1808 |
| 1800 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu e) | 1809 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu e) |
| 1801 { | 1810 { |
| 1802 uint32_t attributes; | 1811 uint32_t attributes; |
| 1803 uint64_t element; | 1812 uint64_t element; |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2442 return false; | 2451 return false; |
| 2443 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; | 2452 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; |
| 2444 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); | 2453 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); |
| 2445 if (objectReference >= m_objectPool.size()) | 2454 if (objectReference >= m_objectPool.size()) |
| 2446 return false; | 2455 return false; |
| 2447 *object = m_objectPool[objectReference]; | 2456 *object = m_objectPool[objectReference]; |
| 2448 return true; | 2457 return true; |
| 2449 } | 2458 } |
| 2450 | 2459 |
| 2451 } // namespace blink | 2460 } // namespace blink |
| OLD | NEW |