OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
6 #include "sky/engine/core/painting/Paint.h" | 6 #include "sky/engine/core/painting/Paint.h" |
7 | 7 |
8 #include "sky/engine/core/painting/ColorFilter.h" | 8 #include "sky/engine/core/painting/ColorFilter.h" |
9 #include "sky/engine/core/painting/DrawLooper.h" | 9 #include "sky/engine/core/painting/DrawLooper.h" |
10 #include "sky/engine/core/painting/MaskFilter.h" | 10 #include "sky/engine/core/painting/MaskFilter.h" |
11 #include "sky/engine/core/painting/Shader.h" | 11 #include "sky/engine/core/painting/Shader.h" |
| 12 #include "sky/engine/wtf/text/StringBuilder.h" |
| 13 #include "third_party/skia/include/core/SkColorFilter.h" |
| 14 #include "third_party/skia/include/core/SkMaskFilter.h" |
| 15 #include "third_party/skia/include/core/SkShader.h" |
| 16 #include "third_party/skia/include/core/SkString.h" |
12 | 17 |
13 namespace blink { | 18 namespace blink { |
14 | 19 |
15 Paint::Paint() | 20 namespace { |
16 { | 21 |
17 setIsAntiAlias(true); | 22 template <typename T> |
| 23 void SkToString(const char* title, const T* sk_object, StringBuilder* result) { |
| 24 if (!sk_object) |
| 25 return; |
| 26 SkString string; |
| 27 sk_object->toString(&string); |
| 28 result->append(String::format(", %s: %s", title, string.c_str())); |
18 } | 29 } |
19 | 30 |
20 Paint::~Paint() | |
21 { | |
22 } | 31 } |
23 | 32 |
24 void Paint::setDrawLooper(DrawLooper* looper) | 33 Paint::Paint() { |
25 { | 34 setIsAntiAlias(true); |
26 ASSERT(looper); | |
27 m_paint.setLooper(looper->looper()); | |
28 } | 35 } |
29 | 36 |
30 void Paint::setColorFilter(ColorFilter* filter) | 37 Paint::~Paint() { |
31 { | |
32 ASSERT(filter); | |
33 m_paint.setColorFilter(filter->filter()); | |
34 } | 38 } |
35 | 39 |
36 void Paint::setMaskFilter(MaskFilter* filter) | 40 void Paint::setDrawLooper(DrawLooper* looper) { |
37 { | 41 ASSERT(looper); |
38 ASSERT(filter); | 42 paint_.setLooper(looper->looper()); |
39 m_paint.setMaskFilter(filter->filter()); | |
40 } | 43 } |
41 | 44 |
42 void Paint::setShader(Shader* shader) | 45 void Paint::setColorFilter(ColorFilter* filter) { |
43 { | 46 ASSERT(filter); |
44 ASSERT(shader); | 47 paint_.setColorFilter(filter->filter()); |
45 m_paint.setShader(shader->shader()); | |
46 } | 48 } |
47 | 49 |
48 void Paint::setStyle(SkPaint::Style style) | 50 void Paint::setMaskFilter(MaskFilter* filter) { |
49 { | 51 ASSERT(filter); |
50 m_paint.setStyle(style); | 52 paint_.setMaskFilter(filter->filter()); |
51 } | 53 } |
52 | 54 |
53 void Paint::setTransferMode(SkXfermode::Mode transfer_mode) | 55 void Paint::setShader(Shader* shader) { |
54 { | 56 ASSERT(shader); |
55 m_paint.setXfermodeMode(transfer_mode); | 57 paint_.setShader(shader->shader()); |
56 } | 58 } |
57 | 59 |
58 } // namespace blink | 60 void Paint::setStyle(SkPaint::Style style) { |
| 61 paint_.setStyle(style); |
| 62 } |
| 63 |
| 64 void Paint::setTransferMode(SkXfermode::Mode transfer_mode) { |
| 65 paint_.setXfermodeMode(transfer_mode); |
| 66 } |
| 67 |
| 68 String Paint::toString() const { |
| 69 StringBuilder result; |
| 70 |
| 71 result.append("Paint("); |
| 72 |
| 73 result.append(String::format("color:Color(0x%.8x)", paint_.getColor())); |
| 74 |
| 75 SkToString("shader", paint_.getShader(), &result); |
| 76 SkToString("colorFilter", paint_.getColorFilter(), &result); |
| 77 SkToString("maskFilter", paint_.getMaskFilter(), &result); |
| 78 |
| 79 if (paint_.getLooper()) { |
| 80 // TODO(mpcomplete): Figure out how to show a drawLooper. |
| 81 result.append(", drawLooper:true"); |
| 82 } |
| 83 result.append(")"); |
| 84 |
| 85 return result.toString(); |
| 86 } |
| 87 |
| 88 } // namespace blink |
OLD | NEW |