blob: fc49ab19f253c294c90fb7b44f5741ad68cbf610 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "tools/Resources.h"
Michael Ludwig4edd4202019-01-15 12:09:25 -050017
18DEF_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
Michael Ludwig4edd4202019-01-15 12:09:25 -050028 // Must be at least medium to require mipmaps when we downscale the image
Mike Reed07c5f522021-01-23 12:23:23 -050029 SkSamplingOptions sampling(SkFilterMode::kLinear,
30 SkMipmapMode::kLinear);
31
Michael Ludwig4edd4202019-01-15 12:09:25 -050032 sk_sp<SkImage> image(GetResourceAsImage("images/mandrill_512.png"));
33
34 SkPaint overlayPaint;
35 overlayPaint.setColor(0x80FFFFFF);
36
37 // Make the overlay visible even when the downscaled images fail to render
38 canvas->clear(0xFF888888);
39
40 canvas->translate(20, 20);
41 for (const auto& xform : xforms) {
42 canvas->save();
43 canvas->translate(xform.fTx, xform.fTy);
44 canvas->scale(xform.fSx, xform.fSy);
45
46 // Draw an image, possibly down sampled, which forces us to generate mipmaps inline
47 // on the second iteration.
Mike Reed07c5f522021-01-23 12:23:23 -050048 canvas->drawImage(image, 0, 0, sampling, nullptr);
Michael Ludwig4edd4202019-01-15 12:09:25 -050049
50 // Draw an overlay that requires the scissor test for its clipping, so that the mipmap
51 // generation + scissor interference bug is highlighted in Adreno 330 devices.
52 SkRect inner = SkRect::MakeLTRB(32.f, 32.f, 480.f, 480.f);
53 SkRect outer = inner.makeOutset(16.f, 16.f);
54
55 // Clip to smaller rectangle
56 canvas->save();
57 canvas->clipRect(inner);
58 // Then apply a rotation and draw a larger rectangle to ensure the clip cannot be dropped
59 canvas->rotate(20.f);
60 canvas->drawRect(outer, overlayPaint);
61 canvas->restore();
62
63 canvas->restore();
64 }
65}