| 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" |
| 11 #include "platform/image-decoders/ImageDecoder.h" | 11 #include "platform/image-decoders/ImageDecoder.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkSurface.h" | 13 #include "third_party/skia/include/core/SkSurface.h" |
| 14 #include "wtf/PtrUtil.h" |
| 14 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 16 #include <memory> |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 18 static const char* imageOrientationFlipY = "flipY"; | 20 static const char* imageOrientationFlipY = "flipY"; |
| 19 static const char* imageBitmapOptionNone = "none"; | 21 static const char* imageBitmapOptionNone = "none"; |
| 20 | 22 |
| 21 // The following two functions are helpers used in cropImage | 23 // The following two functions are helpers used in cropImage |
| 22 static inline IntRect normalizeRect(const IntRect& rect) | 24 static inline IntRect normalizeRect(const IntRect& rect) |
| 23 { | 25 { |
| 24 return IntRect(std::min(rect.x(), rect.maxX()), | 26 return IntRect(std::min(rect.x(), rect.maxX()), |
| 25 std::min(rect.y(), rect.maxY()), | 27 std::min(rect.y(), rect.maxY()), |
| 26 std::max(rect.width(), -rect.width()), | 28 std::max(rect.width(), -rect.width()), |
| 27 std::max(rect.height(), -rect.height())); | 29 std::max(rect.height(), -rect.height())); |
| 28 } | 30 } |
| 29 | 31 |
| 30 static bool frameIsValid(const SkBitmap& frameBitmap) | 32 static bool frameIsValid(const SkBitmap& frameBitmap) |
| 31 { | 33 { |
| 32 ASSERT(!frameBitmap.isNull() && !frameBitmap.empty() && frameBitmap.isImmuta
ble()); | 34 ASSERT(!frameBitmap.isNull() && !frameBitmap.empty() && frameBitmap.isImmuta
ble()); |
| 33 return frameBitmap.colorType() == kN32_SkColorType; | 35 return frameBitmap.colorType() == kN32_SkColorType; |
| 34 } | 36 } |
| 35 | 37 |
| 36 static PassOwnPtr<uint8_t[]> copySkImageData(SkImage* input, SkImageInfo info) | 38 static std::unique_ptr<uint8_t[]> copySkImageData(SkImage* input, SkImageInfo in
fo) |
| 37 { | 39 { |
| 38 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[input->width() * inp
ut->height() * info.bytesPerPixel()]); | 40 std::unique_ptr<uint8_t[]> dstPixels = wrapArrayUnique(new uint8_t[input->wi
dth() * input->height() * info.bytesPerPixel()]); |
| 39 input->readPixels(info, dstPixels.get(), input->width() * info.bytesPerPixel
(), 0, 0); | 41 input->readPixels(info, dstPixels.get(), input->width() * info.bytesPerPixel
(), 0, 0); |
| 40 return dstPixels; | 42 return dstPixels; |
| 41 } | 43 } |
| 42 | 44 |
| 43 static PassRefPtr<SkImage> newSkImageFromRaster(SkImageInfo info, PassOwnPtr<uin
t8_t[]> imagePixels, int imageRowBytes) | 45 static PassRefPtr<SkImage> newSkImageFromRaster(SkImageInfo info, std::unique_pt
r<uint8_t[]> imagePixels, int imageRowBytes) |
| 44 { | 46 { |
| 45 return adoptRef(SkImage::NewFromRaster(info, imagePixels.leakPtr(), imageRow
Bytes, | 47 return adoptRef(SkImage::NewFromRaster(info, imagePixels.release(), imageRow
Bytes, |
| 46 [](const void* pixels, void*) | 48 [](const void* pixels, void*) |
| 47 { | 49 { |
| 48 delete[] static_cast<const uint8_t*>(pixels); | 50 delete[] static_cast<const uint8_t*>(pixels); |
| 49 }, nullptr)); | 51 }, nullptr)); |
| 50 } | 52 } |
| 51 | 53 |
| 52 static void swizzleImageData(unsigned char* srcAddr, int height, int bytesPerRow
, bool flipY) | 54 static void swizzleImageData(unsigned char* srcAddr, int height, int bytesPerRow
, bool flipY) |
| 53 { | 55 { |
| 54 if (flipY) { | 56 if (flipY) { |
| 55 for (int i = 0; i < height / 2; i++) { | 57 for (int i = 0; i < height / 2; i++) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 std::swap(srcAddr[i], srcAddr[i + 2]); | 69 std::swap(srcAddr[i], srcAddr[i + 2]); |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 | 72 |
| 71 static PassRefPtr<SkImage> flipSkImageVertically(SkImage* input, AlphaDispositio
n alphaOp) | 73 static PassRefPtr<SkImage> flipSkImageVertically(SkImage* input, AlphaDispositio
n alphaOp) |
| 72 { | 74 { |
| 73 int width = input->width(); | 75 int width = input->width(); |
| 74 int height = input->height(); | 76 int height = input->height(); |
| 75 SkImageInfo info = SkImageInfo::MakeN32(width, height, (alphaOp == Premultip
lyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); | 77 SkImageInfo info = SkImageInfo::MakeN32(width, height, (alphaOp == Premultip
lyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); |
| 76 int imageRowBytes = width * info.bytesPerPixel(); | 78 int imageRowBytes = width * info.bytesPerPixel(); |
| 77 OwnPtr<uint8_t[]> imagePixels = copySkImageData(input, info); | 79 std::unique_ptr<uint8_t[]> imagePixels = copySkImageData(input, info); |
| 78 for (int i = 0; i < height / 2; i++) { | 80 for (int i = 0; i < height / 2; i++) { |
| 79 int topFirstElement = i * imageRowBytes; | 81 int topFirstElement = i * imageRowBytes; |
| 80 int topLastElement = (i + 1) * imageRowBytes; | 82 int topLastElement = (i + 1) * imageRowBytes; |
| 81 int bottomFirstElement = (height - 1 - i) * imageRowBytes; | 83 int bottomFirstElement = (height - 1 - i) * imageRowBytes; |
| 82 std::swap_ranges(imagePixels.get() + topFirstElement, imagePixels.get()
+ topLastElement, imagePixels.get() + bottomFirstElement); | 84 std::swap_ranges(imagePixels.get() + topFirstElement, imagePixels.get()
+ topLastElement, imagePixels.get() + bottomFirstElement); |
| 83 } | 85 } |
| 84 return newSkImageFromRaster(info, std::move(imagePixels), imageRowBytes); | 86 return newSkImageFromRaster(info, std::move(imagePixels), imageRowBytes); |
| 85 } | 87 } |
| 86 | 88 |
| 87 static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input) | 89 static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input) |
| 88 { | 90 { |
| 89 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S
kColorType, kUnpremul_SkAlphaType); | 91 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S
kColorType, kUnpremul_SkAlphaType); |
| 90 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info); | 92 std::unique_ptr<uint8_t[]> dstPixels = copySkImageData(input, info); |
| 91 return newSkImageFromRaster(info, std::move(dstPixels), input->width() * inf
o.bytesPerPixel()); | 93 return newSkImageFromRaster(info, std::move(dstPixels), input->width() * inf
o.bytesPerPixel()); |
| 92 } | 94 } |
| 93 | 95 |
| 94 static PassRefPtr<SkImage> unPremulSkImageToPremul(SkImage* input) | 96 static PassRefPtr<SkImage> unPremulSkImageToPremul(SkImage* input) |
| 95 { | 97 { |
| 96 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S
kColorType, kPremul_SkAlphaType); | 98 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S
kColorType, kPremul_SkAlphaType); |
| 97 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info); | 99 std::unique_ptr<uint8_t[]> dstPixels = copySkImageData(input, info); |
| 98 return newSkImageFromRaster(info, std::move(dstPixels), input->width() * inf
o.bytesPerPixel()); | 100 return newSkImageFromRaster(info, std::move(dstPixels), input->width() * inf
o.bytesPerPixel()); |
| 99 } | 101 } |
| 100 | 102 |
| 101 PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(PassOwnPtr<ImageDecoder>
decoder) | 103 PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(std::unique_ptr<ImageDeco
der> decoder) |
| 102 { | 104 { |
| 103 if (!decoder->frameCount()) | 105 if (!decoder->frameCount()) |
| 104 return nullptr; | 106 return nullptr; |
| 105 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 107 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
| 106 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) | 108 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) |
| 107 return nullptr; | 109 return nullptr; |
| 108 SkBitmap bitmap = frame->bitmap(); | 110 SkBitmap bitmap = frame->bitmap(); |
| 109 if (!frameIsValid(bitmap)) | 111 if (!frameIsValid(bitmap)) |
| 110 return nullptr; | 112 return nullptr; |
| 111 return adoptRef(SkImage::NewFromBitmap(bitmap)); | 113 return adoptRef(SkImage::NewFromBitmap(bitmap)); |
| 112 } | 114 } |
| 113 | 115 |
| 114 // The parameter imageFormat indicates whether the first parameter "image" is un
premultiplied or not. | 116 // The parameter imageFormat indicates whether the first parameter "image" is un
premultiplied or not. |
| 115 // imageFormat = PremultiplyAlpha means the image is in premuliplied format | 117 // imageFormat = PremultiplyAlpha means the image is in premuliplied format |
| 116 // For example, if the image is already in unpremultiplied format and we want th
e created ImageBitmap | 118 // For example, if the image is already in unpremultiplied format and we want th
e created ImageBitmap |
| 117 // in the same format, then we don't need to use the ImageDecoder to decode the
image. | 119 // in the same format, then we don't need to use the ImageDecoder to decode the
image. |
| 118 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
Rect, bool flipY, bool premultiplyAlpha, AlphaDisposition imageFormat = Premulti
plyAlpha, ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::
GammaAndColorProfileApplied) | 120 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
Rect, bool flipY, bool premultiplyAlpha, AlphaDisposition imageFormat = Premulti
plyAlpha, ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::
GammaAndColorProfileApplied) |
| 119 { | 121 { |
| 120 ASSERT(image); | 122 ASSERT(image); |
| 121 | 123 |
| 122 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); | 124 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); |
| 123 const IntRect srcRect = intersection(imgRect, cropRect); | 125 const IntRect srcRect = intersection(imgRect, cropRect); |
| 124 | 126 |
| 125 // In the case when cropRect doesn't intersect the source image and it requi
res a umpremul image | 127 // In the case when cropRect doesn't intersect the source image and it requi
res a umpremul image |
| 126 // We immediately return a transparent black image with cropRect.size() | 128 // We immediately return a transparent black image with cropRect.size() |
| 127 if (srcRect.isEmpty() && !premultiplyAlpha) { | 129 if (srcRect.isEmpty() && !premultiplyAlpha) { |
| 128 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height()
, kN32_SkColorType, kUnpremul_SkAlphaType); | 130 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height()
, kN32_SkColorType, kUnpremul_SkAlphaType); |
| 129 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[cropRect.width()
* cropRect.height() * info.bytesPerPixel()]()); | 131 std::unique_ptr<uint8_t[]> dstPixels = wrapArrayUnique(new uint8_t[cropR
ect.width() * cropRect.height() * info.bytesPerPixel()]()); |
| 130 return StaticBitmapImage::create(newSkImageFromRaster(info, std::move(ds
tPixels), cropRect.width() * info.bytesPerPixel())); | 132 return StaticBitmapImage::create(newSkImageFromRaster(info, std::move(ds
tPixels), cropRect.width() * info.bytesPerPixel())); |
| 131 } | 133 } |
| 132 | 134 |
| 133 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); | 135 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); |
| 134 // Attempt to get raw unpremultiplied image data, executed only when skiaIma
ge is premultiplied. | 136 // Attempt to get raw unpremultiplied image data, executed only when skiaIma
ge is premultiplied. |
| 135 if ((((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-
>data() && imageFormat == PremultiplyAlpha) || colorSpaceOp == ImageDecoder::Gam
maAndColorProfileIgnored) { | 137 if ((((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-
>data() && imageFormat == PremultiplyAlpha) || colorSpaceOp == ImageDecoder::Gam
maAndColorProfileIgnored) { |
| 136 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*(image->data()), | 138 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*(image->data
()), |
| 137 premultiplyAlpha ? ImageDecoder::AlphaPremultiplied : ImageDecoder::
AlphaNotPremultiplied, | 139 premultiplyAlpha ? ImageDecoder::AlphaPremultiplied : ImageDecoder::
AlphaNotPremultiplied, |
| 138 colorSpaceOp)); | 140 colorSpaceOp)); |
| 139 if (!decoder) | 141 if (!decoder) |
| 140 return nullptr; | 142 return nullptr; |
| 141 decoder->setData(image->data(), true); | 143 decoder->setData(image->data(), true); |
| 142 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); | 144 skiaImage = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); |
| 143 if (!skiaImage) | 145 if (!skiaImage) |
| 144 return nullptr; | 146 return nullptr; |
| 145 } | 147 } |
| 146 | 148 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 209 } |
| 208 | 210 |
| 209 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum
ent* document, const ImageBitmapOptions& options) | 211 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, Docum
ent* document, const ImageBitmapOptions& options) |
| 210 { | 212 { |
| 211 IntSize playerSize; | 213 IntSize playerSize; |
| 212 if (video->webMediaPlayer()) | 214 if (video->webMediaPlayer()) |
| 213 playerSize = video->webMediaPlayer()->naturalSize(); | 215 playerSize = video->webMediaPlayer()->naturalSize(); |
| 214 | 216 |
| 215 IntRect videoRect = IntRect(IntPoint(), playerSize); | 217 IntRect videoRect = IntRect(IntPoint(), playerSize); |
| 216 IntRect srcRect = intersection(cropRect, videoRect); | 218 IntRect srcRect = intersection(cropRect, videoRect); |
| 217 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 219 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), N
onOpaque, DoNotInitializeImagePixels); |
| 218 if (!buffer) | 220 if (!buffer) |
| 219 return; | 221 return; |
| 220 | 222 |
| 221 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe
ct.y())); | 223 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe
ct.y())); |
| 222 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); | 224 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size())
, nullptr); |
| 223 | 225 |
| 224 bool flipY; | 226 bool flipY; |
| 225 bool premultiplyAlpha; | 227 bool premultiplyAlpha; |
| 226 parseOptions(options, flipY, premultiplyAlpha); | 228 parseOptions(options, flipY, premultiplyAlpha); |
| 227 | 229 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 else | 278 else |
| 277 info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkC
olorType, kPremul_SkAlphaType); | 279 info = SkImageInfo::Make(cropRect.width(), dstHeight, kBGRA_8888_SkC
olorType, kPremul_SkAlphaType); |
| 278 int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width(); | 280 int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width(); |
| 279 int dstPixelBytesPerRow = info.bytesPerPixel() * cropRect.width(); | 281 int dstPixelBytesPerRow = info.bytesPerPixel() * cropRect.width(); |
| 280 if (cropRect == IntRect(IntPoint(), data->size())) { | 282 if (cropRect == IntRect(IntPoint(), data->size())) { |
| 281 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); | 283 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); |
| 282 m_image = StaticBitmapImage::create(adoptRef(SkImage::NewRasterCopy(
info, srcAddr, dstPixelBytesPerRow))); | 284 m_image = StaticBitmapImage::create(adoptRef(SkImage::NewRasterCopy(
info, srcAddr, dstPixelBytesPerRow))); |
| 283 // restore the original ImageData | 285 // restore the original ImageData |
| 284 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); | 286 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, flipY); |
| 285 } else { | 287 } else { |
| 286 OwnPtr<uint8_t[]> copiedDataBuffer = adoptArrayPtr(new uint8_t[dstHe
ight * dstPixelBytesPerRow]()); | 288 std::unique_ptr<uint8_t[]> copiedDataBuffer = wrapArrayUnique(new ui
nt8_t[dstHeight * dstPixelBytesPerRow]()); |
| 287 if (!srcRect.isEmpty()) { | 289 if (!srcRect.isEmpty()) { |
| 288 IntPoint srcPoint = IntPoint((cropRect.x() > 0) ? cropRect.x() :
0, (cropRect.y() > 0) ? cropRect.y() : 0); | 290 IntPoint srcPoint = IntPoint((cropRect.x() > 0) ? cropRect.x() :
0, (cropRect.y() > 0) ? cropRect.y() : 0); |
| 289 IntPoint dstPoint = IntPoint((cropRect.x() >= 0) ? 0 : -cropRect
.x(), (cropRect.y() >= 0) ? 0 : -cropRect.y()); | 291 IntPoint dstPoint = IntPoint((cropRect.x() >= 0) ? 0 : -cropRect
.x(), (cropRect.y() >= 0) ? 0 : -cropRect.y()); |
| 290 int copyHeight = srcHeight - srcPoint.y(); | 292 int copyHeight = srcHeight - srcPoint.y(); |
| 291 if (cropRect.height() < copyHeight) | 293 if (cropRect.height() < copyHeight) |
| 292 copyHeight = cropRect.height(); | 294 copyHeight = cropRect.height(); |
| 293 int copyWidth = data->size().width() - srcPoint.x(); | 295 int copyWidth = data->size().width() - srcPoint.x(); |
| 294 if (cropRect.width() < copyWidth) | 296 if (cropRect.width() < copyWidth) |
| 295 copyWidth = cropRect.width(); | 297 copyWidth = cropRect.width(); |
| 296 for (int i = 0; i < copyHeight; i++) { | 298 for (int i = 0; i < copyHeight; i++) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 310 copiedDataBuffer[dstStartCopyPosition + j] = srcAddr
[srcStartCopyPosition + j]; | 312 copiedDataBuffer[dstStartCopyPosition + j] = srcAddr
[srcStartCopyPosition + j]; |
| 311 } | 313 } |
| 312 } | 314 } |
| 313 } | 315 } |
| 314 m_image = StaticBitmapImage::create(newSkImageFromRaster(info, std::
move(copiedDataBuffer), dstPixelBytesPerRow)); | 316 m_image = StaticBitmapImage::create(newSkImageFromRaster(info, std::
move(copiedDataBuffer), dstPixelBytesPerRow)); |
| 315 } | 317 } |
| 316 m_image->setPremultiplied(premultiplyAlpha); | 318 m_image->setPremultiplied(premultiplyAlpha); |
| 317 return; | 319 return; |
| 318 } | 320 } |
| 319 | 321 |
| 320 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque,
DoNotInitializeImagePixels); | 322 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), N
onOpaque, DoNotInitializeImagePixels); |
| 321 if (!buffer) | 323 if (!buffer) |
| 322 return; | 324 return; |
| 323 | 325 |
| 324 if (srcRect.isEmpty()) { | 326 if (srcRect.isEmpty()) { |
| 325 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration, SnapshotReasonUnknown)); | 327 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA
cceleration, SnapshotReasonUnknown)); |
| 326 return; | 328 return; |
| 327 } | 329 } |
| 328 | 330 |
| 329 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe
ct.y())); | 331 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe
ct.y())); |
| 330 if (cropRect.x() < 0) | 332 if (cropRect.x() < 0) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 m_image.clear(); | 438 m_image.clear(); |
| 437 m_isNeutered = true; | 439 m_isNeutered = true; |
| 438 } | 440 } |
| 439 | 441 |
| 440 // static | 442 // static |
| 441 ImageBitmap* ImageBitmap::take(ScriptPromiseResolver*, sk_sp<SkImage> image) | 443 ImageBitmap* ImageBitmap::take(ScriptPromiseResolver*, sk_sp<SkImage> image) |
| 442 { | 444 { |
| 443 return ImageBitmap::create(StaticBitmapImage::create(fromSkSp(image))); | 445 return ImageBitmap::create(StaticBitmapImage::create(fromSkSp(image))); |
| 444 } | 446 } |
| 445 | 447 |
| 446 PassOwnPtr<uint8_t[]> ImageBitmap::copyBitmapData(AlphaDisposition alphaOp) | 448 std::unique_ptr<uint8_t[]> ImageBitmap::copyBitmapData(AlphaDisposition alphaOp) |
| 447 { | 449 { |
| 448 SkImageInfo info = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorTy
pe, (alphaOp == PremultiplyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)
; | 450 SkImageInfo info = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorTy
pe, (alphaOp == PremultiplyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)
; |
| 449 OwnPtr<uint8_t[]> dstPixels = copySkImageData(m_image->imageForCurrentFrame(
).get(), info); | 451 std::unique_ptr<uint8_t[]> dstPixels = copySkImageData(m_image->imageForCurr
entFrame().get(), info); |
| 450 return dstPixels; | 452 return dstPixels; |
| 451 } | 453 } |
| 452 | 454 |
| 453 unsigned long ImageBitmap::width() const | 455 unsigned long ImageBitmap::width() const |
| 454 { | 456 { |
| 455 if (!m_image) | 457 if (!m_image) |
| 456 return 0; | 458 return 0; |
| 457 ASSERT(m_image->width() > 0); | 459 ASSERT(m_image->width() > 0); |
| 458 return m_image->width(); | 460 return m_image->width(); |
| 459 } | 461 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 FloatSize ImageBitmap::elementSize(const FloatSize&) const | 514 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
| 513 { | 515 { |
| 514 return FloatSize(width(), height()); | 516 return FloatSize(width(), height()); |
| 515 } | 517 } |
| 516 | 518 |
| 517 DEFINE_TRACE(ImageBitmap) | 519 DEFINE_TRACE(ImageBitmap) |
| 518 { | 520 { |
| 519 } | 521 } |
| 520 | 522 |
| 521 } // namespace blink | 523 } // namespace blink |
| OLD | NEW |