Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 static inline FloatRect normalizeRect(const FloatRect& rect) | 1186 static inline FloatRect normalizeRect(const FloatRect& rect) |
| 1187 { | 1187 { |
| 1188 return FloatRect(min(rect.x(), rect.maxX()), | 1188 return FloatRect(min(rect.x(), rect.maxX()), |
| 1189 min(rect.y(), rect.maxY()), | 1189 min(rect.y(), rect.maxY()), |
| 1190 max(rect.width(), -rect.width()), | 1190 max(rect.width(), -rect.width()), |
| 1191 max(rect.height(), -rect.height())); | 1191 max(rect.height(), -rect.height())); |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 void CanvasRenderingContext2D::drawImageInternal(Image* image, const FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMode& blendMode) | 1194 template<class T> void CanvasRenderingContext2D::drawImageInternal(T* image, con st FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator& op, co nst BlendMode& blendMode) |
| 1195 { | 1195 { |
| 1196 if (!image) | 1196 if (!image) |
| 1197 return; | 1197 return; |
| 1198 | 1198 |
| 1199 GraphicsContext* c = drawingContext(); | 1199 GraphicsContext* c = drawingContext(); |
| 1200 if (!c) | 1200 if (!c) |
| 1201 return; | 1201 return; |
| 1202 if (!state().m_invertibleCTM) | 1202 if (!state().m_invertibleCTM) |
| 1203 return; | 1203 return; |
| 1204 | 1204 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()); | |
| 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 if (bitmap->canvasImage()) { |
| 1279 | 1275 FloatRect originalCropRect(bitmap->cropRect()); |
| 1280 drawImageInternal(imageForRendering, normalizedSrcRect, actualDstRect, state ().m_globalComposite, state().m_globalBlend); | 1276 normalizedSrcRect.moveBy(originalCropRect.location()); |
| 1277 FloatRect actualSrcRect = intersection(originalCropRect, normalizedSrcRe ct); | |
| 1278 drawImageInternal(bitmap->canvasImage(), actualSrcRect, normalizedDstRec t, state().m_globalComposite, state().m_globalBlend); | |
| 1279 } else { | |
| 1280 FloatRect actualDstRect(FloatPoint(bitmap->bitmapOffset()), bitmap->bitm apSize()); | |
| 1281 actualDstRect.scale(normalizedDstRect.width() / bitmap->width(), normali zedDstRect.height() / bitmap->height()); | |
| 1282 actualDstRect.moveBy(normalizedDstRect.location()); | |
| 1283 drawImageInternal(bitmap->bitmapImage().get(), normalizedSrcRect, actual DstRect, state().m_globalComposite, state().m_globalBlend); | |
| 1284 } | |
| 1281 } | 1285 } |
| 1282 | 1286 |
| 1283 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec) | 1287 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec) |
| 1284 { | 1288 { |
| 1285 if (!image) { | 1289 if (!image) { |
| 1286 ec = TypeMismatchError; | 1290 ec = TypeMismatchError; |
| 1287 return; | 1291 return; |
| 1288 } | 1292 } |
| 1289 LayoutSize s = size(image); | 1293 LayoutSize s = size(image); |
| 1290 drawImage(image, x, y, s.width(), s.height(), ec); | 1294 drawImage(image, x, y, s.width(), s.height(), ec); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1604 | 1608 |
| 1605 c->drawImageBuffer(buffer, bufferRect.location(), state().m_globalComposite) ; | 1609 c->drawImageBuffer(buffer, bufferRect.location(), state().m_globalComposite) ; |
| 1606 c->restore(); | 1610 c->restore(); |
| 1607 } | 1611 } |
| 1608 | 1612 |
| 1609 static void drawImageToContext(Image* image, GraphicsContext* context, FloatRect & dest, const FloatRect& src, CompositeOperator op) | 1613 static void drawImageToContext(Image* image, GraphicsContext* context, FloatRect & dest, const FloatRect& src, CompositeOperator op) |
| 1610 { | 1614 { |
| 1611 context->drawImage(image, dest, src, op); | 1615 context->drawImage(image, dest, src, op); |
| 1612 } | 1616 } |
| 1613 | 1617 |
| 1618 static void drawImageToContext(SkImage* image, GraphicsContext* context, FloatRe ct& dest, const FloatRect& src, CompositeOperator op) | |
|
Justin Novosad
2013/07/22 15:35:41
Don't use skia classes outside of core/platform/ u
| |
| 1619 { | |
| 1620 context->drawImage(image, dest, src, op); | |
| 1621 } | |
| 1622 | |
| 1614 static void drawImageToContext(ImageBuffer* imageBuffer, GraphicsContext* contex t, const FloatRect& dest, const FloatRect& src, CompositeOperator op) | 1623 static void drawImageToContext(ImageBuffer* imageBuffer, GraphicsContext* contex t, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
| 1615 { | 1624 { |
| 1616 context->drawImageBuffer(imageBuffer, dest, src, op); | 1625 context->drawImageBuffer(imageBuffer, dest, src, op); |
| 1617 } | 1626 } |
| 1618 | 1627 |
| 1619 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) | 1628 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
| 1620 { | 1629 { |
| 1621 ASSERT(isFullCanvasCompositeMode(op)); | 1630 ASSERT(isFullCanvasCompositeMode(op)); |
| 1622 | 1631 |
| 1623 IntSize croppedOffset; | 1632 IntSize croppedOffset; |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2301 } | 2310 } |
| 2302 | 2311 |
| 2303 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const | 2312 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const |
| 2304 { | 2313 { |
| 2305 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); | 2314 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); |
| 2306 attributes->setAlpha(m_hasAlpha); | 2315 attributes->setAlpha(m_hasAlpha); |
| 2307 return attributes.release(); | 2316 return attributes.release(); |
| 2308 } | 2317 } |
| 2309 | 2318 |
| 2310 } // namespace WebCore | 2319 } // namespace WebCore |
| OLD | NEW |