blob: d448d2da023354976297263c16d221c0b623ed27 [file] [log] [blame]
reed@google.com7eb3a262012-08-07 14:05:14 +00001/*
2 * Copyright 2012 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#include "SkCanvas.h"
10#include "SkPath.h"
11
12static void make_bm(SkBitmap* bm, int width, int height, SkColor color) {
13 bm->setConfig(SkBitmap::kARGB_8888_Config, width, height);
14 bm->allocPixels();
15 bm->eraseColor(color);
16 bm->setImmutable();
17}
18
19static void show_bm(SkCanvas* canvas, int width, int height, SkColor color) {
20 SkBitmap bm;
21 make_bm(&bm, width, height, color);
22
23 SkPaint paint;
24 SkRect r;
25 SkIRect ir;
26
27 paint.setStyle(SkPaint::kStroke_Style);
28
29 ir.set(0, 0, 128, 128);
30 r.set(ir);
31
32 canvas->save();
33 canvas->clipRect(r);
34 canvas->drawBitmap(bm, 0, 0, NULL);
35 canvas->restore();
36 canvas->drawRect(r, paint);
37
38 r.offset(SkIntToScalar(150), 0);
39 // exercises extract bitmap, but not shader
40 canvas->drawBitmapRect(bm, &ir, r, NULL);
41 canvas->drawRect(r, paint);
42
43 r.offset(SkIntToScalar(150), 0);
44 // exercises bitmapshader
45 canvas->drawBitmapRect(bm, NULL, r, NULL);
46 canvas->drawRect(r, paint);
47}
48
49class VeryLargeBitmapGM : public skiagm::GM {
50public:
51 VeryLargeBitmapGM() {}
52
53protected:
54 virtual SkString onShortName() SK_OVERRIDE {
55 return SkString("verylargebitmap");
56 }
57
58 virtual SkISize onISize() SK_OVERRIDE {
59 return SkISize::Make(640, 480);
60 }
61
62 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
robertphillips@google.comc3dc12d2013-07-15 15:48:48 +000063 int veryBig = 70*1024; // 64K < size
reed@google.com7eb3a262012-08-07 14:05:14 +000064 int big = 60*1024; // 32K < size < 64K
robertphillips@google.comc3dc12d2013-07-15 15:48:48 +000065 int small = 150;
reed@google.com7eb3a262012-08-07 14:05:14 +000066
67 canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
68 show_bm(canvas, small, small, SK_ColorRED);
69 canvas->translate(0, SkIntToScalar(150));
70
71 show_bm(canvas, big, small, SK_ColorBLUE);
72 canvas->translate(0, SkIntToScalar(150));
rmistry@google.comae933ce2012-08-23 18:19:56 +000073
reed@google.com7eb3a262012-08-07 14:05:14 +000074 // as of this writing, the raster code will fail to draw the scaled version
75 // since it has a 64K limit on x,y coordinates... (but gpu should succeed)
76 show_bm(canvas, veryBig, small, SK_ColorGREEN);
77 }
78
79private:
80 typedef skiagm::GM INHERITED;
81};
82
83//////////////////////////////////////////////////////////////////////////////
84
borenet@google.com24e89992012-08-07 14:46:05 +000085// This GM allocates more memory than Android devices are capable of fulfilling.
86#ifndef SK_BUILD_FOR_ANDROID
reed@google.com7eb3a262012-08-07 14:05:14 +000087static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
88static skiagm::GMRegistry reg(MyFactory);
borenet@google.com24e89992012-08-07 14:46:05 +000089#endif