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 return adoptRef(new ImageBitmap(image, normalizedCropRect)); |
132 return imageBitmap.release(); | |
133 } | 143 } |
134 | 144 |
135 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRe
ct& cropRect) | 145 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLVideoElement* video, const IntRe
ct& cropRect) |
136 { | 146 { |
137 IntRect normalizedCropRect = normalizeRect(cropRect); | 147 IntRect normalizedCropRect = normalizeRect(cropRect); |
138 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(video, normalizedCr
opRect))); | 148 return adoptRef(new ImageBitmap(video, normalizedCropRect)); |
139 return imageBitmap.release(); | |
140 } | 149 } |
141 | 150 |
142 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const Int
Rect& cropRect) | 151 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const Int
Rect& cropRect) |
143 { | 152 { |
144 IntRect normalizedCropRect = normalizeRect(cropRect); | 153 IntRect normalizedCropRect = normalizeRect(cropRect); |
145 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(canvas, normalizedC
ropRect))); | 154 return adoptRef(new ImageBitmap(canvas, normalizedCropRect)); |
146 return imageBitmap.release(); | |
147 } | 155 } |
148 | 156 |
149 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop
Rect) | 157 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop
Rect) |
150 { | 158 { |
151 IntRect normalizedCropRect = normalizeRect(cropRect); | 159 IntRect normalizedCropRect = normalizeRect(cropRect); |
152 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(data, normalizedCro
pRect))); | 160 return adoptRef(new ImageBitmap(data, normalizedCropRect)); |
153 return imageBitmap.release(); | |
154 } | 161 } |
155 | 162 |
156 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) | 163 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) |
157 { | 164 { |
158 IntRect normalizedCropRect = normalizeRect(cropRect); | 165 IntRect normalizedCropRect = normalizeRect(cropRect); |
159 RefPtr<ImageBitmap> imageBitmap(adoptRef(new ImageBitmap(bitmap, normalizedC
ropRect))); | 166 return adoptRef(new ImageBitmap(bitmap, normalizedCropRect)); |
160 return imageBitmap.release(); | 167 } |
| 168 |
| 169 PassRefPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntRect& cropRec
t) |
| 170 { |
| 171 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 172 return adoptRef(new ImageBitmap(image, normalizedCropRect)); |
161 } | 173 } |
162 | 174 |
163 void ImageBitmap::notifyImageSourceChanged() | 175 void ImageBitmap::notifyImageSourceChanged() |
164 { | 176 { |
165 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); | 177 m_bitmap = cropImage(m_imageElement->cachedImage()->image(), m_cropRect); |
166 m_bitmapOffset = IntPoint(); | 178 m_bitmapOffset = IntPoint(); |
167 m_imageElement = 0; | 179 m_imageElement = 0; |
168 } | 180 } |
169 | 181 |
170 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 182 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
171 { | 183 { |
172 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); | 184 ASSERT((m_imageElement || m_bitmap) && (!m_imageElement || !m_bitmap)); |
173 if (m_imageElement) | 185 if (m_imageElement) |
174 return m_imageElement->cachedImage()->image(); | 186 return m_imageElement->cachedImage()->image(); |
175 return m_bitmap; | 187 return m_bitmap; |
176 } | 188 } |
177 | 189 |
178 } | 190 } |
OLD | NEW |