| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/graphics/skia/SkiaUtils.h" | 31 #include "platform/graphics/skia/SkiaUtils.h" |
| 32 | 32 |
| 33 #include "platform/graphics/GraphicsContext.h" | 33 #include "platform/graphics/GraphicsContext.h" |
| 34 #include "skia/ext/cdl_common.h" |
| 35 #include "skia/ext/cdl_paint.h" |
| 34 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 36 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| 35 | 37 |
| 36 namespace blink { | 38 namespace blink { |
| 37 | 39 |
| 38 static const struct CompositOpToXfermodeMode { | 40 static const struct CompositOpToXfermodeMode { |
| 39 CompositeOperator mCompositOp; | 41 CompositeOperator mCompositOp; |
| 40 SkBlendMode m_xfermodeMode; | 42 SkBlendMode m_xfermodeMode; |
| 41 } gMapCompositOpsToXfermodeModes[] = { | 43 } gMapCompositOpsToXfermodeModes[] = { |
| 42 {CompositeClear, SkBlendMode::kClear}, | 44 {CompositeClear, SkBlendMode::kClear}, |
| 43 {CompositeCopy, SkBlendMode::kSrc}, | 45 {CompositeCopy, SkBlendMode::kSrc}, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return scaleAlpha(color, clampedAlphaForBlending(alpha)); | 301 return scaleAlpha(color, clampedAlphaForBlending(alpha)); |
| 300 } | 302 } |
| 301 | 303 |
| 302 SkColor scaleAlpha(SkColor color, int alpha) { | 304 SkColor scaleAlpha(SkColor color, int alpha) { |
| 303 int a = (SkColorGetA(color) * alpha) >> 8; | 305 int a = (SkColorGetA(color) * alpha) >> 8; |
| 304 return (color & 0x00FFFFFF) | (a << 24); | 306 return (color & 0x00FFFFFF) | (a << 24); |
| 305 } | 307 } |
| 306 | 308 |
| 307 template <typename PrimitiveType> | 309 template <typename PrimitiveType> |
| 308 void drawFocusRingPrimitive(const PrimitiveType&, | 310 void drawFocusRingPrimitive(const PrimitiveType&, |
| 309 SkCanvas*, | 311 CdlCanvas*, |
| 310 const SkPaint&, | 312 const CdlPaint&, |
| 311 float cornerRadius) { | 313 float cornerRadius) { |
| 312 ASSERT_NOT_REACHED(); // Missing an explicit specialization? | 314 ASSERT_NOT_REACHED(); // Missing an explicit specialization? |
| 313 } | 315 } |
| 314 | 316 |
| 315 template <> | 317 template <> |
| 316 void drawFocusRingPrimitive<SkRect>(const SkRect& rect, | 318 void drawFocusRingPrimitive<SkRect>(const SkRect& rect, |
| 317 SkCanvas* canvas, | 319 CdlCanvas* canvas, |
| 318 const SkPaint& paint, | 320 const CdlPaint& paint, |
| 319 float cornerRadius) { | 321 float cornerRadius) { |
| 320 SkRRect rrect; | 322 SkRRect rrect; |
| 321 rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), | 323 rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), |
| 322 SkFloatToScalar(cornerRadius)); | 324 SkFloatToScalar(cornerRadius)); |
| 323 canvas->drawRRect(rrect, paint); | 325 canvas->drawRRect(rrect, paint); |
| 324 } | 326 } |
| 325 | 327 |
| 326 template <> | 328 template <> |
| 327 void drawFocusRingPrimitive<SkPath>(const SkPath& path, | 329 void drawFocusRingPrimitive<SkPath>(const SkPath& path, |
| 328 SkCanvas* canvas, | 330 CdlCanvas* canvas, |
| 329 const SkPaint& paint, | 331 const CdlPaint& paint, |
| 330 float cornerRadius) { | 332 float cornerRadius) { |
| 331 SkPaint pathPaint = paint; | 333 CdlPaint pathPaint = paint; |
| 332 pathPaint.setPathEffect( | 334 pathPaint.setPathEffect( |
| 333 SkCornerPathEffect::Make(SkFloatToScalar(cornerRadius))); | 335 SkCornerPathEffect::Make(SkFloatToScalar(cornerRadius))); |
| 334 canvas->drawPath(path, pathPaint); | 336 canvas->drawPath(path, pathPaint); |
| 335 } | 337 } |
| 336 | 338 |
| 337 template <typename PrimitiveType> | 339 template <typename PrimitiveType> |
| 338 void drawPlatformFocusRing(const PrimitiveType& primitive, | 340 void drawPlatformFocusRing(const PrimitiveType& primitive, |
| 339 SkCanvas* canvas, | 341 CdlCanvas* canvas, |
| 340 SkColor color, | 342 SkColor color, |
| 341 float width) { | 343 float width) { |
| 342 SkPaint paint; | 344 CdlPaint paint; |
| 343 paint.setAntiAlias(true); | 345 paint.setAntiAlias(true); |
| 344 paint.setStyle(SkPaint::kStroke_Style); | 346 paint.setStyle(CdlPaint::kStroke_Style); |
| 345 paint.setColor(color); | 347 paint.setColor(color); |
| 346 paint.setStrokeWidth(width); | 348 paint.setStrokeWidth(width); |
| 347 | 349 |
| 348 #if OS(MACOSX) | 350 #if OS(MACOSX) |
| 349 paint.setAlpha(64); | 351 paint.setAlpha(64); |
| 350 const float cornerRadius = (width - 1) * 0.5f; | 352 const float cornerRadius = (width - 1) * 0.5f; |
| 351 #else | 353 #else |
| 352 const float cornerRadius = width; | 354 const float cornerRadius = width; |
| 353 #endif | 355 #endif |
| 354 | 356 |
| 355 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); | 357 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
| 356 | 358 |
| 357 #if OS(MACOSX) | 359 #if OS(MACOSX) |
| 358 // Inner part | 360 // Inner part |
| 359 paint.setAlpha(128); | 361 paint.setAlpha(128); |
| 360 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); | 362 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); |
| 361 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); | 363 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
| 362 #endif | 364 #endif |
| 363 } | 365 } |
| 364 | 366 |
| 365 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, | 367 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, |
| 366 SkCanvas*, | 368 CdlCanvas*, |
| 367 SkColor, | 369 SkColor, |
| 368 float width); | 370 float width); |
| 369 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, | 371 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, |
| 370 SkCanvas*, | 372 CdlCanvas*, |
| 371 SkColor, | 373 SkColor, |
| 372 float width); | 374 float width); |
| 373 | 375 |
| 374 } // namespace blink | 376 } // namespace blink |
| OLD | NEW |