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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 1781613002: Fix data race problem in createImageBitmap(Blob) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
10 #include "platform/image-decoders/ImageDecoder.h" 10 #include "platform/image-decoders/ImageDecoder.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return newSkImageFromRaster(info, imagePixels.release(), imageRowBytes); 82 return newSkImageFromRaster(info, imagePixels.release(), imageRowBytes);
83 } 83 }
84 84
85 static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input) 85 static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input)
86 { 86 {
87 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S kColorType, kUnpremul_SkAlphaType); 87 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S kColorType, kUnpremul_SkAlphaType);
88 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info); 88 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info);
89 return newSkImageFromRaster(info, dstPixels.release(), input->width() * info .bytesPerPixel()); 89 return newSkImageFromRaster(info, dstPixels.release(), input->width() * info .bytesPerPixel());
90 } 90 }
91 91
92 PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(PassOwnPtr<ImageDecoder> decoder) 92 PassRefPtr<SkImage> getSkImageFromDecoder(PassOwnPtr<ImageDecoder> decoder)
93 { 93 {
94 if (!decoder->frameCount()) 94 if (!decoder->frameCount())
95 return nullptr; 95 return nullptr;
96 ImageFrame* frame = decoder->frameBufferAtIndex(0); 96 ImageFrame* frame = decoder->frameBufferAtIndex(0);
97 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) 97 if (!frame || frame->getStatus() != ImageFrame::FrameComplete)
98 return nullptr; 98 return nullptr;
99 SkBitmap bitmap = frame->bitmap(); 99 SkBitmap bitmap = frame->bitmap();
100 if (!frameIsValid(bitmap)) 100 if (!frameIsValid(bitmap))
101 return nullptr; 101 return nullptr;
102 return adoptRef(SkImage::NewFromBitmap(bitmap)); 102 return adoptRef(SkImage::NewFromBitmap(bitmap));
(...skipping 17 matching lines...) Expand all
120 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); 120 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame();
121 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied. 121 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied.
122 if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-> data() && alphaOp == DontPremultiplyAlpha) { 122 if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-> data() && alphaOp == DontPremultiplyAlpha) {
123 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion 123 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion
124 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( 124 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(
125 *(image->data()), ImageDecoder::AlphaNotPremultiplied, 125 *(image->data()), ImageDecoder::AlphaNotPremultiplied,
126 ImageDecoder::GammaAndColorProfileApplied)); 126 ImageDecoder::GammaAndColorProfileApplied));
127 if (!decoder) 127 if (!decoder)
128 return nullptr; 128 return nullptr;
129 decoder->setData(image->data(), true); 129 decoder->setData(image->data(), true);
130 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release()); 130 skiaImage = getSkImageFromDecoder(decoder.release());
131 if (!skiaImage) 131 if (!skiaImage)
132 return nullptr; 132 return nullptr;
133 } 133 }
134 134
135 if (cropRect == srcRect) { 135 if (cropRect == srcRect) {
136 if (flipY) 136 if (flipY)
137 return StaticBitmapImage::create(flipSkImageVertically(skiaImage->ne wSubset(srcRect), premultiplyAlpha ? PremultiplyAlpha : DontPremultiplyAlpha)); 137 return StaticBitmapImage::create(flipSkImageVertically(skiaImage->ne wSubset(srcRect), premultiplyAlpha ? PremultiplyAlpha : DontPremultiplyAlpha));
138 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect)) ); 138 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect)) );
139 } 139 }
140 140
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 FloatSize ImageBitmap::elementSize(const FloatSize&) const 446 FloatSize ImageBitmap::elementSize(const FloatSize&) const
447 { 447 {
448 return FloatSize(width(), height()); 448 return FloatSize(width(), height());
449 } 449 }
450 450
451 DEFINE_TRACE(ImageBitmap) 451 DEFINE_TRACE(ImageBitmap)
452 { 452 {
453 } 453 }
454 454
455 } // namespace blink 455 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698