Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1415)

Unified Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 1466773002: Make ImageBitmap::cropImage a static function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/ImageBitmap.cpp
diff --git a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
index 60f71c7f1a8f29312bdf1527b31549a72dee39f2..0d76f4f97cfbdcc40989fda51036e71c09440038 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmap.cpp
@@ -27,6 +27,31 @@ static inline IntRect normalizeRect(const IntRect& rect)
std::max(rect.height(), -rect.height()));
}
+static PassRefPtr<SkImage> cropImage(PassRefPtr<SkImage> image, const IntRect& cropRect)
+{
+ ASSERT(image);
+
+ IntRect imgRect(IntPoint(), IntSize(image->width(), image->height()));
+ const IntRect srcRect = intersection(imgRect, cropRect);
+
+ if (cropRect == srcRect)
+ return adoptRef(image->newSubset(srcRect));
+
+ RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.width(), cropRect.height()));
+
+ if (srcRect.isEmpty())
+ return adoptRef(surface->newImageSnapshot());
+
+ SkScalar dstLeft = std::min(0, -cropRect.x());
+ SkScalar dstTop = std::min(0, -cropRect.y());
+ if (cropRect.x() < 0)
+ dstLeft = -cropRect.x();
+ if (cropRect.y() < 0)
+ dstTop = -cropRect.y();
+ surface->getCanvas()->drawImage(image.get(), dstLeft, dstTop);
+ return adoptRef(surface->newImageSnapshot());
+}
+
ImageBitmap::ImageBitmap(HTMLImageElement* image, const IntRect& cropRect)
{
m_image = cropImage(image->cachedImage()->image()->imageForCurrentFrame(), cropRect);
@@ -127,31 +152,6 @@ PassRefPtrWillBeRawPtr<ImageBitmap> ImageBitmap::create(Image* image, const IntR
return adoptRefWillBeNoop(new ImageBitmap(image, normalizedCropRect));
}
-PassRefPtr<SkImage> ImageBitmap::cropImage(PassRefPtr<SkImage> image, const IntRect& cropRect)
-{
- ASSERT(image);
-
- IntRect imgRect = IntRect(IntPoint(), IntSize(image->width(), image->height()));
- const IntRect srcRect = intersection(imgRect, cropRect);
-
- if (cropRect == srcRect)
- return adoptRef(image->newSubset(srcRect));
-
- RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect.width(), cropRect.height()));
-
- if (srcRect.isEmpty())
- return adoptRef(surface->newImageSnapshot());
-
- SkScalar dstLeft = std::min(0, -cropRect.x());
- SkScalar dstTop = std::min(0, -cropRect.y());
- if (cropRect.x() < 0)
- dstLeft = -cropRect.x();
- if (cropRect.y() < 0)
- dstTop = -cropRect.y();
- surface->getCanvas()->drawImage(image.get(), dstLeft, dstTop);
- return adoptRef(surface->newImageSnapshot());
-}
-
unsigned long ImageBitmap::width() const
{
if (!m_image)
@@ -188,7 +188,6 @@ PassRefPtr<Image> ImageBitmap::getSourceImageForCanvas(SourceImageStatus* status
void ImageBitmap::adjustDrawRects(FloatRect* srcRect, FloatRect* dstRect) const
{
-
}
FloatSize ImageBitmap::elementSize() const
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698