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 "skia/ext/paint_simplifier.h" | 5 #include "skia/ext/paint_simplifier.h" |
6 #include "third_party/skia/include/core/SkPaint.h" | 6 #include "third_party/skia/include/core/SkPaint.h" |
| 7 #include "third_party/skia/include/core/SkShader.h" |
7 | 8 |
8 namespace skia { | 9 namespace skia { |
| 10 namespace { |
| 11 |
| 12 bool PaintHasBitmap(const SkPaint &paint) { |
| 13 SkShader* shader = paint.getShader(); |
| 14 if (!shader) |
| 15 return false; |
| 16 |
| 17 if (shader->asAGradient(NULL) == SkShader::kNone_GradientType) |
| 18 return false; |
| 19 |
| 20 return shader->asABitmap(NULL, NULL, NULL) != SkShader::kNone_BitmapType; |
| 21 } |
| 22 |
| 23 } // namespace |
9 | 24 |
10 PaintSimplifier::PaintSimplifier() | 25 PaintSimplifier::PaintSimplifier() |
11 : INHERITED() { | 26 : INHERITED() { |
12 | 27 |
13 } | 28 } |
14 | 29 |
15 PaintSimplifier::~PaintSimplifier() { | 30 PaintSimplifier::~PaintSimplifier() { |
16 | 31 |
17 } | 32 } |
18 | 33 |
19 bool PaintSimplifier::filter(SkPaint* paint, Type type) { | 34 bool PaintSimplifier::filter(SkPaint* paint, Type type) { |
| 35 // Bitmaps are expensive. Skip draw if type has a bitmap. |
| 36 if (type == kBitmap_Type || PaintHasBitmap(*paint)) |
| 37 return false; |
20 | 38 |
21 // Preserve a modicum of text quality; black & white text is | 39 // Preserve a modicum of text quality; black & white text is |
22 // just too blocky, even during a fling. | 40 // just too blocky, even during a fling. |
23 if (type != kText_Type) { | 41 if (type != kText_Type) { |
24 paint->setAntiAlias(false); | 42 paint->setAntiAlias(false); |
25 } | 43 } |
26 paint->setSubpixelText(false); | 44 paint->setSubpixelText(false); |
27 paint->setLCDRenderText(false); | 45 paint->setLCDRenderText(false); |
28 | 46 |
29 paint->setMaskFilter(NULL); | 47 paint->setMaskFilter(NULL); |
30 | 48 |
31 // Uncomment this line to shade simplified tiles pink during debugging. | 49 // Uncomment this line to shade simplified tiles pink during debugging. |
32 //paint->setColor(SkColorSetRGB(255, 127, 127)); | 50 //paint->setColor(SkColorSetRGB(255, 127, 127)); |
33 | 51 |
34 return true; | 52 return true; |
35 } | 53 } |
36 | 54 |
37 | 55 |
38 } // namespace skia | 56 } // namespace skia |
39 | 57 |
40 | 58 |
OLD | NEW |