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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) | 80 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect) |
| 81 { | 81 { |
| 82 m_image = cropImage(bitmap->skImage(), cropRect); | 82 m_image = cropImage(bitmap->skImage(), cropRect); |
| 83 } | 83 } |
| 84 | 84 |
| 85 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) | 85 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) |
| 86 { | 86 { |
| 87 m_image = cropImage(image->imageForCurrentFrame(), cropRect); | 87 m_image = cropImage(image->imageForCurrentFrame(), cropRect); |
| 88 } | 88 } |
| 89 | 89 |
| 90 ImageBitmap::ImageBitmap(SkImage* image) | |
| 91 { | |
| 92 m_image = adoptRef(image); | |
| 93 } | |
| 94 | |
| 95 PassRefPtr<SkImage> ImageBitmap::transfer() | |
| 96 { | |
| 97 return m_image.release(); | |
|
Justin Novosad
2015/11/11 05:29:08
From the postMessage spec: "If any object is liste
xidachen
2015/11/16 18:00:51
Done.
| |
| 98 } | |
| 99 | |
| 90 ImageBitmap::~ImageBitmap() | 100 ImageBitmap::~ImageBitmap() |
| 91 { | 101 { |
| 92 } | 102 } |
| 93 | 103 |
| 94 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect) | 104 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRect& cropRect) |
| 95 { | 105 { |
| 96 IntRect normalizedCropRect = normalizeRect(cropRect); | 106 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 97 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 107 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); |
| 98 } | 108 } |
| 99 | 109 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 120 IntRect normalizedCropRect = normalizeRect(cropRect); | 130 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 121 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); | 131 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); |
| 122 } | 132 } |
| 123 | 133 |
| 124 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntR ect& cropRect) | 134 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntR ect& cropRect) |
| 125 { | 135 { |
| 126 IntRect normalizedCropRect = normalizeRect(cropRect); | 136 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 127 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); | 137 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); |
| 128 } | 138 } |
| 129 | 139 |
| 140 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(SkImage* image) | |
| 141 { | |
| 142 return adoptRefWillBeNoop(new ImageBitmap(image)); | |
| 143 } | |
| 144 | |
| 130 PassRefPtr<SkImage> ImageBitmap::cropImage(PassRefPtr<SkImage> image, const IntR ect& cropRect) | 145 PassRefPtr<SkImage> ImageBitmap::cropImage(PassRefPtr<SkImage> image, const IntR ect& cropRect) |
| 131 { | 146 { |
| 132 ASSERT(image); | 147 ASSERT(image); |
| 133 | 148 |
| 134 IntRect imgRect = IntRect(IntPoint(), IntSize(image->width(), image->height( ))); | 149 IntRect imgRect = IntRect(IntPoint(), IntSize(image->width(), image->height( ))); |
| 135 const IntRect srcRect = intersection(imgRect, cropRect); | 150 const IntRect srcRect = intersection(imgRect, cropRect); |
| 136 | 151 |
| 137 if (cropRect == srcRect) | 152 if (cropRect == srcRect) |
| 138 return adoptRef(image->newSubset(srcRect)); | 153 return adoptRef(image->newSubset(srcRect)); |
| 139 | 154 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 { | 186 { |
| 172 return FloatSize(width(), height()); | 187 return FloatSize(width(), height()); |
| 173 } | 188 } |
| 174 | 189 |
| 175 DEFINE_TRACE(ImageBitmap) | 190 DEFINE_TRACE(ImageBitmap) |
| 176 { | 191 { |
| 177 ImageLoaderClient::trace(visitor); | 192 ImageLoaderClient::trace(visitor); |
| 178 } | 193 } |
| 179 | 194 |
| 180 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |