blob: be000f95f286d56df80477937c82ad15675b7603 [file] [log] [blame]
junov@google.com869d6d92011-05-17 15:47:10 +00001#include "SampleCode.h"
2#include "SkCanvas.h"
twiz@google.com76b82742011-06-02 20:30:02 +00003#include "SkDevice.h"
junov@google.com869d6d92011-05-17 15:47:10 +00004
5namespace {
6SkBitmap make_bitmap() {
7 SkBitmap bm;
twiz@google.com76b82742011-06-02 20:30:02 +00008 bm.setConfig(SkBitmap::kARGB_8888_Config , 5, 5);
junov@google.com869d6d92011-05-17 15:47:10 +00009 bm.allocPixels();
10
11 for (int y = 0; y < bm.height(); y++) {
12 uint32_t* p = bm.getAddr32(0, y);
13 for (int x = 0; x < bm.width(); x++) {
14 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
15 }
16 }
17 bm.unlockPixels();
18 return bm;
19}
20} // unnamed namespace
21
22class TextureDomainView : public SampleView {
23 SkBitmap fBM;
24
25public:
26 TextureDomainView(){
27 fBM = make_bitmap();
28 }
29
30protected:
31 // overrides from SkEventSink
32 virtual bool onQuery(SkEvent* evt) {
33 if (SampleCode::TitleQ(*evt)) {
34 SampleCode::TitleR(evt, "Texture Domian");
35 return true;
36 }
37 return this->INHERITED::onQuery(evt);
38 }
39
40 virtual void onDrawContent(SkCanvas* canvas) {
41 SkIRect srcRect;
42 SkRect dstRect;
43 SkPaint paint;
44 paint.setFilterBitmap(true);
twiz@google.com76b82742011-06-02 20:30:02 +000045
46 // Test that bitmap draws from malloc-backed bitmaps respect
47 // the constrained texture domain.
48 srcRect.setXYWH(1, 1, 3, 3);
49 dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f);
junov@google.com869d6d92011-05-17 15:47:10 +000050 canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint);
twiz@google.com76b82742011-06-02 20:30:02 +000051
52 // Test that bitmap draws across separate devices also respect
53 // the constrainted texture domain.
54 // Note: GPU-backed bitmaps follow a different rendering path
55 // when copying from one GPU device to another.
56 SkRefPtr<SkDevice> primaryDevice(canvas->getDevice());
57 SkRefPtr<SkDevice> secondDevice(canvas->createDevice(
58 SkBitmap::kARGB_8888_Config, 5, 5, true, true));
59 secondDevice->unref();
60 SkCanvas secondCanvas(secondDevice.get());
61
62 srcRect.setXYWH(1, 1, 3, 3);
63 dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f);
64 secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint);
65
66 SkBitmap deviceBitmap = secondDevice->accessBitmap(false);
67
68 srcRect.setXYWH(1, 1, 3, 3);
69 dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f);
70 canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
junov@google.com869d6d92011-05-17 15:47:10 +000071 }
72private:
73 typedef SkView INHERITED;
74};
75
76//////////////////////////////////////////////////////////////////////////////
77
78static SkView* MyFactory() { return new TextureDomainView; }
79static SkViewRegister reg(MyFactory);
80