| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2012 Google Inc. | 2  * Copyright 2012 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" | 
| 9 #include "SampleCode.h" | 9 #include "SampleCode.h" | 
| 10 #include "SkView.h" | 10 #include "SkView.h" | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 84     void setWHZ(int width, int height, int zoom) { | 84     void setWHZ(int width, int height, int zoom) { | 
| 85         fW = width; | 85         fW = width; | 
| 86         fH = height; | 86         fH = height; | 
| 87         fZoom = zoom; | 87         fZoom = zoom; | 
| 88         fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zo
     om)); | 88         fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zo
     om)); | 
| 89         fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom)); | 89         fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom)); | 
| 90         fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); | 90         fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); | 
| 91         fShader = sk_tool_utils::create_checkerboard_shader(0xFFCCCCCC, 0xFFFFFF
     FF, zoom); | 91         fShader = sk_tool_utils::create_checkerboard_shader(0xFFCCCCCC, 0xFFFFFF
     FF, zoom); | 
| 92 | 92 | 
| 93         SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 93         SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 
| 94         fMinSurface.reset(SkSurface::NewRaster(info)); | 94         fMinSurface = SkSurface::MakeRaster(info); | 
| 95         info = info.makeWH(width * zoom, height * zoom); | 95         info = info.makeWH(width * zoom, height * zoom); | 
| 96         fMaxSurface.reset(SkSurface::NewRaster(info)); | 96         fMaxSurface = SkSurface::MakeRaster(info); | 
| 97     } | 97     } | 
| 98 | 98 | 
| 99     void drawBG(SkCanvas*); | 99     void drawBG(SkCanvas*); | 
| 100     void drawFG(SkCanvas*); | 100     void drawFG(SkCanvas*); | 
| 101     void drawLine(SkCanvas*, SkPoint pts[2]); | 101     void drawLine(SkCanvas*, SkPoint pts[2]); | 
| 102     void drawRect(SkCanvas* canvas, SkPoint pts[2]); | 102     void drawRect(SkCanvas* canvas, SkPoint pts[2]); | 
| 103     void drawTriangle(SkCanvas* canvas, SkPoint pts[3]); | 103     void drawTriangle(SkCanvas* canvas, SkPoint pts[3]); | 
| 104 | 104 | 
| 105     SkPaint::Cap fStrokeCap; | 105     SkPaint::Cap fStrokeCap; | 
| 106 | 106 | 
| 107 private: | 107 private: | 
| 108     bool fAA, fGrid, fShowSkeleton, fUseGPU, fUseClip, fRectAsOval, fUseTriangle
     ; | 108     bool fAA, fGrid, fShowSkeleton, fUseGPU, fUseClip, fRectAsOval, fUseTriangle
     ; | 
