| 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 14 matching lines...) Expand all  Loading... | 
|  25 static SkColorFilter* make_cf_null() { |  25 static SkColorFilter* make_cf_null() { | 
|  26     return nullptr; |  26     return nullptr; | 
|  27 } |  27 } | 
|  28  |  28  | 
|  29 static SkColorFilter* make_cf0() { |  29 static SkColorFilter* make_cf0() { | 
|  30     SkColorMatrix cm; |  30     SkColorMatrix cm; | 
|  31     cm.setSaturation(0.75f); |  31     cm.setSaturation(0.75f); | 
|  32     return SkColorMatrixFilter::Create(cm); |  32     return SkColorMatrixFilter::Create(cm); | 
|  33 } |  33 } | 
|  34  |  34  | 
 |  35 static SkColorFilter* make_cf1() { | 
 |  36     SkColorMatrix cm; | 
 |  37     cm.setSaturation(0.75f); | 
 |  38     SkAutoTUnref<SkColorFilter> a(SkColorMatrixFilter::Create(cm)); | 
 |  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 | 
 |  41     // these two, so our inner filter has a scale-up, which disables the optimiz
    ation of | 
 |  42     // combining the two matrices. | 
 |  43     cm.setScale(1.1f, 0.9f, 1); | 
 |  44     SkAutoTUnref<SkColorFilter> b(SkColorMatrixFilter::Create(cm)); | 
 |  45     return SkColorFilter::CreateComposeFilter(a, b); | 
 |  46 } | 
 |  47  | 
|  35 static void draw_into_canvas(SkCanvas* canvas) { |  48 static void draw_into_canvas(SkCanvas* canvas) { | 
|  36     const SkRect r = SkRect::MakeWH(100, 100); |  49     const SkRect r = SkRect::MakeWH(100, 100); | 
|  37     SkShader* (*shaders[])() { make_opaque_color, make_alpha_color }; |  50     SkShader* (*shaders[])() { make_opaque_color, make_alpha_color }; | 
|  38     SkColorFilter* (*filters[])() { make_cf_null, make_cf0 }; |  51     SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1 }; | 
|  39      |  52      | 
|  40     SkPaint paint; |  53     SkPaint paint; | 
|  41     for (auto shProc : shaders) { |  54     for (auto shProc : shaders) { | 
|  42         paint.setShader(shProc())->unref(); |  55         paint.setShader(shProc())->unref(); | 
|  43         for (auto cfProc : filters) { |  56         for (auto cfProc : filters) { | 
|  44             SkSafeUnref(paint.setColorFilter(cfProc())); |  57             SkSafeUnref(paint.setColorFilter(cfProc())); | 
|  45             canvas->drawRect(r, paint); |  58             canvas->drawRect(r, paint); | 
|  46             canvas->translate(120, 0); |  59             canvas->translate(120, 0); | 
|  47         } |  60         } | 
|  48     } |  61     } | 
|  49 } |  62 } | 
|  50  |  63  | 
|  51 DEF_SIMPLE_GM(color4f, canvas, 510, 250) { |  64 DEF_SIMPLE_GM(color4f, canvas, 620, 260) { | 
|  52     canvas->translate(20, 20); |  65     canvas->translate(20, 20); | 
|  53  |  66  | 
|  54     SkPaint bg; |  67     SkPaint bg; | 
|  55     // need the target to be opaque, so we can draw it to the screen |  68     // need the target to be opaque, so we can draw it to the screen | 
|  56     // even if it holds sRGB values. |  69     // even if it holds sRGB values. | 
|  57     bg.setColor(0xFFFFFFFF); |  70     bg.setColor(0xFFFFFFFF); | 
|  58  |  71  | 
|  59     SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkCo
    lorProfileType }; |  72     SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkCo
    lorProfileType }; | 
|  60     for (auto profile : profiles) { |  73     for (auto profile : profiles) { | 
|  61         const SkImageInfo info = SkImageInfo::Make(500, 100, kN32_SkColorType, k
    Premul_SkAlphaType, |  74         const SkImageInfo info = SkImageInfo::Make(600, 100, kN32_SkColorType, k
    Premul_SkAlphaType, | 
|  62                                                    profile); |  75                                                    profile); | 
|  63         SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |  76         SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 
|  64         surface->getCanvas()->drawPaint(bg); |  77         surface->getCanvas()->drawPaint(bg); | 
|  65         draw_into_canvas(surface->getCanvas()); |  78         draw_into_canvas(surface->getCanvas()); | 
|  66         surface->draw(canvas, 0, 0, nullptr); |  79         surface->draw(canvas, 0, 0, nullptr); | 
|  67         canvas->translate(0, 120); |  80         canvas->translate(0, 120); | 
|  68     } |  81     } | 
|  69 } |  82 } | 
| OLD | NEW |