| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 SkAutoTUnref<SkColorFilter> a(SkColorMatrixFilter::Create(cm)); | 38 SkAutoTUnref<SkColorFilter> a(SkColorMatrixFilter::Create(cm)); |
| 39 // CreateComposedFilter will try to concat these two matrices, resulting in
a single | 39 // CreateComposedFilter will try to concat these two matrices, resulting in
a single |
| 40 // filter (which is good for speed). For this test, we want to force a real
compose of | 40 // filter (which is good for speed). For this test, we want to force a real
compose of |
| 41 // these two, so our inner filter has a scale-up, which disables the optimiz
ation of | 41 // these two, so our inner filter has a scale-up, which disables the optimiz
ation of |
| 42 // combining the two matrices. | 42 // combining the two matrices. |
| 43 cm.setScale(1.1f, 0.9f, 1); | 43 cm.setScale(1.1f, 0.9f, 1); |
| 44 SkAutoTUnref<SkColorFilter> b(SkColorMatrixFilter::Create(cm)); | 44 SkAutoTUnref<SkColorFilter> b(SkColorMatrixFilter::Create(cm)); |
| 45 return SkColorFilter::CreateComposeFilter(a, b); | 45 return SkColorFilter::CreateComposeFilter(a, b); |
| 46 } | 46 } |
| 47 | 47 |
| 48 static SkColorFilter* make_cf2() { |
| 49 return SkColorFilter::CreateModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode
); |
| 50 } |
| 51 |
| 48 static void draw_into_canvas(SkCanvas* canvas) { | 52 static void draw_into_canvas(SkCanvas* canvas) { |
| 49 const SkRect r = SkRect::MakeWH(100, 100); | 53 const SkRect r = SkRect::MakeWH(50, 100); |
| 50 SkShader* (*shaders[])() { make_opaque_color, make_alpha_color }; | 54 SkShader* (*shaders[])() { make_opaque_color, make_alpha_color }; |
| 51 SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1 }; | 55 SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 }
; |
| 52 | 56 |
| 53 SkPaint paint; | 57 SkPaint paint; |
| 54 for (auto shProc : shaders) { | 58 for (auto shProc : shaders) { |
| 55 paint.setShader(shProc())->unref(); | 59 paint.setShader(shProc())->unref(); |
| 56 for (auto cfProc : filters) { | 60 for (auto cfProc : filters) { |
| 57 SkSafeUnref(paint.setColorFilter(cfProc())); | 61 SkSafeUnref(paint.setColorFilter(cfProc())); |
| 58 canvas->drawRect(r, paint); | 62 canvas->drawRect(r, paint); |
| 59 canvas->translate(120, 0); | 63 canvas->translate(60, 0); |
| 60 } | 64 } |
| 61 } | 65 } |
| 62 } | 66 } |
| 63 | 67 |
| 64 DEF_SIMPLE_GM(color4f, canvas, 620, 260) { | 68 DEF_SIMPLE_GM(color4f, canvas, 1024, 260) { |
| 65 canvas->translate(20, 20); | 69 canvas->translate(10, 10); |
| 66 | 70 |
| 67 SkPaint bg; | 71 SkPaint bg; |
| 68 // need the target to be opaque, so we can draw it to the screen | 72 // need the target to be opaque, so we can draw it to the screen |
| 69 // even if it holds sRGB values. | 73 // even if it holds sRGB values. |
| 70 bg.setColor(0xFFFFFFFF); | 74 bg.setColor(0xFFFFFFFF); |
| 71 | 75 |
| 72 SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkCo
lorProfileType }; | 76 SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkCo
lorProfileType }; |
| 73 for (auto profile : profiles) { | 77 for (auto profile : profiles) { |
| 74 const SkImageInfo info = SkImageInfo::Make(600, 100, kN32_SkColorType, k
Premul_SkAlphaType, | 78 const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType,
kPremul_SkAlphaType, |
| 75 profile); | 79 profile); |
| 76 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 80 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 77 surface->getCanvas()->drawPaint(bg); | 81 surface->getCanvas()->drawPaint(bg); |
| 78 draw_into_canvas(surface->getCanvas()); | 82 draw_into_canvas(surface->getCanvas()); |
| 79 surface->draw(canvas, 0, 0, nullptr); | 83 surface->draw(canvas, 0, 0, nullptr); |
| 80 canvas->translate(0, 120); | 84 canvas->translate(0, 120); |
| 81 } | 85 } |
| 82 } | 86 } |
| OLD | NEW |