1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com#include "SampleCode.h" 9b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com#include "SkBlurMask.h" 10ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com#include "SkBlurMaskFilter.h" 11b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com#include "SkCanvas.h" 12ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com#include "SkColorMatrixFilter.h" 13ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com#include "SkDiscretePathEffect.h" 14ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com#include "SkGradientShader.h" 15b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com#include "SkPaint.h" 16b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com#include "SkView.h" 17b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com 18ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 19ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com//#define COLOR 0xFFFF8844 20ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com#define COLOR 0xFF888888 21ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 2293c7ee34dc5c8f6bfad65809f4b39f8d00d7f0d4sugoi@google.comstatic void paint_proc0(SkPaint*) { 23ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com} 24ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 25ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comstatic void paint_proc1(SkPaint* paint) { 26b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com paint->setMaskFilter(SkBlurMaskFilter::Create( 27e396455d2d60ddf8e625b5037254f3c09fbcdcf5commit-bot@chromium.org kNormal_SkBlurStyle, 28b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2))))->unref(); 29ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com} 30ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 31ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comstatic void paint_proc2(SkPaint* paint) { 32ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com SkScalar dir[3] = { 1, 1, 1}; 33ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint->setMaskFilter( 34b3ec29d2d81ae391e433fbdf8aabc791e426ee38skia.committer@gmail.com SkBlurMaskFilter::CreateEmboss(SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), 35b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com dir, 364b413c8bb123e42ca4b9c7bfa6bc2167283cb84ccommit-bot@chromium.org 0.1f, 374b413c8bb123e42ca4b9c7bfa6bc2167283cb84ccommit-bot@chromium.org 0.05f))->unref(); 38ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com} 39ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 40ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comstatic void paint_proc3(SkPaint* paint) { 41ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE }; 4264cc579efa7e416c7298ed159d76b074b283c0f9senorblanco@chromium.org SkPoint pts[] = { { 3, 0 }, { 7, 5 } }; 432880df2609eba09b555ca37be04b6ad89290c765Tom Hudson paint->setShader(SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), 44ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com SkShader::kMirror_TileMode))->unref(); 45ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com} 46ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 47ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comstatic void paint_proc5(SkPaint* paint) { 48ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc3(paint); 49ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc2(paint); 50ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com} 51ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 52ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comtypedef void (*PaintProc)(SkPaint*); 53ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comconst PaintProc gPaintProcs[] = { 54ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc0, 55ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc1, 56ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc2, 57ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc3, 58ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com paint_proc5, 59ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com}; 60ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 61ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com/////////////////////////////////////////////////////////////////////////////// 62ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 635fd9243fd6b82aa3f2a2fae7c62310e77ab7b6d3mike@reedtribe.orgclass EffectsView : public SampleView { 64ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.compublic: 65ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com SkPath fPath; 66ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; 67ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 68ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com EffectsView() { 69ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com size_t i; 70ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com const float pts[] = { 71ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 0, 0, 72ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 10, 0, 73ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 10, 5, 74ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 20, -5, 75ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 10, -15, 76ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 10, -10, 77ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 0, -10 78ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com }; 79ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com fPath.moveTo(pts[0], pts[1]); 80ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) { 81ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com fPath.lineTo(pts[i], pts[i+1]); 82ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 83ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 84ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) { 85ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com fPaint[i].setAntiAlias(true); 86ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com fPaint[i].setColor(COLOR); 87ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com gPaintProcs[i](&fPaint[i]); 88ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 897d970c739d44486d3382eed8acc4eecccecf3453reed@android.com 907d970c739d44486d3382eed8acc4eecccecf3453reed@android.com SkColorMatrix cm; 917d970c739d44486d3382eed8acc4eecccecf3453reed@android.com cm.setRotate(SkColorMatrix::kG_Axis, 180); 927d970c739d44486d3382eed8acc4eecccecf3453reed@android.com cm.setIdentity(); 93ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 945fd9243fd6b82aa3f2a2fae7c62310e77ab7b6d3mike@reedtribe.org this->setBGColor(0xFFDDDDDD); 95ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 96ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 97ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comprotected: 98ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com // overrides from SkEventSink 99ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com virtual bool onQuery(SkEvent* evt) { 100ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com if (SampleCode::TitleQ(*evt)) { 101ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com SampleCode::TitleR(evt, "Effects"); 102ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com return true; 103ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 104ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com return this->INHERITED::onQuery(evt); 105ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 106ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 1075fd9243fd6b82aa3f2a2fae7c62310e77ab7b6d3mike@reedtribe.org virtual void onDrawContent(SkCanvas* canvas) { 108ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com canvas->scale(3, 3); 109ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com canvas->translate(10, 30); 110ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { 111ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com canvas->drawPath(fPath, fPaint[i]); 112ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com canvas->translate(32, 0); 113ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 114ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com } 115ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 116ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comprivate: 1175fd9243fd6b82aa3f2a2fae7c62310e77ab7b6d3mike@reedtribe.org typedef SampleView INHERITED; 118ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com}; 119ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 120ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com/////////////////////////////////////////////////////////////////////////////// 121ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.com 122ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comstatic SkView* MyFactory() { return new EffectsView; } 123ba974ccbdd7e82df46166a97741b53f074a525b6reed@android.comstatic SkViewRegister reg(MyFactory); 124