• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 // HASH=c5bfa944e17ba4a4400dc799f032069c
5 REG_FIDDLE(Canvas_drawBitmapLattice, 256, 128, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7     SkIRect center = { 20, 10, 50, 40 };
8     SkBitmap bitmap;
9     bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
10     SkCanvas bitCanvas(bitmap);
11     SkPaint paint;
12     SkColor gray = 0xFF000000;
13     int left = 0;
14     for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
15         int top = 0;
16         for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
17             paint.setColor(gray);
18             bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
19             gray += 0x001f1f1f;
20             top = bottom;
21         }
22         left = right;
23     }
24     const int xDivs[] = { center.fLeft, center.fRight };
25     const int yDivs[] = { center.fTop, center.fBottom };
26     SkCanvas::Lattice::RectType fillTypes[3][3];
27     memset(fillTypes, 0, sizeof(fillTypes));
28     fillTypes[1][1] = SkCanvas::Lattice::kTransparent;
29     SkColor dummy[9];  // temporary pending bug fix
30     SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs),
31          SK_ARRAY_COUNT(yDivs), nullptr, dummy };
32     for (auto dest: { 20, 30, 40, 60, 90 } ) {
33         canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr);
34         canvas->translate(dest + 4, 0);
35     }
36 }
37 }  // END FIDDLE
38