| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "skia/ext/analysis_canvas.h" | 7 #include "skia/ext/analysis_canvas.h" |
| 8 #include "third_party/skia/include/core/SkDraw.h" | 8 #include "third_party/skia/include/core/SkDraw.h" |
| 9 #include "third_party/skia/include/core/SkRRect.h" | 9 #include "third_party/skia/include/core/SkRRect.h" |
| 10 #include "third_party/skia/include/core/SkShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
| 11 #include "third_party/skia/src/core/SkRasterClip.h" | 11 #include "third_party/skia/src/core/SkRasterClip.h" |
| 12 #include "ui/gfx/rect_conversions.h" | 12 #include "ui/gfx/rect_conversions.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 const int kNoLayer = -1; | 16 const int kNoLayer = -1; |
| 17 | 17 |
| 18 bool ActsLikeClear(SkXfermode::Mode mode, unsigned src_alpha) { |
| 19 switch (mode) { |
| 20 case SkXfermode::kClear_Mode: |
| 21 return true; |
| 22 case SkXfermode::kSrc_Mode: |
| 23 case SkXfermode::kSrcIn_Mode: |
| 24 case SkXfermode::kDstIn_Mode: |
| 25 case SkXfermode::kSrcOut_Mode: |
| 26 case SkXfermode::kDstATop_Mode: |
| 27 return src_alpha == 0; |
| 28 case SkXfermode::kDstOut_Mode: |
| 29 return src_alpha == 0xFF; |
| 30 default: |
| 31 return false; |
| 32 } |
| 33 } |
| 34 |
| 18 bool IsSolidColorPaint(const SkPaint& paint) { | 35 bool IsSolidColorPaint(const SkPaint& paint) { |
| 19 SkXfermode::Mode xfermode; | 36 SkXfermode::Mode xfermode; |
| 20 | 37 |
| 21 // getXfermode can return a NULL, but that is handled | 38 // getXfermode can return a NULL, but that is handled |
| 22 // gracefully by AsMode (NULL turns into kSrcOver mode). | 39 // gracefully by AsMode (NULL turns into kSrcOver mode). |
| 23 SkXfermode::AsMode(paint.getXfermode(), &xfermode); | 40 SkXfermode::AsMode(paint.getXfermode(), &xfermode); |
| 24 | 41 |
| 25 // Paint is solid color if the following holds: | 42 // Paint is solid color if the following holds: |
| 26 // - Alpha is 1.0, style is fill, and there are no special effects | 43 // - Alpha is 1.0, style is fill, and there are no special effects |
| 27 // - Xfer mode is either kSrc or kSrcOver (kSrcOver is equivalent | 44 // - Xfer mode is either kSrc or kSrcOver (kSrcOver is equivalent |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 100 |
| 84 if (!is_forced_not_solid_ && SkColorGetA(color) == 255) { | 101 if (!is_forced_not_solid_ && SkColorGetA(color) == 255) { |
| 85 is_solid_color_ = true; | 102 is_solid_color_ = true; |
| 86 color_ = color; | 103 color_ = color; |
| 87 } else { | 104 } else { |
| 88 is_solid_color_ = false; | 105 is_solid_color_ = false; |
| 89 } | 106 } |
| 90 } | 107 } |
| 91 | 108 |
| 92 void AnalysisCanvas::drawPaint(const SkPaint& paint) { | 109 void AnalysisCanvas::drawPaint(const SkPaint& paint) { |
| 93 // This check is in SkCanvas::drawPaint(), and some of our unittests rely on | 110 SkRect rect; |
| 94 // on this, so we reproduce it here. | 111 getClipBounds(&rect); |
| 95 if (isClipEmpty()) | 112 drawRect(rect, paint); |
| 96 return; | |
| 97 | |
| 98 is_solid_color_ = false; | |
| 99 is_transparent_ = false; | |
| 100 ++draw_op_count_; | |
| 101 } | 113 } |
| 102 | 114 |
| 103 void AnalysisCanvas::drawPoints(SkCanvas::PointMode mode, | 115 void AnalysisCanvas::drawPoints(SkCanvas::PointMode mode, |
| 104 size_t count, | 116 size_t count, |
| 105 const SkPoint points[], | 117 const SkPoint points[], |
| 106 const SkPaint& paint) { | 118 const SkPaint& paint) { |
| 107 is_solid_color_ = false; | 119 is_solid_color_ = false; |
| 108 is_transparent_ = false; | 120 is_transparent_ = false; |
| 109 ++draw_op_count_; | 121 ++draw_op_count_; |
| 110 } | 122 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 130 // - The quad is a full tile quad | 142 // - The quad is a full tile quad |
| 131 // - We're not in "forced not transparent" mode | 143 // - We're not in "forced not transparent" mode |
| 132 // - Transfer mode is clear (0 color, 0 alpha) | 144 // - Transfer mode is clear (0 color, 0 alpha) |
| 133 // | 145 // |
| 134 // If the paint alpha is not 0, or if the transfrer mode is | 146 // If the paint alpha is not 0, or if the transfrer mode is |
| 135 // not src, then this canvas will not be transparent. | 147 // not src, then this canvas will not be transparent. |
| 136 // | 148 // |
| 137 // In all other cases, we keep the current transparent value | 149 // In all other cases, we keep the current transparent value |
| 138 if (does_cover_canvas && | 150 if (does_cover_canvas && |
| 139 !is_forced_not_transparent_ && | 151 !is_forced_not_transparent_ && |
| 140 xfermode == SkXfermode::kClear_Mode) { | 152 ActsLikeClear(xfermode, paint.getAlpha())) { |
| 141 is_transparent_ = true; | 153 is_transparent_ = true; |
| 142 } else if (paint.getAlpha() != 0 || xfermode != SkXfermode::kSrc_Mode) { | 154 } else if (paint.getAlpha() != 0 || xfermode != SkXfermode::kSrc_Mode) { |
| 143 is_transparent_ = false; | 155 is_transparent_ = false; |
| 144 } | 156 } |
| 145 | 157 |
| 146 // This bitmap is solid if and only if the following holds. | 158 // This bitmap is solid if and only if the following holds. |
| 147 // Note that this might be overly conservative: | 159 // Note that this might be overly conservative: |
| 148 // - We're not in "forced not solid" mode | 160 // - We're not in "forced not solid" mode |
| 149 // - Paint is solid color | 161 // - Paint is solid color |
| 150 // - The quad is a full tile quad | 162 // - The quad is a full tile quad |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 force_not_transparent_stack_level_ = kNoLayer; | 464 force_not_transparent_stack_level_ = kNoLayer; |
| 453 } | 465 } |
| 454 } | 466 } |
| 455 | 467 |
| 456 INHERITED::willRestore(); | 468 INHERITED::willRestore(); |
| 457 } | 469 } |
| 458 | 470 |
| 459 } // namespace skia | 471 } // namespace skia |
| 460 | 472 |
| 461 | 473 |
| OLD | NEW |