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.
8 #include "SampleCode.h"
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
12 #include "SkSurface.h"
14 static SkBitmap make_bitmap() {
16 bm.allocN32Pixels(5, 5);
18 for (int y = 0; y < bm.height(); y++) {
19 uint32_t* p = bm.getAddr32(0, y);
20 for (int x = 0; x < bm.width(); x++) {
21 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
28 class TextureDomainView : public SampleView {
37 // overrides from SkEventSink
38 virtual bool onQuery(SkEvent* evt) {
39 if (SampleCode::TitleQ(*evt)) {
40 SampleCode::TitleR(evt, "Texture Domain");
43 return this->INHERITED::onQuery(evt);
46 virtual void onDrawContent(SkCanvas* canvas) {
50 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
52 // Test that bitmap draws from malloc-backed bitmaps respect
53 // the constrained texture domain.
54 srcRect.setXYWH(1, 1, 3, 3);
55 dstRect.setXYWH(5, 5, 305, 305);
56 canvas->drawBitmapRectToRect(fBM, &srcRect, dstRect, &paint);
58 // Test that bitmap draws across separate devices also respect
59 // the constrainted texture domain.
60 // Note: GPU-backed bitmaps follow a different rendering path
61 // when copying from one GPU device to another.
62 SkImageInfo info = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
63 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
65 srcRect.setXYWH(1, 1, 3, 3);
66 dstRect.setXYWH(1, 1, 3, 3);
67 surface->getCanvas()->drawBitmapRectToRect(fBM, &srcRect, dstRect,
70 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
72 srcRect.setXYWH(1, 1, 3, 3);
73 dstRect.setXYWH(405, 5, 305, 305);
74 image->draw(canvas, &srcRect, dstRect, &paint);
76 // Test that bitmap blurring using a subrect
78 srcRect.setXYWH(1, 1, 3, 3);
79 dstRect.setXYWH(5, 405, 305, 305);
80 SkMaskFilter* mf = SkBlurMaskFilter::Create(
82 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
83 SkBlurMaskFilter::kHighQuality_BlurFlag |
84 SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
85 paint.setMaskFilter(mf)->unref();
86 image->draw(canvas, &srcRect, dstRect, &paint);
88 // Blur and a rotation + NULL src rect
89 // This should not trigger the texture domain code
90 // but it will test a code path in SkGpuDevice::drawBitmap
91 // that handles blurs with rects transformed to non-
92 // orthogonal rects. It also tests the NULL src rect handling
93 mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
94 SkBlurMask::ConvertRadiusToSigma(5),
95 SkBlurMaskFilter::kHighQuality_BlurFlag);
96 paint.setMaskFilter(mf)->unref();
98 dstRect.setXYWH(-150, -150, 300, 300);
99 canvas->translate(550, 550);
101 canvas->drawBitmapRectToRect(fBM, NULL, dstRect, &paint);
104 typedef SkView INHERITED;
107 //////////////////////////////////////////////////////////////////////////////
109 static SkView* MyFactory() { return new TextureDomainView; }
110 static SkViewRegister reg(MyFactory);