From 4117a24de4c2dedf47db44746f6636ade6e29dea Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Tue, 30 Oct 2012 20:26:58 +0000 Subject: [PATCH] add test for bug in line drawing. fix is pending a way to handle all of the rebaselines... git-svn-id: http://skia.googlecode.com/svn/trunk@6208 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/fatpathfill.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++ gm/gm.h | 4 ++ gyp/gmslides.gypi | 1 + 3 files changed, 104 insertions(+) create mode 100644 gm/fatpathfill.cpp diff --git a/gm/fatpathfill.cpp b/gm/fatpathfill.cpp new file mode 100644 index 000000000..4c5fee0f6 --- /dev/null +++ b/gm/fatpathfill.cpp @@ -0,0 +1,99 @@ +/* + * 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 "SkCanvas.h" +#include "SkPath.h" +#include "SkSurface.h" + +#define ZOOM 32 +#define SMALL_W 9 +#define SMALL_H 3 +#define REPEAT_LOOP 5 + +static SkSurface* new_surface(int width, int height) { + SkImage::Info info = { + width, + height, + SkImage::kPMColor_ColorType, + SkImage::kPremul_AlphaType + }; + return SkSurface::NewRaster(info, NULL); +} + +static void draw_pixel_centers(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(0xFF0088FF); + paint.setAntiAlias(true); + + for (int y = 0; y < SMALL_H; ++y) { + for (int x = 0; x < SMALL_W; ++x) { + canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint); + } + } +} + +static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, + const SkPath paths[], int count) { + SkPaint paint; + + surface->getCanvas()->clear(0); + for (int i = 0; i < count; ++i) { + surface->getCanvas()->drawPath(paths[i], paint); + } + surface->draw(canvas, 0, 0, NULL); + + paint.setAntiAlias(true); + paint.setColor(SK_ColorRED); + paint.setStyle(SkPaint::kStroke_Style); + for (int j = 0; j < count; ++j) { + canvas->drawPath(paths[j], paint); + } + + draw_pixel_centers(canvas); +} + +class FatPathFillGM : public skiagm::GM { +public: + FatPathFillGM() {} + +protected: + virtual SkString onShortName() { + return SkString("fatpathfill"); + } + + virtual SkISize onISize() { + return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP); + } + + virtual void onDraw(SkCanvas* canvas) { + SkAutoTUnref surface(new_surface(SMALL_W, SMALL_H)); + + canvas->scale(ZOOM, ZOOM); + + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(SK_Scalar1); + + for (int i = 0; i < REPEAT_LOOP; ++i) { + SkPath line, path; + line.moveTo(1, 2); line.lineTo(4 + i, 1); + paint.getFillPath(line, &path); + draw_fatpath(canvas, surface, &path, 1); + + canvas->translate(0, SMALL_H); + } + } + +private: + typedef skiagm::GM INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + +DEF_GM(return new FatPathFillGM;) + diff --git a/gm/gm.h b/gm/gm.h index 453f104bd..e98dda54e 100644 --- a/gm/gm.h +++ b/gm/gm.h @@ -16,6 +16,10 @@ #include "SkString.h" #include "SkTRegistry.h" +#define DEF_GM(code) \ + static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void* p) { code; } \ + static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); + namespace skiagm { static inline SkISize make_isize(int w, int h) { diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index c956150bb..7e1fef55f 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -29,6 +29,7 @@ '../gm/drawlooper.cpp', '../gm/extractbitmap.cpp', '../gm/emptypath.cpp', + '../gm/fatpathfill.cpp', '../gm/filltypes.cpp', '../gm/filltypespersp.cpp', '../gm/fontscaler.cpp',