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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 19705006: Use SkImage as a backing store for copying 2d Contexts to ImageBitmaps. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Change SkImage to use srcRect pointer. Created 7 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 FloatRect dstRect(dx, dy, dw, dh); 1253 FloatRect dstRect(dx, dy, dw, dh);
1254 1254
1255 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi nite(dstRect.width()) || !std::isfinite(dstRect.height()) 1255 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi nite(dstRect.width()) || !std::isfinite(dstRect.height())
1256 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i sfinite(srcRect.width()) || !std::isfinite(srcRect.height())) 1256 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i sfinite(srcRect.width()) || !std::isfinite(srcRect.height()))
1257 return; 1257 return;
1258 1258
1259 if (!dstRect.width() || !dstRect.height()) 1259 if (!dstRect.width() || !dstRect.height())
1260 return; 1260 return;
1261 1261
1262 ASSERT(bitmap->height() && bitmap->width()); 1262 ASSERT(bitmap->height() && bitmap->width());
1263
1264 FloatRect normalizedSrcRect = normalizeRect(srcRect); 1263 FloatRect normalizedSrcRect = normalizeRect(srcRect);
1265 FloatRect normalizedDstRect = normalizeRect(dstRect); 1264 FloatRect normalizedDstRect = normalizeRect(dstRect);
1266 FloatRect actualDstRect(FloatPoint(bitmap->bitmapOffset()), bitmap->bitmapSi ze());
1267 actualDstRect.scale(normalizedDstRect.width() / bitmap->width(), normalizedD stRect.height() / bitmap->height());
Justin Novosad 2013/07/22 15:35:41 This is not correct. What you should be doing here
1268 actualDstRect.moveBy(normalizedDstRect.location());
1269 1265
1270 FloatRect imageRect = FloatRect(FloatPoint(), bitmap->bitmapSize()); 1266 FloatRect imageRect = FloatRect(FloatPoint(), bitmap->bitmapSize());
1271 if (!srcRect.width() || !srcRect.height()) { 1267 if (!srcRect.width() || !srcRect.height()) {
1272 ec = IndexSizeError; 1268 ec = IndexSizeError;
1273 return; 1269 return;
1274 } 1270 }
1275 if (!imageRect.contains(normalizedSrcRect)) 1271 if (!imageRect.contains(normalizedSrcRect))
1276 return; 1272 return;
1277 1273
1278 Image* imageForRendering = bitmap->bitmapImage(); 1274 Image* imageForRendering = bitmap->bitmapImage().get();
1279 1275 if (bitmap->derivedFromCanvas()) {
1280 drawImageInternal(imageForRendering, normalizedSrcRect, actualDstRect, state ().m_globalComposite, state().m_globalBlend); 1276 FloatRect originalCropRect(bitmap->cropRect());
1277 normalizedSrcRect.moveBy(originalCropRect.location());
1278 FloatRect actualSrcRect = intersection(originalCropRect, normalizedSrcRe ct);
1279 drawImageInternal(imageForRendering, actualSrcRect, normalizedDstRect, s tate().m_globalComposite, state().m_globalBlend);
1280 } else {
1281 FloatRect actualDstRect(FloatPoint(bitmap->bitmapOffset()), bitmap->bitm apSize());
1282 actualDstRect.scale(normalizedDstRect.width() / bitmap->width(), normali zedDstRect.height() / bitmap->height());
1283 actualDstRect.moveBy(normalizedDstRect.location());
1284 drawImageInternal(imageForRendering, normalizedSrcRect, actualDstRect, s tate().m_globalComposite, state().m_globalBlend);
1285 }
1281 } 1286 }
1282 1287
1283 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec) 1288 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec)
1284 { 1289 {
1285 if (!image) { 1290 if (!image) {
1286 ec = TypeMismatchError; 1291 ec = TypeMismatchError;
1287 return; 1292 return;
1288 } 1293 }
1289 LayoutSize s = size(image); 1294 LayoutSize s = size(image);
1290 drawImage(image, x, y, s.width(), s.height(), ec); 1295 drawImage(image, x, y, s.width(), s.height(), ec);
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 } 2306 }
2302 2307
2303 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const 2308 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const
2304 { 2309 {
2305 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); 2310 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate();
2306 attributes->setAlpha(m_hasAlpha); 2311 attributes->setAlpha(m_hasAlpha);
2307 return attributes.release(); 2312 return attributes.release();
2308 } 2313 }
2309 2314
2310 } // namespace WebCore 2315 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698