OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 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 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "platform/graphics/skia/NativeImageSkia.h" | 32 #include "platform/graphics/skia/NativeImageSkia.h" |
33 | 33 |
34 #include "platform/PlatformInstrumentation.h" | 34 #include "platform/PlatformInstrumentation.h" |
35 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
36 #include "platform/geometry/FloatPoint.h" | 36 #include "platform/geometry/FloatPoint.h" |
37 #include "platform/geometry/FloatRect.h" | 37 #include "platform/geometry/FloatRect.h" |
38 #include "platform/geometry/FloatSize.h" | 38 #include "platform/geometry/FloatSize.h" |
39 #include "platform/graphics/DeferredImageDecoder.h" | |
39 #include "platform/graphics/GraphicsContext.h" | 40 #include "platform/graphics/GraphicsContext.h" |
40 #include "platform/graphics/Image.h" | 41 #include "platform/graphics/Image.h" |
41 #include "platform/graphics/DeferredImageDecoder.h" | |
42 #include "platform/graphics/skia/SkiaUtils.h" | 42 #include "platform/graphics/skia/SkiaUtils.h" |
43 #include "skia/ext/image_operations.h" | 43 #include "skia/ext/image_operations.h" |
44 #include "third_party/skia/include/core/SkMatrix.h" | 44 #include "third_party/skia/include/core/SkMatrix.h" |
45 #include "third_party/skia/include/core/SkPaint.h" | 45 #include "third_party/skia/include/core/SkPaint.h" |
46 #include "third_party/skia/include/core/SkScalar.h" | 46 #include "third_party/skia/include/core/SkScalar.h" |
47 #include "third_party/skia/include/core/SkShader.h" | 47 #include "third_party/skia/include/core/SkShader.h" |
48 | 48 |
49 #include <algorithm> | 49 #include <algorithm> |
50 #include <math.h> | 50 #include <math.h> |
51 #include <limits> | 51 #include <limits> |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 // discouraged. Always drawing with AA can negatively impact performance | 340 // discouraged. Always drawing with AA can negatively impact performance |
341 // though - that's why it's not always on. | 341 // though - that's why it's not always on. |
342 SkScalar widthExpansion, heightExpansion; | 342 SkScalar widthExpansion, heightExpansion; |
343 if (totalMatrix.getType() & SkMatrix::kAffine_Mask) | 343 if (totalMatrix.getType() & SkMatrix::kAffine_Mask) |
344 widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = total Matrix[SkMatrix::kMSkewX]; | 344 widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = total Matrix[SkMatrix::kMSkewX]; |
345 else | 345 else |
346 widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = tota lMatrix[SkMatrix::kMScaleY]; | 346 widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = tota lMatrix[SkMatrix::kMScaleY]; |
347 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa bs(heightExpansion) < 1; | 347 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa bs(heightExpansion) < 1; |
348 } | 348 } |
349 | 349 |
350 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const | 350 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp, PassRefPtr<SkColorFilter> col orTransform) const |
351 { | 351 { |
352 TRACE_EVENT0("skia", "NativeImageSkia::draw"); | 352 TRACE_EVENT0("skia", "NativeImageSkia::draw"); |
353 SkPaint paint; | 353 SkPaint paint; |
354 paint.setXfermode(compOp.get()); | 354 paint.setXfermode(compOp.get()); |
355 paint.setColorFilter(context->colorFilter()); | 355 // FIXME: GraphicsContext only supports one filter, and here we ignore it an d use the |
356 // colorTransform argument instead (paint-time color correction). | |
357 // -- GraphicsContext needs a new api, setColorSpaceFilter. | |
358 // -- SkPaint needs a new api, paint.setColorSpaceFilter, to allow CSS or SV G | |
359 // software filters to co-exist with the color space filter. | |
Stephen White
2014/07/03 18:38:17
Actually I don't think CSS or SVG filters ever hit
| |
360 // -- Skia can control the application of the filters, and in what order, wh ich | |
361 // is likely to be colorSpaceFilter first then colorFilter, during paint. | |
362 paint.setColorFilter(colorTransform.get() ? colorTransform.get() : context-> colorFilter()); | |
356 paint.setAlpha(context->getNormalizedAlpha()); | 363 paint.setAlpha(context->getNormalizedAlpha()); |
357 paint.setLooper(context->drawLooper()); | 364 paint.setLooper(context->drawLooper()); |
358 paint.setAntiAlias(shouldDrawAntiAliased(context, destRect)); | 365 paint.setAntiAlias(shouldDrawAntiAliased(context, destRect)); |
359 | 366 |
360 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); | 367 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap()); |
361 | 368 |
362 InterpolationQuality resampling; | 369 InterpolationQuality resampling; |
363 if (context->isAccelerated()) { | 370 if (context->isAccelerated()) { |
364 resampling = InterpolationLow; | 371 resampling = InterpolationLow; |
365 } else if (context->printing()) { | 372 } else if (context->printing()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 info.fAlphaType = kPremul_SkAlphaType; | 424 info.fAlphaType = kPremul_SkAlphaType; |
418 | 425 |
419 SkBitmap result; | 426 SkBitmap result; |
420 result.allocPixels(info); | 427 result.allocPixels(info); |
421 result.eraseColor(SK_ColorTRANSPARENT); | 428 result.eraseColor(SK_ColorTRANSPARENT); |
422 bitmap.copyPixelsTo(reinterpret_cast<uint8_t*>(result.getPixels()), result.r owBytes() * result.height(), result.rowBytes()); | 429 bitmap.copyPixelsTo(reinterpret_cast<uint8_t*>(result.getPixels()), result.r owBytes() * result.height(), result.rowBytes()); |
423 | 430 |
424 return result; | 431 return result; |
425 } | 432 } |
426 | 433 |
427 void NativeImageSkia::drawPattern( | 434 void NativeImageSkia::drawPattern(GraphicsContext* context, const FloatRect& src Rect, const FloatSize& scale, |
428 GraphicsContext* context, | 435 const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& des tRect, blink::WebBlendMode blendMode, const IntSize& repeatSpacing, PassRefPtr<S kColorFilter> colorTransform) const |
429 const FloatRect& floatSrcRect, | |
430 const FloatSize& scale, | |
431 const FloatPoint& phase, | |
432 CompositeOperator compositeOp, | |
433 const FloatRect& destRect, | |
434 blink::WebBlendMode blendMode, | |
435 const IntSize& repeatSpacing) const | |
436 { | 436 { |
437 FloatRect normSrcRect = floatSrcRect; | 437 FloatRect normSrcRect = srcRect; |
438 normSrcRect.intersect(FloatRect(0, 0, bitmap().width(), bitmap().height())); | 438 normSrcRect.intersect(FloatRect(0, 0, bitmap().width(), bitmap().height())); |
439 if (destRect.isEmpty() || normSrcRect.isEmpty()) | 439 if (destRect.isEmpty() || normSrcRect.isEmpty()) |
440 return; // nothing to draw | 440 return; // nothing to draw |
441 | 441 |
442 SkMatrix totalMatrix = context->getTotalMatrix(); | 442 SkMatrix totalMatrix = context->getTotalMatrix(); |
443 AffineTransform ctm = context->getCTM(); | 443 AffineTransform ctm = context->getCTM(); |
444 SkScalar ctmScaleX = ctm.xScale(); | 444 SkScalar ctmScaleX = ctm.xScale(); |
445 SkScalar ctmScaleY = ctm.yScale(); | 445 SkScalar ctmScaleY = ctm.yScale(); |
446 totalMatrix.preScale(scale.width(), scale.height()); | 446 totalMatrix.preScale(scale.width(), scale.height()); |
447 | 447 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 } else { | 520 } else { |
521 shader = adoptRef(SkShader::CreateBitmapShader( | 521 shader = adoptRef(SkShader::CreateBitmapShader( |
522 createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScal eX, repeatSpacing.height() * ctmScaleY), | 522 createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScal eX, repeatSpacing.height() * ctmScaleY), |
523 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa trix)); | 523 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa trix)); |
524 } | 524 } |
525 } | 525 } |
526 | 526 |
527 SkPaint paint; | 527 SkPaint paint; |
528 paint.setShader(shader.get()); | 528 paint.setShader(shader.get()); |
529 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge t()); | 529 paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).ge t()); |
530 paint.setColorFilter(context->colorFilter()); | 530 // FIXME: GraphicsContext only supports one filter, and here we ignore it an d use the |
531 // colorTransform argument instead (paint-time color correction). | |
532 paint.setColorFilter(colorTransform.get() ? colorTransform.get() : context-> colorFilter()); | |
531 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling)) ; | 533 paint.setFilterLevel(convertToSkiaFilterLevel(useBicubicFilter, resampling)) ; |
532 | 534 |
533 if (isLazyDecoded) | 535 if (isLazyDecoded) |
534 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID()) ; | 536 PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID()) ; |
535 | 537 |
536 context->drawRect(destRect, paint); | 538 context->drawRect(destRect, paint); |
537 } | 539 } |
538 | 540 |
539 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons t SkIRect& scaledImageSubset) const | 541 bool NativeImageSkia::shouldCacheResampling(const SkISize& scaledImageSize, cons t SkIRect& scaledImageSubset) const |
540 { | 542 { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) | 604 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) |
603 { | 605 { |
604 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 606 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
605 return SkIRect::MakeEmpty(); | 607 return SkIRect::MakeEmpty(); |
606 SkIRect subsetRect = otherScaledImageSubset; | 608 SkIRect subsetRect = otherScaledImageSubset; |
607 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 609 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
608 return subsetRect; | 610 return subsetRect; |
609 } | 611 } |
610 | 612 |
611 } // namespace WebCore | 613 } // namespace WebCore |
OLD | NEW |