| 109     Style fStyle; | 109     Style fStyle; | 
| 110     int fW, fH, fZoom; | 110     int fW, fH, fZoom; | 
| 111     SkMatrix fMatrix, fInverse; | 111     SkMatrix fMatrix, fInverse; | 
| 112     SkRect   fBounds, fClipRect; | 112     SkRect   fBounds, fClipRect; | 
| 113     sk_sp<SkShader> fShader; | 113     sk_sp<SkShader> fShader; | 
| 114     SkAutoTUnref<SkSurface> fMinSurface; | 114     sk_sp<SkSurface> fMinSurface; | 
| 115     SkAutoTUnref<SkSurface> fMaxSurface; | 115     sk_sp<SkSurface> fMaxSurface; | 
| 116 | 116 | 
| 117     void setupPaint(SkPaint* paint) { | 117     void setupPaint(SkPaint* paint) { | 
| 118         bool aa = this->getAA(); | 118         bool aa = this->getAA(); | 
| 119         paint->setStrokeCap(fStrokeCap); | 119         paint->setStrokeCap(fStrokeCap); | 
| 120         switch (fStyle) { | 120         switch (fStyle) { | 
| 121             case kHair_Style: | 121             case kHair_Style: | 
| 122                 paint->setStrokeWidth(0); | 122                 paint->setStrokeWidth(0); | 
| 123                 break; | 123                 break; | 
| 124             case kStroke_Style: | 124             case kStroke_Style: | 
| 125                 paint->setStrokeWidth(SK_Scalar1); | 125                 paint->setStrokeWidth(SK_Scalar1); | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 155             fRectAsOval ? path.addOval(r) : path.addRect(r); | 155             fRectAsOval ? path.addOval(r) : path.addRect(r); | 
| 156             if (fUseGPU) { | 156             if (fUseGPU) { | 
| 157                 path.moveTo(r.fLeft, r.fTop); | 157                 path.moveTo(r.fLeft, r.fTop); | 
| 158                 path.lineTo(r.fRight, r.fBottom); | 158                 path.lineTo(r.fRight, r.fBottom); | 
| 159             } | 159             } | 
| 160         } | 160         } | 
| 161         max->drawPath(path, paint); | 161         max->drawPath(path, paint); | 
| 162     } | 162     } | 
| 163 | 163 | 
| 164     void copyMinToMax() { | 164     void copyMinToMax() { | 
| 165         erase(fMaxSurface); | 165         erase(fMaxSurface.get()); | 
| 166         SkCanvas* canvas = fMaxSurface->getCanvas(); | 166         SkCanvas* canvas = fMaxSurface->getCanvas(); | 
| 167         canvas->save(); | 167         canvas->save(); | 
| 168         canvas->concat(fMatrix); | 168         canvas->concat(fMatrix); | 
| 169         fMinSurface->draw(canvas, 0, 0, nullptr); | 169         fMinSurface->draw(canvas, 0, 0, nullptr); | 
| 170         canvas->restore(); | 170         canvas->restore(); | 
| 171 | 171 | 
| 172         SkPaint paint; | 172         SkPaint paint; | 
| 173         paint.setXfermodeMode(SkXfermode::kClear_Mode); | 173         paint.setXfermodeMode(SkXfermode::kClear_Mode); | 
| 174         for (int iy = 1; iy < fH; ++iy) { | 174         for (int iy = 1; iy < fH; ++iy) { | 
| 175             SkScalar y = SkIntToScalar(iy * fZoom); | 175             SkScalar y = SkIntToScalar(iy * fZoom); | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 268 | 268 | 
| 269 void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) { | 269 void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) { | 
| 270     SkPaint paint; | 270     SkPaint paint; | 
| 271 | 271 | 
| 272     fInverse.mapPoints(pts, 2); | 272     fInverse.mapPoints(pts, 2); | 
| 273 | 273 | 
| 274     if (fGrid) { | 274     if (fGrid) { | 
| 275         apply_grid(pts, 2); | 275         apply_grid(pts, 2); | 
| 276     } | 276     } | 
| 277 | 277 | 
| 278     erase(fMinSurface); | 278     erase(fMinSurface.get()); | 
| 279     this->setupPaint(&paint); | 279     this->setupPaint(&paint); | 
| 280     paint.setColor(FAT_PIXEL_COLOR); | 280     paint.setColor(FAT_PIXEL_COLOR); | 
| 281     if (fUseClip) { | 281     if (fUseClip) { | 
| 282         fMinSurface->getCanvas()->save(); | 282         fMinSurface->getCanvas()->save(); | 
| 283         SkRect r = fClipRect; | 283         SkRect r = fClipRect; | 
| 284         r.inset(SK_Scalar1/3, SK_Scalar1/3); | 284         r.inset(SK_Scalar1/3, SK_Scalar1/3); | 
| 285         fMinSurface->getCanvas()->clipRect(r, SkRegion::kIntersect_Op, true); | 285         fMinSurface->getCanvas()->clipRect(r, SkRegion::kIntersect_Op, true); | 
| 286     } | 286     } | 
| 287     fMinSurface->getCanvas()->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].f
     Y, paint); | 287     fMinSurface->getCanvas()->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].f
     Y, paint); | 
