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