• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 
8 #include "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkFilterQuality.h"
11 #include "include/core/SkImage.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkScalar.h"
16 #include "tools/Resources.h"
17 
18 DEF_SIMPLE_GM(skbug_8664, canvas, 830, 550) {
19     const struct {
20         SkScalar    fSx, fSy, fTx, fTy;
21     } xforms[] = {
22         { 1, 1, 0, 0 },
23         { 0.5f, 0.5f, 530, 0 },
24         { 0.25f, 0.25f, 530, 275 },
25         { 0.125f, 0.125f, 530, 420 },
26     };
27 
28     SkPaint imagePaint;
29     // Must be at least medium to require mipmaps when we downscale the image
30     imagePaint.setFilterQuality(kMedium_SkFilterQuality);
31     sk_sp<SkImage> image(GetResourceAsImage("images/mandrill_512.png"));
32 
33     SkPaint overlayPaint;
34     overlayPaint.setColor(0x80FFFFFF);
35 
36     // Make the overlay visible even when the downscaled images fail to render
37     canvas->clear(0xFF888888);
38 
39     canvas->translate(20, 20);
40     for (const auto& xform : xforms) {
41         canvas->save();
42         canvas->translate(xform.fTx, xform.fTy);
43         canvas->scale(xform.fSx, xform.fSy);
44 
45         // Draw an image, possibly down sampled, which forces us to generate mipmaps inline
46         // on the second iteration.
47         canvas->drawImage(image, 0, 0, &imagePaint);
48 
49         // Draw an overlay that requires the scissor test for its clipping, so that the mipmap
50         // generation + scissor interference bug is highlighted in Adreno 330 devices.
51         SkRect inner = SkRect::MakeLTRB(32.f, 32.f, 480.f, 480.f);
52         SkRect outer = inner.makeOutset(16.f, 16.f);
53 
54         // Clip to smaller rectangle
55         canvas->save();
56         canvas->clipRect(inner);
57         // Then apply a rotation and draw a larger rectangle to ensure the clip cannot be dropped
58         canvas->rotate(20.f);
59         canvas->drawRect(outer, overlayPaint);
60         canvas->restore();
61 
62         canvas->restore();
63     }
64 }
65