pathopsskpclip.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkPath.h"
  10. #include "include/core/SkPicture.h"
  11. #include "include/core/SkPictureRecorder.h"
  12. #include "include/core/SkRect.h"
  13. #include "include/core/SkRefCnt.h"
  14. #include "include/core/SkScalar.h"
  15. #include "include/core/SkSize.h"
  16. #include "include/core/SkString.h"
  17. namespace skiagm {
  18. class PathOpsSkpClipGM : public GM {
  19. public:
  20. PathOpsSkpClipGM() {
  21. }
  22. protected:
  23. SkString onShortName() override {
  24. return SkString("pathopsskpclip");
  25. }
  26. SkISize onISize() override {
  27. return SkISize::Make(1200, 900);
  28. }
  29. void onDraw(SkCanvas* canvas) override {
  30. SkPictureRecorder recorder;
  31. SkCanvas* rec = recorder.beginRecording(1200, 900, nullptr, 0);
  32. SkPath p;
  33. SkRect r = {
  34. SkIntToScalar(100),
  35. SkIntToScalar(200),
  36. SkIntToScalar(400),
  37. SkIntToScalar(700)
  38. };
  39. p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
  40. rec->clipPath(p, true);
  41. rec->translate(SkIntToScalar(250), SkIntToScalar(250));
  42. rec->clipPath(p, true);
  43. rec->drawColor(0xffff0000);
  44. sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
  45. canvas->setAllowSimplifyClip(true);
  46. canvas->save();
  47. canvas->drawPicture(pict);
  48. canvas->restore();
  49. canvas->setAllowSimplifyClip(false);
  50. canvas->save();
  51. canvas->translate(SkIntToScalar(1200 / 2), 0);
  52. canvas->drawPicture(pict);
  53. canvas->restore();
  54. }
  55. private:
  56. typedef GM INHERITED;
  57. };
  58. //////////////////////////////////////////////////////////////////////////////
  59. DEF_GM( return new PathOpsSkpClipGM; )
  60. }