| 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/image-decoders/ImageDecoder.h" | 10 #include "platform/image-decoders/ImageDecoder.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 { | 83 { |
| 84 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S
kColorType, kUnpremul_SkAlphaType); | 84 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S
kColorType, kUnpremul_SkAlphaType); |
| 85 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info); | 85 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info); |
| 86 return newSkImageFromRaster(info, dstPixels.release(), input->width() * info
.bytesPerPixel()); | 86 return newSkImageFromRaster(info, dstPixels.release(), input->width() * info
.bytesPerPixel()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
Rect, bool flipYEnabled, bool premultiplyAlphaEnabled) | 89 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop
Rect, bool flipYEnabled, bool premultiplyAlphaEnabled) |
| 90 { | 90 { |
| 91 ASSERT(image); | 91 ASSERT(image); |
| 92 | 92 |
| 93 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); | 93 IntRect imgRect(IntPoint(), IntSize(image->defaultConcreteObjectSizeWidth(),
image->defaultConcreteObjectSizeHeight())); |
| 94 const IntRect srcRect = intersection(imgRect, cropRect); | 94 const IntRect srcRect = intersection(imgRect, cropRect); |
| 95 | 95 |
| 96 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); | 96 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); |
| 97 // Attempt to get raw unpremultiplied image data. | 97 // Attempt to get raw unpremultiplied image data. |
| 98 if (((!premultiplyAlphaEnabled && !skiaImage->isOpaque()) || !skiaImage) &&
image->data()) { | 98 if (((!premultiplyAlphaEnabled && !skiaImage->isOpaque()) || !skiaImage) &&
image->data()) { |
| 99 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when
working on color-space conversion | 99 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when
working on color-space conversion |
| 100 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( | 100 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( |
| 101 *(image->data()), ImageDecoder::AlphaNotPremultiplied, | 101 *(image->data()), ImageDecoder::AlphaNotPremultiplied, |
| 102 ImageDecoder::GammaAndColorProfileApplied)); | 102 ImageDecoder::GammaAndColorProfileApplied)); |
| 103 if (!decoder) | 103 if (!decoder) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 { | 309 { |
| 310 SkImageInfo info = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorTy
pe, (alphaOp == PremultiplyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)
; | 310 SkImageInfo info = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorTy
pe, (alphaOp == PremultiplyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)
; |
| 311 OwnPtr<uint8_t[]> dstPixels = copySkImageData(m_image->imageForCurrentFrame(
).get(), info); | 311 OwnPtr<uint8_t[]> dstPixels = copySkImageData(m_image->imageForCurrentFrame(
).get(), info); |
| 312 return dstPixels.release(); | 312 return dstPixels.release(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 unsigned long ImageBitmap::width() const | 315 unsigned long ImageBitmap::width() const |
| 316 { | 316 { |
| 317 if (!m_image) | 317 if (!m_image) |
| 318 return 0; | 318 return 0; |
| 319 ASSERT(m_image->width() > 0); | 319 ASSERT(m_image->defaultConcreteObjectSizeWidth() > 0); |
| 320 return m_image->width(); | 320 return m_image->defaultConcreteObjectSizeWidth(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 unsigned long ImageBitmap::height() const | 323 unsigned long ImageBitmap::height() const |
| 324 { | 324 { |
| 325 if (!m_image) | 325 if (!m_image) |
| 326 return 0; | 326 return 0; |
| 327 ASSERT(m_image->height() > 0); | 327 ASSERT(m_image->defaultConcreteObjectSizeHeight() > 0); |
| 328 return m_image->height(); | 328 return m_image->defaultConcreteObjectSizeHeight(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 IntSize ImageBitmap::size() const | 331 IntSize ImageBitmap::size() const |
| 332 { | 332 { |
| 333 if (!m_image) | 333 if (!m_image) |
| 334 return IntSize(); | 334 return IntSize(); |
| 335 ASSERT(m_image->width() > 0 && m_image->height() > 0); | 335 ASSERT(m_image->defaultConcreteObjectSizeWidth() > 0 && m_image->defaultConc
reteObjectSizeHeight() > 0); |
| 336 return IntSize(m_image->width(), m_image->height()); | 336 return IntSize(m_image->defaultConcreteObjectSizeWidth(), m_image->defaultCo
ncreteObjectSizeHeight()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 ScriptPromise ImageBitmap::createImageBitmap(ScriptState* scriptState, EventTarg
et& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& optio
ns, ExceptionState& exceptionState) | 339 ScriptPromise ImageBitmap::createImageBitmap(ScriptState* scriptState, EventTarg
et& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& optio
ns, ExceptionState& exceptionState) |
| 340 { | 340 { |
| 341 if (!sw || !sh) { | 341 if (!sw || !sh) { |
| 342 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 342 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 343 return ScriptPromise(); | 343 return ScriptPromise(); |
| 344 } | 344 } |
| 345 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe
ct(sx, sy, sw, sh), options)); | 345 return ImageBitmapSource::fulfillImageBitmap(scriptState, create(this, IntRe
ct(sx, sy, sw, sh), options)); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void ImageBitmap::notifyImageSourceChanged() | 348 void ImageBitmap::notifyImageSourceChanged() |
| 349 { | 349 { |
| 350 } | 350 } |
| 351 | 351 |
| 352 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint, SnapshotReason) const | 352 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
, AccelerationHint, SnapshotReason) const |
| 353 { | 353 { |
| 354 *status = NormalSourceImageStatus; | 354 *status = NormalSourceImageStatus; |
| 355 return m_image ? m_image : nullptr; | 355 return m_image ? m_image : nullptr; |
| 356 } | 356 } |
| 357 | 357 |
| 358 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const | 358 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const |
| 359 { | 359 { |
| 360 } | 360 } |
| 361 | 361 |
| 362 FloatSize ImageBitmap::elementSize() const | 362 FloatSize ImageBitmap::elementSize(const FloatSize&) const |
| 363 { | 363 { |
| 364 return FloatSize(width(), height()); | 364 return FloatSize(width(), height()); |
| 365 } | 365 } |
| 366 | 366 |
| 367 DEFINE_TRACE(ImageBitmap) | 367 DEFINE_TRACE(ImageBitmap) |
| 368 { | 368 { |
| 369 ImageLoaderClient::trace(visitor); | 369 ImageLoaderClient::trace(visitor); |
| 370 } | 370 } |
| 371 | 371 |
| 372 } // namespace blink | 372 } // namespace blink |
| OLD | NEW |