| 288     if (fUseClip) { | 288     if (fUseClip) { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 303 | 303 | 
| 304     fInverse.mapPoints(pts, 2); | 304     fInverse.mapPoints(pts, 2); | 
| 305 | 305 | 
| 306     if (fGrid) { | 306     if (fGrid) { | 
| 307         apply_grid(pts, 2); | 307         apply_grid(pts, 2); | 
| 308     } | 308     } | 
| 309 | 309 | 
| 310     SkRect r; | 310     SkRect r; | 
| 311     r.set(pts, 2); | 311     r.set(pts, 2); | 
| 312 | 312 | 
| 313     erase(fMinSurface); | 313     erase(fMinSurface.get()); | 
| 314     this->setupPaint(&paint); | 314     this->setupPaint(&paint); | 
| 315     paint.setColor(FAT_PIXEL_COLOR); | 315     paint.setColor(FAT_PIXEL_COLOR); | 
| 316     { | 316     { | 
| 317         SkCanvas* c = fMinSurface->getCanvas(); | 317         SkCanvas* c = fMinSurface->getCanvas(); | 
| 318         fRectAsOval ? c->drawOval(r, paint) : c->drawRect(r, paint); | 318         fRectAsOval ? c->drawOval(r, paint) : c->drawRect(r, paint); | 
| 319     } | 319     } | 
| 320     this->copyMinToMax(); | 320     this->copyMinToMax(); | 
| 321 | 321 | 
| 322     SkCanvas* max = fMaxSurface->getCanvas(); | 322     SkCanvas* max = fMaxSurface->getCanvas(); | 
| 323 | 323 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 349     if (fGrid) { | 349     if (fGrid) { | 
| 350         apply_grid(pts, 3); | 350         apply_grid(pts, 3); | 
| 351     } | 351     } | 
| 352 | 352 | 
| 353     SkPath path; | 353     SkPath path; | 
| 354     path.moveTo(pts[0]); | 354     path.moveTo(pts[0]); | 
| 355     path.lineTo(pts[1]); | 355     path.lineTo(pts[1]); | 
| 356     path.lineTo(pts[2]); | 356     path.lineTo(pts[2]); | 
| 357     path.close(); | 357     path.close(); | 
| 358 | 358 | 
| 359     erase(fMinSurface); | 359     erase(fMinSurface.get()); | 
| 360     this->setupPaint(&paint); | 360     this->setupPaint(&paint); | 
| 361     paint.setColor(FAT_PIXEL_COLOR); | 361     paint.setColor(FAT_PIXEL_COLOR); | 
| 362     fMinSurface->getCanvas()->drawPath(path, paint); | 362     fMinSurface->getCanvas()->drawPath(path, paint); | 
| 363     this->copyMinToMax(); | 363     this->copyMinToMax(); | 
| 364 | 364 | 
| 365     SkCanvas* max = fMaxSurface->getCanvas(); | 365     SkCanvas* max = fMaxSurface->getCanvas(); | 
| 366 | 366 | 
| 367     fMatrix.mapPoints(pts, 3); | 367     fMatrix.mapPoints(pts, 3); | 
| 368     this->drawTriangleSkeleton(max, pts); | 368     this->drawTriangleSkeleton(max, pts); | 
| 369 | 369 | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 525 | 525 | 
| 526 private: | 526 private: | 
| 527 | 527 | 
| 528     typedef SampleView INHERITED; | 528     typedef SampleView INHERITED; | 
| 529 }; | 529 }; | 
| 530 | 530 | 
| 531 ////////////////////////////////////////////////////////////////////////////// | 531 ////////////////////////////////////////////////////////////////////////////// | 
| 532 | 532 | 
| 533 static SkView* MyFactory() { return new DrawLineView; } | 533 static SkView* MyFactory() { return new DrawLineView; } | 
| 534 static SkViewRegister reg(MyFactory); | 534 static SkViewRegister reg(MyFactory); | 
| OLD | NEW | 
|---|