diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-13 14:22:17 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-13 14:22:17 +0000 |
commit | 82aa7482cbf55ce6d42c692550cadee5e23146e4 (patch) | |
tree | cf208c1d3e82a2288236d1591b1b85e3870371a9 /gm | |
parent | 3ada0efdc8de8316df8113ec54ffd1a3f33ecd21 (diff) |
Add a zoom filter to Skia. This will be used on ChromeOS to implement the screen magnifier.
Committed on behalf of zork@chromium.org
Review URL: http://codereview.appspot.com/6354065/
git-svn-id: http://skia.googlecode.com/svn/trunk@5056 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/imagemagnifier.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/gm/imagemagnifier.cpp b/gm/imagemagnifier.cpp new file mode 100644 index 0000000000..f9aff281fe --- /dev/null +++ b/gm/imagemagnifier.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2012 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 "SkMagnifierImageFilter.h" + +#define WIDTH 500 +#define HEIGHT 500 + +namespace skiagm { + +class ImageMagnifierGM : public GM { +public: + ImageMagnifierGM() { + this->setBGColor(0xFF000000); + } + +protected: + virtual SkString onShortName() { + return SkString("imagemagnifier"); + } + + virtual SkISize onISize() { + return make_isize(WIDTH, HEIGHT); + } + + virtual void onDraw(SkCanvas* canvas) { + SkPaint paint; + paint.setImageFilter( + new SkMagnifierImageFilter( + SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125), + SkIntToScalar(WIDTH / 2), + SkIntToScalar(HEIGHT / 2)), + 100))->unref(); + canvas->saveLayer(NULL, &paint); + paint.setAntiAlias(true); + const char* str = "The quick brown fox jumped over the lazy dog."; + srand(1234); + for (int i = 0; i < 25; ++i) { + int x = rand() % WIDTH; + int y = rand() % HEIGHT; + paint.setColor(rand() % 0x1000000 | 0xFF000000); + paint.setTextSize(SkIntToScalar(rand() % 300)); + canvas->drawText(str, strlen(str), SkIntToScalar(x), + SkIntToScalar(y), paint); + } + canvas->restore(); + } + +private: + typedef GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +static GM* MyFactory(void*) { return new ImageMagnifierGM; } +static GMRegistry reg(MyFactory); + +} |