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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 m_imageElement->addClient(this); | 112 m_imageElement->addClient(this); |
113 m_bitmap = 0; | 113 m_bitmap = 0; |
114 m_bitmapOffset = srcRect.location(); | 114 m_bitmapOffset = srcRect.location(); |
115 } else { | 115 } else { |
116 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR ect.y() - oldBitmapRect.y()), cropRect.size()); | 116 IntRect adjustedCropRect(IntPoint(cropRect.x() -oldBitmapRect.x(), cropR ect.y() - oldBitmapRect.y()), cropRect.size()); |
117 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); | 117 m_bitmap = cropImage(bitmap->bitmapImage().get(), adjustedCropRect); |
118 } | 118 } |
119 ScriptWrappable::init(this); | 119 ScriptWrappable::init(this); |
120 } | 120 } |
121 | 121 |
122 ImageBitmap::ImageBitmap(Image* image, const IntRect& cropRect) | |
123 : m_cropRect(cropRect) | |
124 , m_imageElement(0) | |
125 { | |
126 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), image->size())) ; | |
127 m_bitmap = cropImage(image, cropRect); | |
128 m_bitmapRect = IntRect(IntPoint(max(0, -cropRect.x()), max(0, -cropRect.y()) ), srcRect.size()); | |
129 | |
130 ScriptWrappable::init(this); | |
131 } | |
132 | |
122 ImageBitmap::~ImageBitmap() | 133 ImageBitmap::~ImageBitmap() |
123 { | 134 { |
124 if (m_imageElement) | 135 if (m_imageElement) |
125 m_imageElement->removeClient(this); | 136 m_imageElement->removeClient(this); |
126 } | 137 } |
127 | 138 |
128 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe ct& cropRect) | 139 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe ct& cropRect) |
129 { | 140 { |
130 IntRect normalizedCropRect = normalizeRect(cropRect); | 141 IntRect normalizedCropRect = normalizeRect(cropRect); |
131 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr opRect))); | 142 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr opRect))); |
(...skipping 21 matching lines...) Expand all Loading... | |
153 return imageBitmap.release(); | 164 return imageBitmap.release(); |
154 } | 165 } |
155 | 166 |
156 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect) | 167 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect& cropRect) |
157 { | 168 { |
158 IntRect normalizedCropRect = normalizeRect(cropRect); | 169 IntRect normalizedCropRect = normalizeRect(cropRect); |
159 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC ropRect))); | 170 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC ropRect))); |
160 return imageBitmap.release(); | 171 return imageBitmap.release(); |
161 } | 172 } |
162 | 173 |
174 PassRefPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntRect& cropRec t) | |
175 { | |
176 IntRect normalizedCropRect = normalizeRect(cropRect); | |
177 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(image, normalizedCr opRect))); | |
do-not-use
2013/08/12 21:46:19
nit: Useless local variable. We can return adoptRe
| |
178 return imageBitmap.release(); | |
179 } | |
180 | |
163 void ImageBitmap::notifyImageSourceChanged() | 181 void ImageBitmap::notifyImageSourceChanged() |
164 { | 182 { |
165 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); | 183 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); |
166 m_bitmapOffset = IntPoint(); | 184 m_bitmapOffset = IntPoint(); |
167 m_imageElement = 0; | 185 m_imageElement = 0; |
168 } | 186 } |
169 | 187 |
170 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 188 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
171 { | 189 { |
172 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); | 190 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); |
173 if (m_imageElement) | 191 if (m_imageElement) |
174 return m_imageElement->cachedImage()->image(); | 192 return m_imageElement->cachedImage()->image(); |
175 return m_bitmap; | 193 return m_bitmap; |
176 } | 194 } |
177 | 195 |
178 } | 196 } |
OLD | NEW |