• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
make_bm(SkBitmap * bm,int width,int height,SkColor color)12 static 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 
show_bm(SkCanvas * canvas,int width,int height,SkColor color)19 static 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 
49 class VeryLargeBitmapGM : public skiagm::GM {
50 public:
VeryLargeBitmapGM()51     VeryLargeBitmapGM() {}
52 
53 protected:
onShortName()54     virtual SkString onShortName() SK_OVERRIDE {
55         return SkString("verylargebitmap");
56     }
57 
onISize()58     virtual SkISize onISize() SK_OVERRIDE {
59         return SkISize::Make(640, 480);
60     }
61 
onDraw(SkCanvas * canvas)62     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
63         int veryBig = 100*1024; // 64K < size
64         int big = 60*1024;      // 32K < size < 64K
65         int small = 300;
66 
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));
73 
74         // 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 
79 private:
80     typedef skiagm::GM INHERITED;
81 };
82 
83 //////////////////////////////////////////////////////////////////////////////
84 
85 // This GM allocates more memory than Android devices are capable of fulfilling.
86 #ifndef SK_BUILD_FOR_ANDROID
MyFactory(void *)87 static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
88 static skiagm::GMRegistry reg(MyFactory);
89 #endif
90