2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
13 #include "SkSurface.h"
17 static void create_bitmap(SkBitmap* bitmap) {
20 bitmap->allocN32Pixels(W, H);
22 SkCanvas canvas(*bitmap);
23 canvas.drawColor(SK_ColorRED);
25 paint.setColor(SK_ColorBLUE);
26 canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
29 class ExtractBitmapGM : public GM {
34 // overrides from SkEventSink
35 SkString onShortName() SK_OVERRIDE {
36 return SkString("extractbitmap");
39 SkISize onISize() SK_OVERRIDE {
40 return SkISize::Make(600, 600);
43 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
45 create_bitmap(&bitmap);
46 int x = bitmap.width() / 2;
47 int y = bitmap.height() / 2;
49 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
51 canvas->drawBitmap(bitmap, 0, 0);
54 // Do some subset drawing. This will test that an SkGPipe properly
55 // handles the case where bitmaps share a pixelref
56 // Draw the bottom right fourth of the bitmap over the top left
58 bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
59 canvas->drawBitmap(subset, 0, 0);
60 // Draw the top left corner over the bottom right
61 bitmap.extractSubset(&subset, SkIRect::MakeWH(x, y));
62 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y));
63 // Draw a subset which has the same height and pixelref offset but a
65 bitmap.extractSubset(&subset, SkIRect::MakeWH(x, bitmap.height()));
66 SkAutoCanvasRestore autoRestore(canvas, true);
67 canvas->translate(0, SkIntToScalar(bitmap.height() + 20));
68 canvas->drawBitmap(subset, 0, 0);
69 // Now draw a subet which has the same width and pixelref offset but
71 bitmap.extractSubset(&subset, SkIRect::MakeWH(bitmap.height(), y));
72 canvas->translate(0, SkIntToScalar(bitmap.height() + 20));
73 canvas->drawBitmap(subset, 0, 0);
81 //////////////////////////////////////////////////////////////////////////////
83 static GM* MyFactory(void*) { return new ExtractBitmapGM; }
84 static GMRegistry reg(MyFactory);