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/page/ImageBitmap.h" | 6 #include "core/page/ImageBitmap.h" |
7 | 7 |
8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
9 #include "core/html/HTMLImageElement.h" | 9 #include "core/html/HTMLImageElement.h" |
10 #include "core/html/HTMLVideoElement.h" | 10 #include "core/html/HTMLVideoElement.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (m_imageElement) { | 106 if (m_imageElement) { |
107 m_imageElement->addClient(this); | 107 m_imageElement->addClient(this); |
108 m_bitmap = 0; | 108 m_bitmap = 0; |
109 } else { | 109 } else { |
110 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR
ect.y() - oldBitmapRect.y()), cropRect.size()); | 110 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR
ect.y() - oldBitmapRect.y()), cropRect.size()); |
111 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); | 111 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); |
112 } | 112 } |
113 ScriptWrappable::init(this); | 113 ScriptWrappable::init(this); |
114 } | 114 } |
115 | 115 |
| 116 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) |
| 117 : m_cropRect(cropRect) |
| 118 , m_imageElement(0) |
| 119 { |
| 120 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), image->size()))
; |
| 121 m_bitmap = cropImage(image, cropRect); |
| 122 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y())
), srcRect.size()); |
| 123 |
| 124 ScriptWrappable::init(this); |
| 125 } |
| 126 |
116 ImageBitmap::~ImageBitmap() | 127 ImageBitmap::~ImageBitmap() |
117 { | 128 { |
118 if (m_imageElement) | 129 if (m_imageElement) |
119 m_imageElement->removeClient(this); | 130 m_imageElement->removeClient(this); |
120 } | 131 } |
121 | 132 |
122 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe
ct& cropRect) | 133 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe
ct& cropRect) |
123 { | 134 { |
124 IntRect normalizedCropRect = normalizeRect(cropRect); | 135 IntRect normalizedCropRect = normalizeRect(cropRect); |
125 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr
opRect))); | 136 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr
opRect))); |
(...skipping 21 matching lines...) Expand all Loading... |
147 return imageBitmap.release(); | 158 return imageBitmap.release(); |
148 } | 159 } |
149 | 160 |
150 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) | 161 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) |
151 { | 162 { |
152 IntRect normalizedCropRect = normalizeRect(cropRect); | 163 IntRect normalizedCropRect = normalizeRect(cropRect); |
153 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC
ropRect))); | 164 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC
ropRect))); |
154 return imageBitmap.release(); | 165 return imageBitmap.release(); |
155 } | 166 } |
156 | 167 |
| 168 PassRefPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntRect& cropRec
t) |
| 169 { |
| 170 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 171 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr
opRect))); |
| 172 return imageBitmap.release(); |
| 173 } |
| 174 |
157 void ImageBitmap::notifyImageSourceChanged() | 175 void ImageBitmap::notifyImageSourceChanged() |
158 { | 176 { |
159 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); | 177 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); |
160 m_imageElement = 0; | 178 m_imageElement = 0; |
161 } | 179 } |
162 | 180 |
163 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 181 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
164 { | 182 { |
165 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); | 183 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); |
166 if (m_imageElement) | 184 if (m_imageElement) |
167 return cropImage(m_imageElement->cachedImage()->image(), m_cropRect); | 185 return cropImage(m_imageElement->cachedImage()->image(), m_cropRect); |
168 return m_bitmap; | 186 return m_bitmap; |
169 } | 187 } |
170 | 188 |
171 } | 189 } |
OLD | NEW |