Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/graphics/skia/SkiaUtils.h" | 10 #include "platform/graphics/skia/SkiaUtils.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // canvas is always premultiplied, so set the last parameter to true and con vert to un-premul later | 251 // canvas is always premultiplied, so set the last parameter to true and con vert to un-premul later |
| 252 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get( ), cropRect, flipY, true); | 252 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get( ), cropRect, flipY, true); |
| 253 if (!m_image) | 253 if (!m_image) |
| 254 return; | 254 return; |
| 255 if (!premultiplyAlpha) | 255 if (!premultiplyAlpha) |
| 256 m_image = StaticBitmapImage::create(premulSkImageToUnPremul(m_image->ima geForCurrentFrame().get())); | 256 m_image = StaticBitmapImage::create(premulSkImageToUnPremul(m_image->ima geForCurrentFrame().get())); |
| 257 m_image->setOriginClean(canvas->originClean()); | 257 m_image->setOriginClean(canvas->originClean()); |
| 258 m_image->setPremultiplied(premultiplyAlpha); | 258 m_image->setPremultiplied(premultiplyAlpha); |
| 259 } | 259 } |
| 260 | 260 |
| 261 // The last two parameters are used for structure-cloning. | 261 // The last parameter are used for structure-cloning. |
|
jbroman
2016/06/27 19:16:16
nit: "The last parameter is...", or better yet, "i
xidachen
2016/06/27 19:48:21
Done.
| |
| 262 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi tmapOptions& options, const bool& isImageDataPremultiplied, const bool& isImageD ataOriginClean) | 262 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect, const ImageBi tmapOptions& options, const bool& isImageDataOriginClean) |
| 263 { | 263 { |
| 264 bool flipY; | 264 bool flipY; |
| 265 bool premultiplyAlpha; | 265 bool premultiplyAlpha; |
| 266 parseOptions(options, flipY, premultiplyAlpha); | 266 parseOptions(options, flipY, premultiplyAlpha); |
| 267 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 267 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 268 | 268 |
| 269 // treat non-premultiplyAlpha as a special case | 269 // treat non-premultiplyAlpha as a special case |
| 270 if (!premultiplyAlpha) { | 270 if (!premultiplyAlpha) { |
| 271 unsigned char* srcAddr = data->data()->data(); | 271 unsigned char* srcAddr = data->data()->data(); |
| 272 int srcHeight = data->size().height(); | 272 int srcHeight = data->size().height(); |
| 273 int dstHeight = cropRect.height(); | 273 int dstHeight = cropRect.height(); |
| 274 // TODO (xidachen): skia doesn't support SkImage::NewRasterCopy from a k RGBA color type. | 274 // TODO (xidachen): skia doesn't support SkImage::NewRasterCopy from a k RGBA color type. |
| 275 // For now, we swap R and B channel and uses kBGRA color type. | 275 // For now, we swap R and B channel and uses kBGRA color type. |
| 276 SkImageInfo info; | 276 SkImageInfo info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_ 8888_SkColorType, kUnpremul_SkAlphaType); |
| 277 if (!isImageDataPremultiplied) | |
| 278 info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkC olorType, kUnpremul_SkAlphaType); | |
| 279 else | |
| 280 info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkC olorType, kPremul_SkAlphaType); | |
| 281 int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width(); | 277 int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width(); |
| 282 int dstPixelBytesPerRow = info.bytesPerPixel() * cropRect.width(); | 278 int dstPixelBytesPerRow = info.bytesPerPixel() * cropRect.width(); |
| 283 if (cropRect == IntRect(IntPoint(), data->size())) { | 279 if (cropRect == IntRect(IntPoint(), data->size())) { |
| 284 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); | 280 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); |
| 285 m_image = StaticBitmapImage::create(fromSkSp(SkImage::MakeRasterCopy (SkPixmap(info, srcAddr, dstPixelBytesPerRow)))); | 281 m_image = StaticBitmapImage::create(fromSkSp(SkImage::MakeRasterCopy (SkPixmap(info, srcAddr, dstPixelBytesPerRow)))); |
| 286 // restore the original ImageData | 282 // restore the original ImageData |
| 287 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); | 283 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); |
| 288 } else { | 284 } else { |
| 289 std::unique_ptr<uint8_t[]> copiedDataBuffer = wrapArrayUnique(new ui nt8_t[dstHeight * dstPixelBytesPerRow]()); | 285 std::unique_ptr<uint8_t[]> copiedDataBuffer = wrapArrayUnique(new ui nt8_t[dstHeight * dstPixelBytesPerRow]()); |
| 290 if (!srcRect.isEmpty()) { | 286 if (!srcRect.isEmpty()) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe ct.y())); | 329 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe ct.y())); |
| 334 if (cropRect.x() < 0) | 330 if (cropRect.x() < 0) |
| 335 dstPoint.setX(-cropRect.x()); | 331 dstPoint.setX(-cropRect.x()); |
| 336 if (cropRect.y() < 0) | 332 if (cropRect.y() < 0) |
| 337 dstPoint.setY(-cropRect.y()); | 333 dstPoint.setY(-cropRect.y()); |
| 338 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint); | 334 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint); |
| 339 if (flipY) | 335 if (flipY) |
| 340 m_image = StaticBitmapImage::create(flipSkImageVertically(buffer->newSkI mageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown).get(), PremultiplyAlph a)); | 336 m_image = StaticBitmapImage::create(flipSkImageVertically(buffer->newSkI mageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown).get(), PremultiplyAlph a)); |
| 341 else | 337 else |
| 342 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown)); | 338 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration, SnapshotReasonUnknown)); |
| 339 m_image->setOriginClean(isImageDataOriginClean); | |
|
jbroman
2016/06/27 19:16:16
Is this change related to this CL?
xidachen
2016/06/27 19:48:21
Without this CL, the code path for structured-clon
| |
| 343 } | 340 } |
| 344 | 341 |
| 345 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima geBitmapOptions& options) | 342 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima geBitmapOptions& options) |
| 346 { | 343 { |
| 347 bool flipY; | 344 bool flipY; |
| 348 bool premultiplyAlpha; | 345 bool premultiplyAlpha; |
| 349 parseOptions(options, flipY, premultiplyAlpha); | 346 parseOptions(options, flipY, premultiplyAlpha); |
| 350 m_image = cropImage(bitmap->bitmapImage(), cropRect, flipY, premultiplyAlpha , bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); | 347 m_image = cropImage(bitmap->bitmapImage(), cropRect, flipY, premultiplyAlpha , bitmap->isPremultiplied() ? PremultiplyAlpha : DontPremultiplyAlpha); |
| 351 if (!m_image) | 348 if (!m_image) |
| 352 return; | 349 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 IntRect normalizedCropRect = normalizeRect(cropRect); | 395 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 399 return new ImageBitmap(video, normalizedCropRect, document, options); | 396 return new ImageBitmap(video, normalizedCropRect, document, options); |
| 400 } | 397 } |
| 401 | 398 |
| 402 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, const IntRect& cropR ect, const ImageBitmapOptions& options) | 399 ImageBitmap* ImageBitmap::create(HTMLCanvasElement* canvas, const IntRect& cropR ect, const ImageBitmapOptions& options) |
| 403 { | 400 { |
| 404 IntRect normalizedCropRect = normalizeRect(cropRect); | 401 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 405 return new ImageBitmap(canvas, normalizedCropRect, options); | 402 return new ImageBitmap(canvas, normalizedCropRect, options); |
| 406 } | 403 } |
| 407 | 404 |
| 408 ImageBitmap* ImageBitmap::create(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options, const bool& isImageDataPremultiplied, const bool& isImageDataOriginClean) | 405 ImageBitmap* ImageBitmap::create(ImageData* data, const IntRect& cropRect, const ImageBitmapOptions& options, const bool& isImageDataOriginClean) |
| 409 { | 406 { |
| 410 IntRect normalizedCropRect = normalizeRect(cropRect); | 407 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 411 return new ImageBitmap(data, normalizedCropRect, options, isImageDataPremult iplied, isImageDataOriginClean); | 408 return new ImageBitmap(data, normalizedCropRect, options, isImageDataOriginC lean); |
| 412 } | 409 } |
| 413 | 410 |
| 414 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect, c onst ImageBitmapOptions& options) | 411 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect, c onst ImageBitmapOptions& options) |
| 415 { | 412 { |
| 416 IntRect normalizedCropRect = normalizeRect(cropRect); | 413 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 417 return new ImageBitmap(bitmap, normalizedCropRect, options); | 414 return new ImageBitmap(bitmap, normalizedCropRect, options); |
| 418 } | 415 } |
| 419 | 416 |
| 420 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, const IntR ect& cropRect, const ImageBitmapOptions& options) | 417 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, const IntR ect& cropRect, const ImageBitmapOptions& options) |
| 421 { | 418 { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 518 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
| 522 { | 519 { |
| 523 return FloatSize(width(), height()); | 520 return FloatSize(width(), height()); |
| 524 } | 521 } |
| 525 | 522 |
| 526 DEFINE_TRACE(ImageBitmap) | 523 DEFINE_TRACE(ImageBitmap) |
| 527 { | 524 { |
| 528 } | 525 } |
| 529 | 526 |
| 530 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |