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

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

Issue 27142003: Revert "Use srcset's resource pixel density to determine intrinsic size" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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
« no previous file with comments | « Source/core/html/HTMLImageElement.cpp ('k') | Source/core/html/parser/HTMLSrcsetParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "core/html/TextMetrics.h" 52 #include "core/html/TextMetrics.h"
53 #include "core/html/canvas/Canvas2DContextAttributes.h" 53 #include "core/html/canvas/Canvas2DContextAttributes.h"
54 #include "core/html/canvas/CanvasGradient.h" 54 #include "core/html/canvas/CanvasGradient.h"
55 #include "core/html/canvas/CanvasPattern.h" 55 #include "core/html/canvas/CanvasPattern.h"
56 #include "core/html/canvas/CanvasStyle.h" 56 #include "core/html/canvas/CanvasStyle.h"
57 #include "core/html/canvas/DOMPath.h" 57 #include "core/html/canvas/DOMPath.h"
58 #include "core/frame/ImageBitmap.h" 58 #include "core/frame/ImageBitmap.h"
59 #include "core/platform/graphics/DrawLooper.h" 59 #include "core/platform/graphics/DrawLooper.h"
60 #include "core/platform/graphics/FontCache.h" 60 #include "core/platform/graphics/FontCache.h"
61 #include "core/platform/graphics/GraphicsContextStateSaver.h" 61 #include "core/platform/graphics/GraphicsContextStateSaver.h"
62 #include "core/rendering/RenderImage.h"
63 #include "core/rendering/RenderLayer.h" 62 #include "core/rendering/RenderLayer.h"
64 #include "core/rendering/RenderTheme.h" 63 #include "core/rendering/RenderTheme.h"
65 #include "platform/geometry/FloatQuad.h" 64 #include "platform/geometry/FloatQuad.h"
66 #include "platform/graphics/TextRun.h" 65 #include "platform/graphics/TextRun.h"
67 #include "platform/transforms/AffineTransform.h" 66 #include "platform/transforms/AffineTransform.h"
68 #include "weborigin/SecurityOrigin.h" 67 #include "weborigin/SecurityOrigin.h"
69 #include "wtf/CheckedArithmetic.h" 68 #include "wtf/CheckedArithmetic.h"
70 #include "wtf/MathExtras.h" 69 #include "wtf/MathExtras.h"
71 #include "wtf/OwnPtr.h" 70 #include "wtf/OwnPtr.h"
72 #include "wtf/Uint8ClampedArray.h" 71 #include "wtf/Uint8ClampedArray.h"
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 } else { 1205 } else {
1207 c->clearShadow(); 1206 c->clearShadow();
1208 } 1207 }
1209 } 1208 }
1210 1209
1211 bool CanvasRenderingContext2D::shouldDrawShadows() const 1210 bool CanvasRenderingContext2D::shouldDrawShadows() const
1212 { 1211 {
1213 return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !stat e().m_shadowOffset.isZero()); 1212 return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !stat e().m_shadowOffset.isZero());
1214 } 1213 }
1215 1214
1216 enum ImageSizeType { 1215 static LayoutSize sizeFor(HTMLImageElement* image)
1217 ImageSizeAfterDevicePixelRatio,
1218 ImageSizeBeforeDevicePixelRatio
1219 };
1220
1221 static LayoutSize sizeFor(HTMLImageElement* image, ImageSizeType sizeType)
1222 { 1216 {
1223 LayoutSize size; 1217 if (ImageResource* cachedImage = image->cachedImage())
1224 ImageResource* cachedImage = image->cachedImage(); 1218 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI XME: Not sure about this.
1225 if (cachedImage) { 1219 return IntSize();
1226 size = cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI XME: Not sure about this.
1227
1228 if (sizeType == ImageSizeAfterDevicePixelRatio && image->renderer() && i mage->renderer()->isRenderImage() && cachedImage->image() && !cachedImage->image ()->hasRelativeWidth())
1229 size.scale(toRenderImage(image->renderer())->imageDevicePixelRatio() );
1230 }
1231 return size;
1232 } 1220 }
1233 1221
1234 static IntSize sizeFor(HTMLVideoElement* video) 1222 static IntSize sizeFor(HTMLVideoElement* video)
1235 { 1223 {
1236 if (MediaPlayer* player = video->player()) 1224 if (MediaPlayer* player = video->player())
1237 return player->naturalSize(); 1225 return player->naturalSize();
1238 return IntSize(); 1226 return IntSize();
1239 } 1227 }
1240 1228
1241 static inline FloatRect normalizeRect(const FloatRect& rect) 1229 static inline FloatRect normalizeRect(const FloatRect& rect)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 1360
1373 drawImageInternal(imageForRendering.get(), actualSrcRect, actualDstRect, sta te().m_globalComposite, state().m_globalBlend); 1361 drawImageInternal(imageForRendering.get(), actualSrcRect, actualDstRect, sta te().m_globalComposite, state().m_globalBlend);
1374 } 1362 }
1375 1363
1376 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionState& es) 1364 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionState& es)
1377 { 1365 {
1378 if (!image) { 1366 if (!image) {
1379 es.throwUninformativeAndGenericDOMException(TypeMismatchError); 1367 es.throwUninformativeAndGenericDOMException(TypeMismatchError);
1380 return; 1368 return;
1381 } 1369 }
1382 LayoutSize destRectSize = sizeFor(image, ImageSizeAfterDevicePixelRatio); 1370 LayoutSize size = sizeFor(image);
1383 drawImage(image, x, y, destRectSize.width(), destRectSize.height(), es); 1371 drawImage(image, x, y, size.width(), size.height(), es);
1384 } 1372 }
1385 1373
1386 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, 1374 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
1387 float x, float y, float width, float height, ExceptionState& es) 1375 float x, float y, float width, float height, ExceptionState& es)
1388 { 1376 {
1389 if (!image) { 1377 if (!image) {
1390 es.throwUninformativeAndGenericDOMException(TypeMismatchError); 1378 es.throwUninformativeAndGenericDOMException(TypeMismatchError);
1391 return; 1379 return;
1392 } 1380 }
1393 LayoutSize sourceRectSize = sizeFor(image, ImageSizeBeforeDevicePixelRatio); 1381 LayoutSize size = sizeFor(image);
1394 drawImage(image, FloatRect(0, 0, sourceRectSize.width(), sourceRectSize.heig ht()), FloatRect(x, y, width, height), es); 1382 drawImage(image, FloatRect(0, 0, size.width(), size.height()), FloatRect(x, y, width, height), es);
1395 } 1383 }
1396 1384
1397 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, 1385 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
1398 float sx, float sy, float sw, float sh, 1386 float sx, float sy, float sw, float sh,
1399 float dx, float dy, float dw, float dh, ExceptionState& es) 1387 float dx, float dy, float dw, float dh, ExceptionState& es)
1400 { 1388 {
1401 drawImage(image, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), es); 1389 drawImage(image, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), es);
1402 } 1390 }
1403 1391
1404 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec t& srcRect, const FloatRect& dstRect, ExceptionState& es) 1392 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec t& srcRect, const FloatRect& dstRect, ExceptionState& es)
1405 { 1393 {
1406 drawImage(image, srcRect, dstRect, state().m_globalComposite, state().m_glob alBlend, es); 1394 drawImage(image, srcRect, dstRect, state().m_globalComposite, state().m_glob alBlend, es);
1407 } 1395 }
1408 1396
1409 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec t& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMo de& blendMode, ExceptionState& es) 1397 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRec t& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMo de& blendMode, ExceptionState& es)
1410 { 1398 {
1411 if (!image) { 1399 if (!image) {
1412 es.throwUninformativeAndGenericDOMException(TypeMismatchError); 1400 es.throwUninformativeAndGenericDOMException(TypeMismatchError);
1413 return; 1401 return;
1414 } 1402 }
1415 1403
1416 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi nite(dstRect.width()) || !std::isfinite(dstRect.height()) 1404 if (!std::isfinite(dstRect.x()) || !std::isfinite(dstRect.y()) || !std::isfi nite(dstRect.width()) || !std::isfinite(dstRect.height())
1417 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i sfinite(srcRect.width()) || !std::isfinite(srcRect.height())) 1405 || !std::isfinite(srcRect.x()) || !std::isfinite(srcRect.y()) || !std::i sfinite(srcRect.width()) || !std::isfinite(srcRect.height()))
1418 return; 1406 return;
1419 1407
1420 ImageResource* cachedImage = image->cachedImage(); 1408 ImageResource* cachedImage = image->cachedImage();
1421 if (!cachedImage || !image->complete()) 1409 if (!cachedImage || !image->complete())
1422 return; 1410 return;
1423 1411
1424 LayoutSize size = sizeFor(image, ImageSizeBeforeDevicePixelRatio); 1412 LayoutSize size = sizeFor(image);
1425 if (!size.width() || !size.height()) { 1413 if (!size.width() || !size.height()) {
1426 es.throwUninformativeAndGenericDOMException(InvalidStateError); 1414 es.throwUninformativeAndGenericDOMException(InvalidStateError);
1427 return; 1415 return;
1428 } 1416 }
1429 1417
1430 if (!dstRect.width() || !dstRect.height()) 1418 if (!dstRect.width() || !dstRect.height())
1431 return; 1419 return;
1432 1420
1433 FloatRect normalizedSrcRect = normalizeRect(srcRect); 1421 FloatRect normalizedSrcRect = normalizeRect(srcRect);
1434 FloatRect normalizedDstRect = normalizeRect(dstRect); 1422 FloatRect normalizedDstRect = normalizeRect(dstRect);
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 const int focusRingWidth = 5; 2419 const int focusRingWidth = 5;
2432 const int focusRingOutline = 0; 2420 const int focusRingOutline = 0;
2433 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2421 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2434 2422
2435 c->restore(); 2423 c->restore();
2436 2424
2437 didDraw(dirtyRect); 2425 didDraw(dirtyRect);
2438 } 2426 }
2439 2427
2440 } // namespace WebCore 2428 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLImageElement.cpp ('k') | Source/core/html/parser/HTMLSrcsetParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698