OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkAndroidSDKCanvas.h" | 8 #include "SkAndroidSDKCanvas.h" |
9 | 9 |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
12 #include "SkPathEffect.h" | 12 #include "SkPathEffect.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 #include "SkTLazy.h" | 14 #include "SkTLazy.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 /** Discard SkShaders not exposed by the Android Java API. */ | 18 /** Discard SkShaders not exposed by the Android Java API. */ |
19 | 19 |
20 void CheckShader(SkPaint* paint) { | 20 void CheckShader(SkPaint* paint) { |
21 SkShader* shader = paint->getShader(); | 21 SkShader* shader = paint->getShader(); |
22 if (!shader) { | 22 if (!shader) { |
23 return; | 23 return; |
24 } | 24 } |
25 | 25 |
26 if (shader->isABitmap()) { | 26 if (shader->isABitmap()) { |
27 return; | 27 return; |
28 } | 28 } |
29 if (shader->asACompose(NULL)) { | 29 if (shader->asACompose(nullptr)) { |
30 return; | 30 return; |
31 } | 31 } |
32 SkShader::GradientType gtype = shader->asAGradient(NULL); | 32 SkShader::GradientType gtype = shader->asAGradient(nullptr); |
33 if (gtype == SkShader::kLinear_GradientType || | 33 if (gtype == SkShader::kLinear_GradientType || |
34 gtype == SkShader::kRadial_GradientType || | 34 gtype == SkShader::kRadial_GradientType || |
35 gtype == SkShader::kSweep_GradientType) { | 35 gtype == SkShader::kSweep_GradientType) { |
36 return; | 36 return; |
37 } | 37 } |
38 paint->setShader(NULL); | 38 paint->setShader(nullptr); |
39 } | 39 } |
40 | 40 |
41 void Filter(SkPaint* paint) { | 41 void Filter(SkPaint* paint) { |
42 | 42 |
43 uint32_t flags = paint->getFlags(); | 43 uint32_t flags = paint->getFlags(); |
44 flags &= ~SkPaint::kLCDRenderText_Flag; | 44 flags &= ~SkPaint::kLCDRenderText_Flag; |
45 paint->setFlags(flags); | 45 paint->setFlags(flags); |
46 | 46 |
47 // Android doesn't support Xfermodes above kLighten_Mode | 47 // Android doesn't support Xfermodes above kLighten_Mode |
48 SkXfermode::Mode mode; | 48 SkXfermode::Mode mode; |
49 SkXfermode::AsMode(paint->getXfermode(), &mode); | 49 SkXfermode::AsMode(paint->getXfermode(), &mode); |
50 if (mode > SkXfermode::kLighten_Mode) { | 50 if (mode > SkXfermode::kLighten_Mode) { |
51 paint->setXfermode(NULL); | 51 paint->setXfermode(nullptr); |
52 } | 52 } |
53 | 53 |
54 // Force bilinear scaling or none | 54 // Force bilinear scaling or none |
55 if (paint->getFilterQuality() != kNone_SkFilterQuality) { | 55 if (paint->getFilterQuality() != kNone_SkFilterQuality) { |
56 paint->setFilterQuality(kLow_SkFilterQuality); | 56 paint->setFilterQuality(kLow_SkFilterQuality); |
57 } | 57 } |
58 | 58 |
59 CheckShader(paint); | 59 CheckShader(paint); |
60 | 60 |
61 // Android SDK only supports mode & matrix color filters | 61 // Android SDK only supports mode & matrix color filters |
62 // (and, again, no modes above kLighten_Mode). | 62 // (and, again, no modes above kLighten_Mode). |
63 SkColorFilter* cf = paint->getColorFilter(); | 63 SkColorFilter* cf = paint->getColorFilter(); |
64 if (cf) { | 64 if (cf) { |
65 SkColor color; | 65 SkColor color; |
66 SkXfermode::Mode mode; | 66 SkXfermode::Mode mode; |
67 SkScalar srcColorMatrix[20]; | 67 SkScalar srcColorMatrix[20]; |
68 bool isMode = cf->asColorMode(&color, &mode); | 68 bool isMode = cf->asColorMode(&color, &mode); |
69 if (isMode && mode > SkXfermode::kLighten_Mode) { | 69 if (isMode && mode > SkXfermode::kLighten_Mode) { |
70 paint->setColorFilter( | 70 paint->setColorFilter( |
71 SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode
)); | 71 SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode
)); |
72 } else if (!isMode && !cf->asColorMatrix(srcColorMatrix)) { | 72 } else if (!isMode && !cf->asColorMatrix(srcColorMatrix)) { |
73 paint->setColorFilter(NULL); | 73 paint->setColorFilter(nullptr); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 77 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
78 SkPathEffect* pe = paint->getPathEffect(); | 78 SkPathEffect* pe = paint->getPathEffect(); |
79 if (pe && !pe->exposedInAndroidJavaAPI()) { | 79 if (pe && !pe->exposedInAndroidJavaAPI()) { |
80 paint->setPathEffect(NULL); | 80 paint->setPathEffect(nullptr); |
81 } | 81 } |
82 #endif | 82 #endif |
83 | 83 |
84 // TODO: Android doesn't support all the flags that can be passed to | 84 // TODO: Android doesn't support all the flags that can be passed to |
85 // blur filters; we need plumbing to get them out. | 85 // blur filters; we need plumbing to get them out. |
86 | 86 |
87 paint->setImageFilter(NULL); | 87 paint->setImageFilter(nullptr); |
88 paint->setLooper(NULL); | 88 paint->setLooper(nullptr); |
89 }; | 89 }; |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 #define FILTER(p) \ | 93 #define FILTER(p) \ |
94 SkPaint filteredPaint(p); \ | 94 SkPaint filteredPaint(p); \ |
95 Filter(&filteredPaint); | 95 Filter(&filteredPaint); |
96 | 96 |
97 #define FILTER_PTR(p) \ | 97 #define FILTER_PTR(p) \ |
98 SkTLazy<SkPaint> lazyPaint; \ | 98 SkTLazy<SkPaint> lazyPaint; \ |
99 SkPaint* filteredPaint = (SkPaint*) p; \ | 99 SkPaint* filteredPaint = (SkPaint*) p; \ |
100 if (p) { \ | 100 if (p) { \ |
101 filteredPaint = lazyPaint.set(*p); \ | 101 filteredPaint = lazyPaint.set(*p); \ |
102 Filter(filteredPaint); \ | 102 Filter(filteredPaint); \ |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 SkAndroidSDKCanvas::SkAndroidSDKCanvas() : fProxyTarget(NULL) { } | 106 SkAndroidSDKCanvas::SkAndroidSDKCanvas() : fProxyTarget(nullptr) { } |
107 | 107 |
108 void SkAndroidSDKCanvas::reset(SkCanvas* newTarget) { fProxyTarget = newTarget;
} | 108 void SkAndroidSDKCanvas::reset(SkCanvas* newTarget) { fProxyTarget = newTarget;
} |
109 | 109 |
110 void SkAndroidSDKCanvas::onDrawPaint(const SkPaint& paint) { | 110 void SkAndroidSDKCanvas::onDrawPaint(const SkPaint& paint) { |
111 FILTER(paint); | 111 FILTER(paint); |
112 fProxyTarget->drawPaint(filteredPaint); | 112 fProxyTarget->drawPaint(filteredPaint); |
113 } | 113 } |
114 void SkAndroidSDKCanvas::onDrawPoints(PointMode pMode, | 114 void SkAndroidSDKCanvas::onDrawPoints(PointMode pMode, |
115 size_t count, | 115 size_t count, |
116 const SkPoint pts[], | 116 const SkPoint pts[], |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 pmap->reset(info, addr, rowBytes); | 285 pmap->reset(info, addr, rowBytes); |
286 return true; | 286 return true; |
287 } | 287 } |
288 return false; | 288 return false; |
289 } | 289 } |
290 | 290 |
291 bool SkAndroidSDKCanvas::onAccessTopLayerPixels(SkPixmap* pmap) { | 291 bool SkAndroidSDKCanvas::onAccessTopLayerPixels(SkPixmap* pmap) { |
292 SkASSERT(pmap); | 292 SkASSERT(pmap); |
293 SkImageInfo info; | 293 SkImageInfo info; |
294 size_t rowBytes; | 294 size_t rowBytes; |
295 const void* addr = fProxyTarget->accessTopLayerPixels(&info, &rowBytes, NULL
); | 295 const void* addr = fProxyTarget->accessTopLayerPixels(&info, &rowBytes, null
ptr); |
296 if (addr) { | 296 if (addr) { |
297 pmap->reset(info, addr, rowBytes); | 297 pmap->reset(info, addr, rowBytes); |
298 return true; | 298 return true; |
299 } | 299 } |
300 return false; | 300 return false; |
301 } | 301 } |
302 | 302 |
303 void SkAndroidSDKCanvas::willSave() { | 303 void SkAndroidSDKCanvas::willSave() { |
304 fProxyTarget->save(); | 304 fProxyTarget->save(); |
305 } | 305 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 fProxyTarget->clipPath(path, op, style); | 343 fProxyTarget->clipPath(path, op, style); |
344 } | 344 } |
345 | 345 |
346 void SkAndroidSDKCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) { | 346 void SkAndroidSDKCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) { |
347 fProxyTarget->clipRegion(region, op); | 347 fProxyTarget->clipRegion(region, op); |
348 } | 348 } |
349 | 349 |
350 void SkAndroidSDKCanvas::onDiscard() { fProxyTarget->discard(); } | 350 void SkAndroidSDKCanvas::onDiscard() { fProxyTarget->discard(); } |
351 | 351 |
352 | 352 |
OLD | NEW |