| 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 "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/core/frame/ImageBitmap.h" | 6 #include "sky/engine/core/frame/ImageBitmap.h" |
| 7 | 7 |
| 8 #include "sky/engine/core/html/HTMLCanvasElement.h" | |
| 9 #include "sky/engine/core/html/ImageData.h" | 8 #include "sky/engine/core/html/ImageData.h" |
| 10 #include "sky/engine/core/html/canvas/CanvasRenderingContext.h" | |
| 11 #include "sky/engine/platform/graphics/BitmapImage.h" | 9 #include "sky/engine/platform/graphics/BitmapImage.h" |
| 12 #include "sky/engine/platform/graphics/GraphicsContext.h" | 10 #include "sky/engine/platform/graphics/GraphicsContext.h" |
| 13 #include "sky/engine/platform/graphics/ImageBuffer.h" | 11 #include "sky/engine/platform/graphics/ImageBuffer.h" |
| 14 #include "sky/engine/wtf/RefPtr.h" | 12 #include "sky/engine/wtf/RefPtr.h" |
| 15 | 13 |
| 16 namespace blink { | 14 namespace blink { |
| 17 | 15 |
| 18 static inline IntRect normalizeRect(const IntRect& rect) | 16 static inline IntRect normalizeRect(const IntRect& rect) |
| 19 { | 17 { |
| 20 return IntRect(std::min(rect.x(), rect.maxX()), | 18 return IntRect(std::min(rect.x(), rect.maxX()), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | 41 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); |
| 44 m_bitmapOffset = srcRect.location(); | 42 m_bitmapOffset = srcRect.location(); |
| 45 | 43 |
| 46 if (!srcRect.width() || !srcRect.height()) | 44 if (!srcRect.width() || !srcRect.height()) |
| 47 m_imageElement = nullptr; | 45 m_imageElement = nullptr; |
| 48 else | 46 else |
| 49 m_imageElement->addClient(this); | 47 m_imageElement->addClient(this); |
| 50 | 48 |
| 51 } | 49 } |
| 52 | 50 |
| 53 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, const IntRect& cropRect) | |
| 54 : m_imageElement(nullptr) | |
| 55 , m_cropRect(cropRect) | |
| 56 , m_bitmapOffset(IntPoint()) | |
| 57 { | |
| 58 CanvasRenderingContext* sourceContext = canvas->renderingContext(); | |
| 59 if (sourceContext && sourceContext->is3d()) | |
| 60 sourceContext->paintRenderingResultsToCanvas(); | |
| 61 | |
| 62 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), canvas->size())
); | |
| 63 m_bitmapRect = IntRect(IntPoint(std::max(0, -cropRect.x()), std::max(0, -cro
pRect.y())), srcRect.size()); | |
| 64 m_bitmap = cropImage(canvas->buffer()->copyImage(CopyBackingStore).get(), cr
opRect); | |
| 65 } | |
| 66 | |
| 67 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) | 51 ImageBitmap::ImageBitmap(ImageData* data, const IntRect& cropRect) |
| 68 : m_imageElement(nullptr) | 52 : m_imageElement(nullptr) |
| 69 , m_cropRect(cropRect) | 53 , m_cropRect(cropRect) |
| 70 , m_bitmapOffset(IntPoint()) | 54 , m_bitmapOffset(IntPoint()) |
| 71 { | 55 { |
| 72 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); | 56 IntRect srcRect = intersection(cropRect, IntRect(IntPoint(), data->size())); |
| 73 | 57 |
| 74 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); | 58 OwnPtr<ImageBuffer> buf = ImageBuffer::create(data->size()); |
| 75 if (!buf) | 59 if (!buf) |
| 76 return; | 60 return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 m_imageElement->removeClient(this); | 100 m_imageElement->removeClient(this); |
| 117 #endif | 101 #endif |
| 118 } | 102 } |
| 119 | 103 |
| 120 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe
ct& cropRect) | 104 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLImageElement* image, const IntRe
ct& cropRect) |
| 121 { | 105 { |
| 122 IntRect normalizedCropRect = normalizeRect(cropRect); | 106 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 123 return adoptRef(new ImageBitmap(image, normalizedCropRect)); | 107 return adoptRef(new ImageBitmap(image, normalizedCropRect)); |
| 124 } | 108 } |
| 125 | 109 |
| 126 PassRefPtr<ImageBitmap> ImageBitmap::create(HTMLCanvasElement* canvas, const Int
Rect& cropRect) | |
| 127 { | |
| 128 IntRect normalizedCropRect = normalizeRect(cropRect); | |
| 129 return adoptRef(new ImageBitmap(canvas, normalizedCropRect)); | |
| 130 } | |
| 131 | |
| 132 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop
Rect) | 110 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageData* data, const IntRect& crop
Rect) |
| 133 { | 111 { |
| 134 IntRect normalizedCropRect = normalizeRect(cropRect); | 112 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 135 return adoptRef(new ImageBitmap(data, normalizedCropRect)); | 113 return adoptRef(new ImageBitmap(data, normalizedCropRect)); |
| 136 } | 114 } |
| 137 | 115 |
| 138 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) | 116 PassRefPtr<ImageBitmap> ImageBitmap::create(ImageBitmap* bitmap, const IntRect&
cropRect) |
| 139 { | 117 { |
| 140 IntRect normalizedCropRect = normalizeRect(cropRect); | 118 IntRect normalizedCropRect = normalizeRect(cropRect); |
| 141 return adoptRef(new ImageBitmap(bitmap, normalizedCropRect)); | 119 return adoptRef(new ImageBitmap(bitmap, normalizedCropRect)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 } | 133 } |
| 156 | 134 |
| 157 PassRefPtr<Image> ImageBitmap::bitmapImage() const | 135 PassRefPtr<Image> ImageBitmap::bitmapImage() const |
| 158 { | 136 { |
| 159 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); | 137 ASSERT((m_imageElement || m_bitmap || !m_bitmapRect.width() || !m_bitmapRect
.height()) && (!m_imageElement || !m_bitmap)); |
| 160 if (m_imageElement) | 138 if (m_imageElement) |
| 161 return m_imageElement->cachedImage()->image(); | 139 return m_imageElement->cachedImage()->image(); |
| 162 return m_bitmap; | 140 return m_bitmap; |
| 163 } | 141 } |
| 164 | 142 |
| 165 PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageMode, SourceIm
ageStatus* status) const | |
| 166 { | |
| 167 *status = NormalSourceImageStatus; | |
| 168 return bitmapImage(); | |
| 169 } | 143 } |
| 170 | |
| 171 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const | |
| 172 { | |
| 173 FloatRect intersectRect = intersection(m_bitmapRect, *srcRect); | |
| 174 FloatRect newSrcRect = intersectRect; | |
| 175 newSrcRect.move(m_bitmapOffset - m_bitmapRect.location()); | |
| 176 FloatRect newDstRect(FloatPoint(intersectRect.location() - srcRect->location
()), m_bitmapRect.size()); | |
| 177 newDstRect.scale(dstRect->width() / srcRect->width() * intersectRect.width()
/ m_bitmapRect.width(), | |
| 178 dstRect->height() / srcRect->height() * intersectRect.height() / m_bitma
pRect.height()); | |
| 179 newDstRect.moveBy(dstRect->location()); | |
| 180 *srcRect = newSrcRect; | |
| 181 *dstRect = newDstRect; | |
| 182 } | |
| 183 | |
| 184 FloatSize ImageBitmap::sourceSize() const | |
| 185 { | |
| 186 return FloatSize(width(), height()); | |
| 187 } | |
| 188 | |
| 189 } | |
| OLD | NEW |