skia2/gm/shadows.cpp
epoger@google.com ec3ed6a5eb Automatic update of all copyright notices to reflect new license terms.
I have manually examined all of these diffs and restored a few files that
seem to require manual adjustment.

The following files still need to be modified manually, in a separate CL:

android_sample/SampleApp/AndroidManifest.xml
android_sample/SampleApp/res/layout/layout.xml
android_sample/SampleApp/res/menu/sample.xml
android_sample/SampleApp/res/values/strings.xml
android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java
android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java
experimental/CiCarbonSampleMain.c
experimental/CocoaDebugger/main.m
experimental/FileReaderApp/main.m
experimental/SimpleCocoaApp/main.m
experimental/iOSSampleApp/Shared/SkAlertPrompt.h
experimental/iOSSampleApp/Shared/SkAlertPrompt.m
experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig
experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig
experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig
gpu/src/android/GrGLDefaultInterface_android.cpp
gyp/common.gypi
gyp_skia
include/ports/SkHarfBuzzFont.h
include/views/SkOSWindow_wxwidgets.h
make.bat
make.py
src/opts/memset.arm.S
src/opts/memset16_neon.S
src/opts/memset32_neon.S
src/opts/opts_check_arm.cpp
src/ports/SkDebug_brew.cpp
src/ports/SkMemory_brew.cpp
src/ports/SkOSFile_brew.cpp
src/ports/SkXMLParser_empty.cpp
src/utils/ios/SkImageDecoder_iOS.mm
src/utils/ios/SkOSFile_iOS.mm
src/utils/ios/SkStream_NSData.mm
tests/FillPathTest.cpp
Review URL: http://codereview.appspot.com/4816058

git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00

122 lines
4.0 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkBlurDrawLooper.h"
namespace skiagm {
///////////////////////////////////////////////////////////////////////////////
static void setup(SkPaint* paint, SkColor c, SkScalar strokeWidth) {
paint->setColor(c);
if (strokeWidth < 0) {
paint->setStyle(SkPaint::kFill_Style);
} else {
paint->setStyle(SkPaint::kStroke_Style);
paint->setStrokeWidth(strokeWidth);
}
}
class ShadowsGM : public GM {
public:
SkPath fCirclePath;
SkRect fRect;
ShadowsGM() {
fCirclePath.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(10) );
fRect.set(SkIntToScalar(10), SkIntToScalar(10),
SkIntToScalar(30), SkIntToScalar(30));
}
protected:
virtual SkString onShortName() {
return SkString("shadows");
}
virtual SkISize onISize() {
return make_isize(200, 80);
}
void drawBG(SkCanvas* canvas) {
canvas->drawColor(0xFFDDDDDD);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
SkBlurDrawLooper* shadowLoopers[5];
shadowLoopers[0] =
new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5),
SkIntToScalar(10), 0xFF0000FF,
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag );
SkAutoUnref aurL0(shadowLoopers[0]);
shadowLoopers[1] =
new SkBlurDrawLooper (SkIntToScalar(10), SkIntToScalar(5),
SkIntToScalar(10), 0xFF0000FF,
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag );
SkAutoUnref aurL1(shadowLoopers[1]);
shadowLoopers[2] =
new SkBlurDrawLooper (SkIntToScalar(5), SkIntToScalar(5),
SkIntToScalar(10), 0xFF000000,
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag );
SkAutoUnref aurL2(shadowLoopers[2]);
shadowLoopers[3] =
new SkBlurDrawLooper (SkIntToScalar(5), SkIntToScalar(-5),
SkIntToScalar(-10), 0x7FFF0000,
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag );
SkAutoUnref aurL3(shadowLoopers[3]);
shadowLoopers[4] =
new SkBlurDrawLooper (SkIntToScalar(0), SkIntToScalar(5),
SkIntToScalar(5), 0xFF000000,
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
SkBlurDrawLooper::kHighQuality_BlurFlag );
SkAutoUnref aurL4(shadowLoopers[4]);
static const struct {
SkColor fColor;
SkScalar fStrokeWidth;
} gRec[] = {
{ SK_ColorRED, -SK_Scalar1 },
{ SK_ColorGREEN, SkIntToScalar(4) },
};
SkPaint paint;
paint.setAntiAlias(true);
for (size_t i = 0; i < SK_ARRAY_COUNT(shadowLoopers); ++i) {
SkAutoCanvasRestore acr(canvas, true);
paint.setLooper(shadowLoopers[i]);
canvas->translate(SkIntToScalar(i*40), SkIntToScalar(0));
setup(&paint, gRec[0].fColor, gRec[0].fStrokeWidth);
canvas->drawRect(fRect, paint);
canvas->translate(SkIntToScalar(0), SkIntToScalar(40));
setup(&paint, gRec[1].fColor, gRec[1].fStrokeWidth);
canvas->drawPath(fCirclePath, paint);
}
}
private:
typedef GM INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new ShadowsGM; }
static GMRegistry reg(MyFactory);
}