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 "platform/graphics/paint/PaintFlags.h" |
34 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 35 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 static const struct CompositOpToXfermodeMode { | 39 static const struct CompositOpToXfermodeMode { |
39 CompositeOperator mCompositOp; | 40 CompositeOperator mCompositOp; |
40 SkBlendMode m_xfermodeMode; | 41 SkBlendMode m_xfermodeMode; |
41 } gMapCompositOpsToXfermodeModes[] = { | 42 } gMapCompositOpsToXfermodeModes[] = { |
42 {CompositeClear, SkBlendMode::kClear}, | 43 {CompositeClear, SkBlendMode::kClear}, |
43 {CompositeCopy, SkBlendMode::kSrc}, | 44 {CompositeCopy, SkBlendMode::kSrc}, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 return scaleAlpha(color, clampedAlphaForBlending(alpha)); | 300 return scaleAlpha(color, clampedAlphaForBlending(alpha)); |
300 } | 301 } |
301 | 302 |
302 SkColor scaleAlpha(SkColor color, int alpha) { | 303 SkColor scaleAlpha(SkColor color, int alpha) { |
303 int a = (SkColorGetA(color) * alpha) >> 8; | 304 int a = (SkColorGetA(color) * alpha) >> 8; |
304 return (color & 0x00FFFFFF) | (a << 24); | 305 return (color & 0x00FFFFFF) | (a << 24); |
305 } | 306 } |
306 | 307 |
307 template <typename PrimitiveType> | 308 template <typename PrimitiveType> |
308 void drawFocusRingPrimitive(const PrimitiveType&, | 309 void drawFocusRingPrimitive(const PrimitiveType&, |
309 SkCanvas*, | 310 PaintCanvas*, |
310 const SkPaint&, | 311 const PaintFlags&, |
311 float cornerRadius) { | 312 float cornerRadius) { |
312 ASSERT_NOT_REACHED(); // Missing an explicit specialization? | 313 ASSERT_NOT_REACHED(); // Missing an explicit specialization? |
313 } | 314 } |
314 | 315 |
315 template <> | 316 template <> |
316 void drawFocusRingPrimitive<SkRect>(const SkRect& rect, | 317 void drawFocusRingPrimitive<SkRect>(const SkRect& rect, |
317 SkCanvas* canvas, | 318 PaintCanvas* canvas, |
318 const SkPaint& paint, | 319 const PaintFlags& paint, |
319 float cornerRadius) { | 320 float cornerRadius) { |
320 SkRRect rrect; | 321 SkRRect rrect; |
321 rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), | 322 rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), |
322 SkFloatToScalar(cornerRadius)); | 323 SkFloatToScalar(cornerRadius)); |
323 canvas->drawRRect(rrect, paint); | 324 canvas->drawRRect(rrect, paint); |
324 } | 325 } |
325 | 326 |
326 template <> | 327 template <> |
327 void drawFocusRingPrimitive<SkPath>(const SkPath& path, | 328 void drawFocusRingPrimitive<SkPath>(const SkPath& path, |
328 SkCanvas* canvas, | 329 PaintCanvas* canvas, |
329 const SkPaint& paint, | 330 const PaintFlags& paint, |
330 float cornerRadius) { | 331 float cornerRadius) { |
331 SkPaint pathPaint = paint; | 332 PaintFlags pathPaint = paint; |
332 pathPaint.setPathEffect( | 333 pathPaint.setPathEffect( |
333 SkCornerPathEffect::Make(SkFloatToScalar(cornerRadius))); | 334 SkCornerPathEffect::Make(SkFloatToScalar(cornerRadius))); |
334 canvas->drawPath(path, pathPaint); | 335 canvas->drawPath(path, pathPaint); |
335 } | 336 } |
336 | 337 |
337 template <typename PrimitiveType> | 338 template <typename PrimitiveType> |
338 void drawPlatformFocusRing(const PrimitiveType& primitive, | 339 void drawPlatformFocusRing(const PrimitiveType& primitive, |
339 SkCanvas* canvas, | 340 PaintCanvas* canvas, |
340 SkColor color, | 341 SkColor color, |
341 float width) { | 342 float width) { |
342 SkPaint paint; | 343 PaintFlags paint; |
343 paint.setAntiAlias(true); | 344 paint.setAntiAlias(true); |
344 paint.setStyle(SkPaint::kStroke_Style); | 345 paint.setStyle(PaintFlags::kStroke_Style); |
345 paint.setColor(color); | 346 paint.setColor(color); |
346 paint.setStrokeWidth(width); | 347 paint.setStrokeWidth(width); |
347 | 348 |
348 #if OS(MACOSX) | 349 #if OS(MACOSX) |
349 paint.setAlpha(64); | 350 paint.setAlpha(64); |
350 const float cornerRadius = (width - 1) * 0.5f; | 351 const float cornerRadius = (width - 1) * 0.5f; |
351 #else | 352 #else |
352 const float cornerRadius = width; | 353 const float cornerRadius = width; |
353 #endif | 354 #endif |
354 | 355 |
355 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); | 356 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
356 | 357 |
357 #if OS(MACOSX) | 358 #if OS(MACOSX) |
358 // Inner part | 359 // Inner part |
359 paint.setAlpha(128); | 360 paint.setAlpha(128); |
360 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); | 361 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); |
361 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); | 362 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
362 #endif | 363 #endif |
363 } | 364 } |
364 | 365 |
365 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, | 366 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, |
366 SkCanvas*, | 367 PaintCanvas*, |
367 SkColor, | 368 SkColor, |
368 float width); | 369 float width); |
369 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, | 370 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, |
370 SkCanvas*, | 371 PaintCanvas*, |
371 SkColor, | 372 SkColor, |
372 float width); | 373 float width); |
373 | 374 |
374 } // namespace blink | 375 } // namespace blink |
OLD | NEW |