| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * THE POSSIBILITY OF SUCH DAMAGE. | 24 * THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "platform/graphics/GraphicsContext.h" | 28 #include "platform/graphics/GraphicsContext.h" |
| 29 | 29 |
| 30 #include "platform/TraceEvent.h" | 30 #include "platform/TraceEvent.h" |
| 31 #include "platform/geometry/IntRect.h" | 31 #include "platform/geometry/IntRect.h" |
| 32 #include "platform/graphics/ColorSpace.h" | 32 #include "platform/graphics/ColorSpace.h" |
| 33 #include "platform/graphics/Gradient.h" | 33 #include "platform/graphics/Gradient.h" |
| 34 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 34 #include "platform/graphics/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
| 35 #include "platform/graphics/paint/PaintController.h" | 36 #include "platform/graphics/paint/PaintController.h" |
| 36 #include "platform/weborigin/KURL.h" | 37 #include "platform/weborigin/KURL.h" |
| 37 #include "skia/ext/platform_device.h" | 38 #include "skia/ext/platform_device.h" |
| 38 #include "third_party/skia/include/core/SkAnnotation.h" | 39 #include "third_party/skia/include/core/SkAnnotation.h" |
| 39 #include "third_party/skia/include/core/SkColorFilter.h" | 40 #include "third_party/skia/include/core/SkColorFilter.h" |
| 40 #include "third_party/skia/include/core/SkData.h" | 41 #include "third_party/skia/include/core/SkData.h" |
| 41 #include "third_party/skia/include/core/SkPicture.h" | 42 #include "third_party/skia/include/core/SkPicture.h" |
| 42 #include "third_party/skia/include/core/SkPictureRecorder.h" | 43 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 43 #include "third_party/skia/include/core/SkRRect.h" | 44 #include "third_party/skia/include/core/SkRRect.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 406 |
| 406 if (focusRingRegion.isRect()) { | 407 if (focusRingRegion.isRect()) { |
| 407 drawFocusRingRect(SkRect::Make(focusRingRegion.getBounds()), color, widt
h); | 408 drawFocusRingRect(SkRect::Make(focusRingRegion.getBounds()), color, widt
h); |
| 408 } else { | 409 } else { |
| 409 SkPath path; | 410 SkPath path; |
| 410 if (focusRingRegion.getBoundaryPath(&path)) | 411 if (focusRingRegion.getBoundaryPath(&path)) |
| 411 drawFocusRingPath(path, color, width); | 412 drawFocusRingPath(path, color, width); |
| 412 } | 413 } |
| 413 } | 414 } |
| 414 | 415 |
| 415 static inline FloatRect areaCastingShadowInHole(const FloatRect& holeRect, int s
hadowBlur, int shadowSpread, const IntSize& shadowOffset) | 416 static inline FloatRect areaCastingShadowInHole(const FloatRect& holeRect, float
shadowBlur, |
| 417 float shadowSpread, const FloatSize& shadowOffset) |
| 416 { | 418 { |
| 417 IntRect bounds(holeRect); | 419 FloatRect bounds(holeRect); |
| 418 | 420 |
| 419 bounds.inflate(shadowBlur); | 421 bounds.inflate(shadowBlur); |
| 420 | 422 |
| 421 if (shadowSpread < 0) | 423 if (shadowSpread < 0) |
| 422 bounds.inflate(-shadowSpread); | 424 bounds.inflate(-shadowSpread); |
| 423 | 425 |
| 424 IntRect offsetBounds = bounds; | 426 FloatRect offsetBounds = bounds; |
| 425 offsetBounds.move(-shadowOffset); | 427 offsetBounds.move(-shadowOffset); |
| 426 return unionRect(bounds, offsetBounds); | 428 return unionRect(bounds, offsetBounds); |
| 427 } | 429 } |
| 428 | 430 |
| 429 void GraphicsContext::drawInnerShadow(const FloatRoundedRect& rect, const Color&
shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edge
s clippedEdges) | 431 void GraphicsContext::drawInnerShadow(const FloatRoundedRect& rect, const Color&
shadowColor, |
| 432 const FloatSize& shadowOffset, float shadowBlur, float shadowSpread, Edges c
lippedEdges) |
| 430 { | 433 { |
| 431 if (contextDisabled()) | 434 if (contextDisabled()) |
| 432 return; | 435 return; |
| 433 | 436 |
| 434 FloatRect holeRect(rect.rect()); | 437 FloatRect holeRect(rect.rect()); |
| 435 holeRect.inflate(-shadowSpread); | 438 holeRect.inflate(-shadowSpread); |
| 436 | 439 |
| 437 if (holeRect.isEmpty()) { | 440 if (holeRect.isEmpty()) { |
| 438 fillRoundedRect(rect, shadowColor); | 441 fillRoundedRect(rect, shadowColor); |
| 439 return; | 442 return; |
| 440 } | 443 } |
| 441 | 444 |
| 442 if (clippedEdges & LeftEdge) { | 445 if (clippedEdges & LeftEdge) { |
| 443 holeRect.move(-std::max(shadowOffset.width(), 0) - shadowBlur, 0); | 446 holeRect.move(-std::max(shadowOffset.width(), 0.0f) - shadowBlur, 0); |
| 444 holeRect.setWidth(holeRect.width() + std::max(shadowOffset.width(), 0) +
shadowBlur); | 447 holeRect.setWidth(holeRect.width() + std::max(shadowOffset.width(), 0.0f
) + shadowBlur); |
| 445 } | 448 } |
| 446 if (clippedEdges & TopEdge) { | 449 if (clippedEdges & TopEdge) { |
| 447 holeRect.move(0, -std::max(shadowOffset.height(), 0) - shadowBlur); | 450 holeRect.move(0, -std::max(shadowOffset.height(), 0.0f) - shadowBlur); |
| 448 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0
) + shadowBlur); | 451 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0
.0f) + shadowBlur); |
| 449 } | 452 } |
| 450 if (clippedEdges & RightEdge) | 453 if (clippedEdges & RightEdge) |
| 451 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0) +
shadowBlur); | 454 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0.0f
) + shadowBlur); |
| 452 if (clippedEdges & BottomEdge) | 455 if (clippedEdges & BottomEdge) |
| 453 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0
) + shadowBlur); | 456 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0
.0f) + shadowBlur); |
| 454 | 457 |
| 455 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(),
255); | 458 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(),
255); |
| 456 | 459 |
| 457 FloatRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shado
wSpread, shadowOffset); | 460 FloatRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shado
wSpread, shadowOffset); |
| 458 FloatRoundedRect roundedHole(holeRect, rect.radii()); | 461 FloatRoundedRect roundedHole(holeRect, rect.radii()); |
| 459 | 462 |
| 460 save(); | 463 GraphicsContextStateSaver stateSaver(*this); |
| 461 if (rect.isRounded()) { | 464 if (rect.isRounded()) { |
| 462 clipRoundedRect(rect); | 465 clipRoundedRect(rect); |
| 463 if (shadowSpread < 0) | 466 if (shadowSpread < 0) |
| 464 roundedHole.expandRadii(-shadowSpread); | 467 roundedHole.expandRadii(-shadowSpread); |
| 465 else | 468 else |
| 466 roundedHole.shrinkRadii(shadowSpread); | 469 roundedHole.shrinkRadii(shadowSpread); |
| 467 } else { | 470 } else { |
| 468 clip(rect.rect()); | 471 clip(rect.rect()); |
| 469 } | 472 } |
| 470 | 473 |
| 471 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); | 474 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); |
| 472 drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor, | 475 drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor, |
| 473 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg
noresAlpha); | 476 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg
noresAlpha); |
| 474 setDrawLooper(drawLooperBuilder.release()); | 477 setDrawLooper(drawLooperBuilder.release()); |
| 475 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); | 478 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); |
| 476 restore(); | |
| 477 clearDrawLooper(); | |
| 478 } | 479 } |
| 479 | 480 |
| 480 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) | 481 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) |
| 481 { | 482 { |
| 482 if (contextDisabled()) | 483 if (contextDisabled()) |
| 483 return; | 484 return; |
| 484 ASSERT(m_canvas); | 485 ASSERT(m_canvas); |
| 485 | 486 |
| 486 StrokeStyle penStyle = strokeStyle(); | 487 StrokeStyle penStyle = strokeStyle(); |
| 487 if (penStyle == NoStroke) | 488 if (penStyle == NoStroke) |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 static const SkPMColor colors[] = { | 1344 static const SkPMColor colors[] = { |
| 1344 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1345 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
| 1345 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1346 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
| 1346 }; | 1347 }; |
| 1347 | 1348 |
| 1348 return colors[index]; | 1349 return colors[index]; |
| 1349 } | 1350 } |
| 1350 #endif | 1351 #endif |
| 1351 | 1352 |
| 1352 } // namespace blink | 1353 } // namespace blink |
| OLD | NEW |