| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 { | 138 { |
| 139 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), image->size()))
; | 139 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), image->size()))
; |
| 140 m_bitmap = cropImage(image, cropRect); | 140 m_bitmap = cropImage(image, cropRect); |
| 141 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); | 141 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); |
| 142 | 142 |
| 143 ScriptWrappable::init(this); | 143 ScriptWrappable::init(this); |
| 144 } | 144 } |
| 145 | 145 |
| 146 ImageBitmap::~ImageBitmap() | 146 ImageBitmap::~ImageBitmap() |
| 147 { | 147 { |
| 148 if (m_imageElement) | 148 detach(); |
| 149 m_imageElement->removeClient(this); | |
| 150 } | 149 } |
| 151 | 150 |
| 152 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe
ct& cropRect) | 151 void ImageBitmap::detach() |
| 152 { |
| 153 if (m_imageElement) { |
| 154 m_imageElement->removeClient(this); |
| 155 m_imageElement = nullptr; |
| 156 } |
| 157 } |
| 158 |
| 159 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image,
const IntRect& cropRect) |
| 153 { | 160 { |
| 154 IntRect normalizedCropRect = normalizeRect(cropRect); | 161 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 155 return adoptRef(new ImageBitmap(image, normalizedCropRect)); | 162 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); |
| 156 } | 163 } |
| 157 | 164 |
| 158 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRe
ct& cropRect) | 165 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video,
const IntRect& cropRect) |
| 159 { | 166 { |
| 160 IntRect normalizedCropRect = normalizeRect(cropRect); | 167 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 161 return adoptRef(new ImageBitmap(video, normalizedCropRect)); | 168 return adoptRefWillBeNoop(new ImageBitmap(video, normalizedCropRect)); |
| 162 } | 169 } |
| 163 | 170 |
| 164 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const Int
Rect& cropRect) | 171 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canva
s, const IntRect& cropRect) |
| 165 { | 172 { |
| 166 IntRect normalizedCropRect = normalizeRect(cropRect); | 173 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 167 return adoptRef(new ImageBitmap(canvas, normalizedCropRect)); | 174 return adoptRefWillBeNoop(new ImageBitmap(canvas, normalizedCropRect)); |
| 168 } | 175 } |
| 169 | 176 |
| 170 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop
Rect) | 177 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const I
ntRect& cropRect) |
| 171 { | 178 { |
| 172 IntRect normalizedCropRect = normalizeRect(cropRect); | 179 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 173 return adoptRef(new ImageBitmap(data, normalizedCropRect)); | 180 return adoptRefWillBeNoop(new ImageBitmap(data, normalizedCropRect)); |
| 174 } | 181 } |
| 175 | 182 |
| 176 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) | 183 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, con
st IntRect& cropRect) |
| 177 { | 184 { |
| 178 IntRect normalizedCropRect = normalizeRect(cropRect); | 185 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 179 return adoptRef(new ImageBitmap(bitmap, normalizedCropRect)); | 186 return adoptRefWillBeNoop(new ImageBitmap(bitmap, normalizedCropRect)); |
| 180 } | 187 } |
| 181 | 188 |
| 182 PassRefPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntRect& cropRec
t) | 189 PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntR
ect& cropRect) |
| 183 { | 190 { |
| 184 IntRect normalizedCropRect = normalizeRect(cropRect); | 191 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 185 return adoptRef(new ImageBitmap(image, normalizedCropRect)); | 192 return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect)); |
| 186 } | 193 } |
| 187 | 194 |
| 188 void ImageBitmap::notifyImageSourceChanged() | 195 void ImageBitmap::notifyImageSourceChanged() |
| 189 { | 196 { |
| 190 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); | 197 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); |
| 191 m_bitmapOffset = IntPoint(); | 198 m_bitmapOffset = IntPoint(); |
| 192 m_imageElement = nullptr; | 199 m_imageElement = nullptr; |
| 193 } | 200 } |
| 194 | 201 |
| 195 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 202 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
| 196 { | 203 { |
| 197 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); | 204 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); |
| 198 if (m_imageElement) | 205 if (m_imageElement) |
| 199 return m_imageElement->cachedImage()->image(); | 206 return m_imageElement->cachedImage()->image(); |
| 200 return m_bitmap; | 207 return m_bitmap; |
| 201 } | 208 } |
| 202 | 209 |
| 210 void ImageBitmap::trace(Visitor*) |
| 211 { |
| 203 } | 212 } |
| 213 |
| 214 } |
| OLD | NEW |