Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2016 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "gm.h"
      9 #include "SkBlurImageFilter.h"
     10 #include "SkBlurMaskFilter.h"
     11 #include "SkCanvas.h"
     12 #include "SkDashPathEffect.h"
     13 #include "SkGradientShader.h"
     14 #include "SkRegion.h"
     15 
     16 class DrawRegionModesGM : public skiagm::GM {
     17 public:
     18     DrawRegionModesGM() {}
     19 
     20 protected:
     21     SkString onShortName() override {
     22         return SkString("drawregionmodes");
     23     }
     24 
     25     SkISize onISize() override {
     26         return SkISize::Make(375, 500);
     27     }
     28 
     29     void onOnceBeforeDraw() override {
     30         fRegion.op( 50,  50, 100, 100, SkRegion::kUnion_Op);
     31         fRegion.op( 50, 100, 150, 150, SkRegion::kUnion_Op);
     32     }
     33 
     34     void onDraw(SkCanvas* canvas) override {
     35         canvas->clear(SK_ColorGREEN);
     36 
     37         SkPaint paint;
     38         paint.setStyle(SkPaint::kFill_Style);
     39         paint.setColor(0xFFFF0000);
     40         paint.setAntiAlias(true);
     41 
     42         canvas->translate(-50.0f, 75.0f);
     43         canvas->rotate(-45.0f);
     44         canvas->drawRegion(fRegion, paint);
     45 
     46         canvas->translate(125.0f, 125.0f);
     47         paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr, nullptr));
     48         canvas->drawRegion(fRegion, paint);
     49 
     50         canvas->translate(-125.0f, 125.0f);
     51         paint.setImageFilter(nullptr);
     52         SkRect occluder = SkRect::MakeEmpty();
     53         paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 5.0f, occluder, 0));
     54         canvas->drawRegion(fRegion, paint);
     55 
     56         canvas->translate(-125.0f, -125.0f);
     57         paint.setMaskFilter(nullptr);
     58         paint.setStyle(SkPaint::kStroke_Style);
     59         float intervals[] = { 5.0f, 5.0f };
     60         paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f));
     61         canvas->drawRegion(fRegion, paint);
     62 
     63         canvas->setMatrix(SkMatrix::I());
     64         canvas->translate(100, 325);
     65         paint.setPathEffect(nullptr);
     66         paint.setStyle(SkPaint::kFill_Style);
     67         SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) };
     68         SkColor colors[] = { SK_ColorBLUE, SK_ColorYELLOW };
     69         paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2,
     70                                                      SkShader::kClamp_TileMode));
     71         canvas->drawRegion(fRegion, paint);
     72     }
     73 
     74     SkRegion fRegion;
     75 
     76 private:
     77     typedef skiagm::GM INHERITED;
     78 };
     79 DEF_GM( return new DrawRegionModesGM; )
     80