Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 7 | |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
| 12 #include "SkString.h" | 12 #include "SkString.h" |
| 13 #include "SkSurface.h" | |
|
scroggo
2014/02/05 16:41:12
Did you mean to call newSurface in this file? It c
| |
| 13 | 14 |
| 14 namespace skiagm { | 15 namespace skiagm { |
| 15 | 16 |
| 16 static void create_bitmap(SkBitmap* bitmap) { | 17 static void create_bitmap(SkBitmap* bitmap) { |
| 17 const int W = 100; | 18 const int W = 100; |
| 18 const int H = 100; | 19 const int H = 100; |
| 19 bitmap->allocN32Pixels(W, H); | 20 bitmap->allocN32Pixels(W, H); |
| 20 | 21 |
| 21 SkCanvas canvas(*bitmap); | 22 SkCanvas canvas(*bitmap); |
| 22 canvas.drawColor(SK_ColorRED); | 23 canvas.drawColor(SK_ColorRED); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 bitmap.extractSubset(&subset, SkIRect::MakeWH(x, bitmap.height())); | 65 bitmap.extractSubset(&subset, SkIRect::MakeWH(x, bitmap.height())); |
| 65 SkAutoCanvasRestore autoRestore(canvas, true); | 66 SkAutoCanvasRestore autoRestore(canvas, true); |
| 66 canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); | 67 canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); |
| 67 canvas->drawBitmap(subset, 0, 0); | 68 canvas->drawBitmap(subset, 0, 0); |
| 68 // Now draw a subet which has the same width and pixelref offset but | 69 // Now draw a subet which has the same width and pixelref offset but |
| 69 // a different height | 70 // a different height |
| 70 bitmap.extractSubset(&subset, SkIRect::MakeWH(bitmap.height(), y)); | 71 bitmap.extractSubset(&subset, SkIRect::MakeWH(bitmap.height(), y)); |
| 71 canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); | 72 canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); |
| 72 canvas->drawBitmap(subset, 0, 0); | 73 canvas->drawBitmap(subset, 0, 0); |
| 73 } | 74 } |
| 74 | |
| 75 // Now do the same but with a device bitmap as source image | |
| 76 SkAutoTUnref<SkBaseDevice> secondDevice(canvas->createCompatibleDevice( | |
| 77 SkBitmap::kARGB_8888_Config, bitmap.width(), | |
| 78 bitmap.height(), true)); | |
| 79 SkCanvas secondCanvas(secondDevice.get()); | |
| 80 secondCanvas.writePixels(bitmap, 0, 0); | |
| 81 | |
| 82 SkBitmap deviceBitmap = secondDevice->accessBitmap(false); | |
| 83 SkBitmap deviceSubset; | |
| 84 deviceBitmap.extractSubset(&deviceSubset, | |
| 85 SkIRect::MakeXYWH(x, y, x, y)); | |
| 86 | |
| 87 canvas->translate(SkIntToScalar(120), SkIntToScalar(0)); | |
| 88 | |
| 89 canvas->drawBitmap(deviceBitmap, 0, 0); | |
| 90 canvas->drawBitmap(deviceSubset, 0, 0); | |
| 91 | |
| 92 } | 75 } |
| 93 | 76 |
| 94 private: | 77 private: |
| 95 typedef GM INHERITED; | 78 typedef GM INHERITED; |
| 96 }; | 79 }; |
| 97 | 80 |
| 98 ////////////////////////////////////////////////////////////////////////////// | 81 ////////////////////////////////////////////////////////////////////////////// |
| 99 | 82 |
| 100 static GM* MyFactory(void*) { return new ExtractBitmapGM; } | 83 static GM* MyFactory(void*) { return new ExtractBitmapGM; } |
| 101 static GMRegistry reg(MyFactory); | 84 static GMRegistry reg(MyFactory); |
| 102 | 85 |
| 103 } | 86 } |
| OLD | NEW |