Chromium Code Reviews| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 53 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| 54 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | 54 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" |
| 55 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 55 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| 56 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" | 56 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" |
| 57 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 57 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
| 58 #include "third_party/skia/include/gpu/GrRenderTarget.h" | 58 #include "third_party/skia/include/gpu/GrRenderTarget.h" |
| 59 #include "third_party/skia/include/gpu/GrTexture.h" | 59 #include "third_party/skia/include/gpu/GrTexture.h" |
| 60 #include "wtf/Assertions.h" | 60 #include "wtf/Assertions.h" |
| 61 #include "wtf/MathExtras.h" | 61 #include "wtf/MathExtras.h" |
| 62 | 62 |
| 63 namespace { | |
| 64 | |
| 65 // Tolerance value use for comparing scale factor to 1.. | |
| 66 // Numerical error should not reach 6th decimal except for highly degenerate cas es, | |
| 67 // and effect of 6th decimal on scale is negligible over max span of a skia canv as | |
| 68 // which is 32k pixels. | |
| 69 const float cPictureScaleEpsilon = 0.000001; | |
| 70 | |
| 71 } | |
| 72 | |
| 73 namespace blink { | 63 namespace blink { |
| 74 | 64 |
| 75 class GraphicsContext::RecordingState { | 65 class GraphicsContext::RecordingState { |
| 76 WTF_MAKE_FAST_ALLOCATED; | 66 WTF_MAKE_FAST_ALLOCATED; |
| 77 WTF_MAKE_NONCOPYABLE(RecordingState); | 67 WTF_MAKE_NONCOPYABLE(RecordingState); |
| 78 public: | 68 public: |
| 79 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m atrix, unsigned trackingMode) | 69 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m atrix, unsigned trackingMode) |
| 80 { | 70 { |
| 81 return adoptPtr(new RecordingState(canvas, matrix, static_cast<RegionTra ckingMode>(trackingMode))); | 71 return adoptPtr(new RecordingState(canvas, matrix, static_cast<RegionTra ckingMode>(trackingMode))); |
| 82 } | 72 } |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 | 561 |
| 572 if (regionTrackingEnabled()) { | 562 if (regionTrackingEnabled()) { |
| 573 // Since we don't track regions within display lists, conservatively | 563 // Since we don't track regions within display lists, conservatively |
| 574 // mark the bounds as non-opaque. | 564 // mark the bounds as non-opaque. |
| 575 SkPaint paint; | 565 SkPaint paint; |
| 576 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 566 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
| 577 m_trackedRegion.didDrawBounded(this, picture->cullRect(), paint); | 567 m_trackedRegion.didDrawBounded(this, picture->cullRect(), paint); |
| 578 } | 568 } |
| 579 } | 569 } |
| 580 | 570 |
| 581 static inline bool pictureScaleIsApproximatelyOne(float x) | 571 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest , const FloatRect& src, CompositeOperator op, WebBlendMode blendMode) |
|
Stephen White
2014/12/12 22:14:11
Why the name change? Most draw ops in GraphicsCont
Justin Novosad
2014/12/12 22:31:51
Because the behavior is significantly different fr
| |
| 582 { | |
| 583 return fabsf(x - 1.0f) < cPictureScaleEpsilon; | |
| 584 } | |
| 585 | |
| 586 void GraphicsContext::drawPicture(SkPicture* picture, const FloatRect& dest, con st FloatRect& src, CompositeOperator op, WebBlendMode blendMode) | |
| 587 { | 572 { |
| 588 ASSERT(m_canvas); | 573 ASSERT(m_canvas); |
| 589 if (contextDisabled() || !picture) | 574 if (contextDisabled() || !picture) |
| 590 return; | 575 return; |
| 591 | 576 |
| 592 SkMatrix ctm = m_canvas->getTotalMatrix(); | |
| 593 SkRect deviceDest; | |
| 594 ctm.mapRect(&deviceDest, dest); | |
| 595 float scaleX = deviceDest.width() / src.width(); | |
| 596 float scaleY = deviceDest.height() / src.height(); | |
| 597 | |
| 598 SkPaint picturePaint; | 577 SkPaint picturePaint; |
| 599 picturePaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op, blendMode)) ; | 578 picturePaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op, blendMode)) ; |
| 579 m_canvas->save(); | |
| 600 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); | 580 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); |
| 601 if (pictureScaleIsApproximatelyOne(scaleX * m_deviceScaleFactor) && pictureS caleIsApproximatelyOne(scaleY * m_deviceScaleFactor)) { | 581 SkRect skBounds = WebCoreFloatRectToSKRect(dest); |
| 602 // Fast path for canvases that are rasterized at screen resolution | 582 SkMatrix pictureTransform; |
| 603 SkRect skBounds = WebCoreFloatRectToSKRect(dest); | 583 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit); |
| 604 m_canvas->saveLayer(&skBounds, &picturePaint); | 584 m_canvas->concat(pictureTransform); |
| 605 SkMatrix pictureTransform; | 585 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter:: CreateForLocalSpace(picture, sourceBounds, static_cast<SkPaint::FilterLevel>(ima geInterpolationQuality()))); |
| 606 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_S caleToFit); | 586 picturePaint.setImageFilter(pictureFilter.get()); |
| 607 m_canvas->concat(pictureTransform); | 587 m_canvas->saveLayer(&sourceBounds, &picturePaint); |
| 608 m_canvas->drawPicture(picture); | 588 m_canvas->restore(); |
| 609 m_canvas->restore(); | 589 m_canvas->restore(); |
| 610 } else { | |
| 611 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilt er::Create(picture, sourceBounds)); | |
| 612 SkMatrix layerScale; | |
| 613 layerScale.setScale(scaleX, scaleY); | |
| 614 RefPtr<SkMatrixImageFilter> matrixFilter = adoptRef(SkMatrixImageFilter: :Create(layerScale, SkPaint::kLow_FilterLevel, pictureFilter.get())); | |
| 615 picturePaint.setImageFilter(matrixFilter.get()); | |
| 616 SkRect layerBounds = SkRect::MakeWH(std::max(deviceDest.width(), sourceB ounds.width()), std::max(deviceDest.height(), sourceBounds.height())); | |
| 617 m_canvas->save(); | |
| 618 m_canvas->resetMatrix(); | |
| 619 m_canvas->translate(deviceDest.x(), deviceDest.y()); | |
| 620 m_canvas->saveLayer(&layerBounds, &picturePaint); | |
| 621 m_canvas->restore(); | |
| 622 m_canvas->restore(); | |
| 623 } | |
| 624 } | 590 } |
| 625 | 591 |
| 626 void GraphicsContext::fillPolygon(size_t numPoints, const FloatPoint* points, co nst Color& color, | 592 void GraphicsContext::fillPolygon(size_t numPoints, const FloatPoint* points, co nst Color& color, |
| 627 bool shouldAntialias) | 593 bool shouldAntialias) |
| 628 { | 594 { |
| 629 if (contextDisabled()) | 595 if (contextDisabled()) |
| 630 return; | 596 return; |
| 631 | 597 |
| 632 ASSERT(numPoints > 2); | 598 ASSERT(numPoints > 2); |
| 633 | 599 |
| (...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1988 GraphicsContext::AutoCanvasRestorer::~AutoCanvasRestorer() | 1954 GraphicsContext::AutoCanvasRestorer::~AutoCanvasRestorer() |
| 1989 { | 1955 { |
| 1990 while (m_restoreCount) { | 1956 while (m_restoreCount) { |
| 1991 m_canvas->restore(); | 1957 m_canvas->restore(); |
| 1992 m_restoreCount--; | 1958 m_restoreCount--; |
| 1993 } | 1959 } |
| 1994 | 1960 |
| 1995 } | 1961 } |
| 1996 | 1962 |
| 1997 } // namespace blink | 1963 } // namespace blink |
| OLD | NEW |