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 "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/ImageBitmap.h" | 6 #include "core/frame/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
| 10 #include "core/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 SkScalar dstLeft = std::min(0, -cropRect.x()); | 39 SkScalar dstLeft = std::min(0, -cropRect.x()); |
| 40 SkScalar dstTop = std::min(0, -cropRect.y()); | 40 SkScalar dstTop = std::min(0, -cropRect.y()); |
| 41 if (cropRect.x() < 0) | 41 if (cropRect.x() < 0) |
| 42 dstLeft = -cropRect.x(); | 42 dstLeft = -cropRect.x(); |
| 43 if (cropRect.y() < 0) | 43 if (cropRect.y() < 0) |
| 44 dstTop = -cropRect.y(); | 44 dstTop = -cropRect.y(); |
| 45 surface->getCanvas()->drawImage(image->imageForCurrentFrame().get(), dstLeft , dstTop); | 45 surface->getCanvas()->drawImage(image->imageForCurrentFrame().get(), dstLeft , dstTop); |
| 46 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); | 46 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect) | 49 ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect, bool originCleanFlag) |
| 50 { | 50 { |
| 51 m_isOriginClean = originCleanFlag; | |
| 51 m_image = cropImage(image->cachedImage()->image(), cropRect); | 52 m_image = cropImage(image->cachedImage()->image(), cropRect); |
| 52 } | 53 } |
| 53 | 54 |
| 54 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect) | 55 ImageBitmap::ImageBitmap(HTMLVideoElement* video, const IntRect& cropRect, bool originCleanFlag) |
| 55 { | 56 { |
| 56 IntSize playerSize; | 57 IntSize playerSize; |
| 57 if (video->webMediaPlayer()) | 58 if (video->webMediaPlayer()) |
| 58 playerSize = video->webMediaPlayer()->naturalSize(); | 59 playerSize = video->webMediaPlayer()->naturalSize(); |
| 59 | 60 |
| 60 IntRect videoRect = IntRect(IntPoint(), playerSize); | 61 IntRect videoRect = IntRect(IntPoint(), playerSize); |
| 61 IntRect srcRect = intersection(cropRect, videoRect); | 62 IntRect srcRect = intersection(cropRect, videoRect); |
| 62 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque, DoNotInitializeImagePixels); | 63 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque, DoNotInitializeImagePixels); |
| 63 if (!buffer) | 64 if (!buffer) |
| 64 return; | 65 return; |
| 65 | 66 |
| 66 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe ct.y())); | 67 IntPoint dstPoint = IntPoint(std::max(0, -cropRect.x()), std::max(0, -cropRe ct.y())); |
| 67 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr); | 68 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr); |
| 69 m_isOriginClean = originCleanFlag; | |
| 68 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel eration)); | 70 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel eration)); |
| 69 } | 71 } |
| 70 | 72 |
| 71 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | 73 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) |
|
Justin Novosad
2015/12/16 03:34:35
This constructor should transfer the origin clean
xidachen
2015/12/22 14:29:40
Done.
| |
| 72 { | 74 { |
| 73 ASSERT(canvas->isPaintable()); | 75 ASSERT(canvas->isPaintable()); |
| 74 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get( ), cropRect); | 76 m_image = cropImage(canvas->copiedImage(BackBuffer, PreferAcceleration).get( ), cropRect); |
| 75 } | 77 } |
| 76 | 78 |
| 77 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 79 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 78 { | 80 { |
| 79 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 81 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 80 | 82 |
| 81 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque, DoNotInitializeImagePixels); | 83 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque, DoNotInitializeImagePixels); |
| 82 if (!buffer) | 84 if (!buffer) |
| 83 return; | 85 return; |
| 84 | 86 |
| 85 if (srcRect.isEmpty()) { | 87 if (srcRect.isEmpty()) { |
| 86 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration)); | 88 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration)); |
| 87 return; | 89 return; |
| 88 } | 90 } |
| 89 | 91 |
| 90 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe ct.y())); | 92 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe ct.y())); |
| 91 if (cropRect.x() < 0) | 93 if (cropRect.x() < 0) |
| 92 dstPoint.setX(-cropRect.x()); | 94 dstPoint.setX(-cropRect.x()); |
| 93 if (cropRect.y() < 0) | 95 if (cropRect.y() < 0) |
| 94 dstPoint.setY(-cropRect.y()); | 96 dstPoint.setY(-cropRect.y()); |
| 95 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint); | 97 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint); |
| 96 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel eration)); | 98 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel eration)); |
| 97 } | 99 } |
| 98 | 100 |
| 99 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) | 101 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
|
Justin Novosad
2015/12/16 03:34:35
This constructor should take the value of the orig
xidachen
2015/12/22 14:29:40
Done.
| |
| 100 { | 102 { |
| 101 m_image = cropImage(bitmap->bitmapImage(), cropRect); | 103 m_image = cropImage(bitmap->bitmapImage(), cropRect); |
| 102 } | 104 } |
| 103 | 105 |
| 104 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) | 106 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) |
|
Justin Novosad
2015/12/16 03:34:35
this can be cross-origin.
xidachen
2015/12/22 14:29:40
Done.
| |
| 105 { | 107 { |
| 106 m_image = cropImage(image, cropRect); | 108 m_image = cropImage(image, cropRect); |
| 107 } | 109 } |
| 108 | 110 |
| 109 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) | 111 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) |
|
Justin Novosad
2015/12/16 03:34:35
this can be cross-origin
xidachen
2015/12/22 14:29:40
Done.
| |
| 110 { | 112 { |
| 111 m_image = image; | 113 m_image = image; |
| 112 } | 114 } |
| 113 | 115 |
| 114 PassRefPtr<StaticBitmapImage> ImageBitmap::transfer() | 116 PassRefPtr<StaticBitmapImage> ImageBitmap::transfer() |
|
Justin Novosad
2015/12/16 03:34:35
the transfer logic needs some special precautions.
| |
| 115 { | 117 { |
| 116 ASSERT(!isNeutered()); | 118 ASSERT(!isNeutered()); |
| 117 m_isNeutered = true; | 119 m_isNeutered = true; |
| 118 return m_image.release(); | 120 return m_image.release(); |
| 119 } | 121 } |
| 120 | 122 |
| 121 ImageBitmap::~ImageBitmap() | 123 ImageBitmap::~ImageBitmap() |
| 122 { | 124 { |
| 123 } | 125 } |
| 124 | 126 |
| 125 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect) | 127 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect, bool originCleanFlag) |
| 126 { | 128 { |
| 127 IntRect normalizedCropRect = normalizeRect(cropRect); | 129 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 128 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 130 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect, originC leanFlag)); |
| 129 } | 131 } |
| 130 | 132 |
| 131 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRect& cropRect) | 133 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRect& cropRect, bool originCleanFlag) |
| 132 { | 134 { |
| 133 IntRect normalizedCropRect = normalizeRect(cropRect); | 135 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 134 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect)); | 136 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect, originC leanFlag)); |
| 135 } | 137 } |
| 136 | 138 |
| 137 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva s, const IntRect& cropRect) | 139 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva s, const IntRect& cropRect) |
| 138 { | 140 { |
| 139 IntRect normalizedCropRect = normalizeRect(cropRect); | 141 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 140 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); | 142 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); |
| 141 } | 143 } |
| 142 | 144 |
| 143 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I ntRect& cropRect) | 145 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I ntRect& cropRect) |
| 144 { | 146 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 { | 216 { |
| 215 return FloatSize(width(), height()); | 217 return FloatSize(width(), height()); |
| 216 } | 218 } |
| 217 | 219 |
| 218 DEFINE_TRACE(ImageBitmap) | 220 DEFINE_TRACE(ImageBitmap) |
| 219 { | 221 { |
| 220 ImageLoaderClient::trace(visitor); | 222 ImageLoaderClient::trace(visitor); |
| 221 } | 223 } |
| 222 | 224 |
| 223 } // namespace blink | 225 } // namespace blink |
| OLD | NEW |