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

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: rebase 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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(DontP remultiplyAlpha);
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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 return false; 1779 return false;
1779 *value = toV8(imageData, m_scriptState->context()->Global(), isolate()); 1780 *value = toV8(imageData, m_scriptState->context()->Global(), isolate());
1780 return !value->IsEmpty(); 1781 return !value->IsEmpty();
1781 } 1782 }
1782 1783
1783 bool SerializedScriptValueReader::readImageBitmap(v8::Local<v8::Value>* value) 1784 bool SerializedScriptValueReader::readImageBitmap(v8::Local<v8::Value>* value)
1784 { 1785 {
1785 uint32_t isOriginClean; 1786 uint32_t isOriginClean;
1786 if (!doReadUint32(&isOriginClean)) 1787 if (!doReadUint32(&isOriginClean))
1787 return false; 1788 return false;
1789 uint32_t isPremultiplied;
1790 if (!doReadUint32(&isPremultiplied))
1791 return false;
1788 ImageData* imageData = doReadImageData(); 1792 ImageData* imageData = doReadImageData();
1789 if (!imageData) 1793 if (!imageData)
1790 return false; 1794 return false;
1791 ImageBitmapOptions options; 1795 ImageBitmapOptions options;
1792 options.setPremultiplyAlpha("none"); 1796 if (!isPremultiplied)
1793 ImageBitmap* imageBitmap = ImageBitmap::create(imageData, IntRect(0, 0, imag eData->width(), imageData->height()), options, true, isOriginClean); 1797 options.setPremultiplyAlpha("none");
1798 ImageBitmap* imageBitmap = ImageBitmap::create(imageData, IntRect(0, 0, imag eData->width(), imageData->height()), options, isOriginClean);
1794 if (!imageBitmap) 1799 if (!imageBitmap)
1795 return false; 1800 return false;
1796 *value = toV8(imageBitmap, m_scriptState->context()->Global(), isolate()); 1801 *value = toV8(imageBitmap, m_scriptState->context()->Global(), isolate());
1797 return !value->IsEmpty(); 1802 return !value->IsEmpty();
1798 } 1803 }
1799 1804
1800 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu e) 1805 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu e)
1801 { 1806 {
1802 uint32_t attributes; 1807 uint32_t attributes;
1803 uint64_t element; 1808 uint64_t element;
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 return false; 2447 return false;
2443 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1]; 2448 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe renceStack.size() - 1];
2444 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1); 2449 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - 1);
2445 if (objectReference >= m_objectPool.size()) 2450 if (objectReference >= m_objectPool.size())
2446 return false; 2451 return false;
2447 *object = m_objectPool[objectReference]; 2452 *object = m_objectPool[objectReference];
2448 return true; 2453 return true;
2449 } 2454 }
2450 2455
2451 } // namespace blink 2456 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698