| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * 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 |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
| 10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkDevice.h" | 12 #include "SkSurface.h" |
| 13 | 13 |
| 14 static SkBitmap make_bitmap() { | 14 static SkBitmap make_bitmap() { |
| 15 SkBitmap bm; | 15 SkBitmap bm; |
| 16 bm.setConfig(SkBitmap::kARGB_8888_Config , 5, 5); | 16 bm.setConfig(SkBitmap::kARGB_8888_Config , 5, 5); |
| 17 bm.allocPixels(); | 17 bm.allocPixels(); |
| 18 | 18 |
| 19 for (int y = 0; y < bm.height(); y++) { | 19 for (int y = 0; y < bm.height(); y++) { |
| 20 uint32_t* p = bm.getAddr32(0, y); | 20 uint32_t* p = bm.getAddr32(0, y); |
| 21 for (int x = 0; x < bm.width(); x++) { | 21 for (int x = 0; x < bm.width(); x++) { |
| 22 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | 22 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 // overrides from SkEventSink | 38 // overrides from SkEventSink |
| 39 virtual bool onQuery(SkEvent* evt) { | 39 virtual bool onQuery(SkEvent* evt) { |
| 40 if (SampleCode::TitleQ(*evt)) { | 40 if (SampleCode::TitleQ(*evt)) { |
| 41 SampleCode::TitleR(evt, "Texture Domain"); | 41 SampleCode::TitleR(evt, "Texture Domain"); |
| 42 return true; | 42 return true; |
| 43 } | 43 } |
| 44 return this->INHERITED::onQuery(evt); | 44 return this->INHERITED::onQuery(evt); |
| 45 } | 45 } |
| 46 | 46 |
| 47 virtual void onDrawContent(SkCanvas* canvas) { | 47 virtual void onDrawContent(SkCanvas* canvas) { |
| 48 SkIRect srcRect; | 48 SkRect srcRect; |
| 49 SkRect dstRect; | 49 SkRect dstRect; |
| 50 SkPaint paint; | 50 SkPaint paint; |
| 51 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | 51 paint.setFilterLevel(SkPaint::kLow_FilterLevel); |
| 52 | 52 |
| 53 // Test that bitmap draws from malloc-backed bitmaps respect | 53 // Test that bitmap draws from malloc-backed bitmaps respect |
| 54 // the constrained texture domain. | 54 // the constrained texture domain. |
| 55 srcRect.setXYWH(1, 1, 3, 3); | 55 srcRect.setXYWH(1, 1, 3, 3); |
| 56 dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f); | 56 dstRect.setXYWH(5, 5, 305, 305); |
| 57 canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint); | 57 canvas->drawBitmapRectToRect(fBM, &srcRect, dstRect, &paint); |
| 58 | 58 |
| 59 // Test that bitmap draws across separate devices also respect | 59 // Test that bitmap draws across separate devices also respect |
| 60 // the constrainted texture domain. | 60 // the constrainted texture domain. |
| 61 // Note: GPU-backed bitmaps follow a different rendering path | 61 // Note: GPU-backed bitmaps follow a different rendering path |
| 62 // when copying from one GPU device to another. | 62 // when copying from one GPU device to another. |
| 63 SkAutoTUnref<SkBaseDevice> secondDevice(canvas->createCompatibleDevice( | 63 SkImageInfo info = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); |
| 64 SkBitmap::kARGB_8888_Config, 5, 5, true)); | 64 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
| 65 SkCanvas secondCanvas(secondDevice.get()); | |
| 66 | 65 |
| 67 srcRect.setXYWH(1, 1, 3, 3); | 66 srcRect.setXYWH(1, 1, 3, 3); |
| 68 dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f); | 67 dstRect.setXYWH(1, 1, 3, 3); |
| 69 secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint); | 68 surface->getCanvas()->drawBitmapRectToRect(fBM, &srcRect, dstRect, |
| 69 &paint); |
| 70 | 70 |
| 71 SkBitmap deviceBitmap = secondDevice->accessBitmap(false); | 71 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 72 | 72 |
| 73 srcRect.setXYWH(1, 1, 3, 3); | 73 srcRect.setXYWH(1, 1, 3, 3); |
| 74 dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f); | 74 dstRect.setXYWH(405, 5, 305, 305); |
| 75 canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint); | 75 image->draw(canvas, &srcRect, dstRect, &paint); |
| 76 | 76 |
| 77 // Test that bitmap blurring using a subrect | 77 // Test that bitmap blurring using a subrect |
| 78 // renders correctly | 78 // renders correctly |
| 79 srcRect.setXYWH(1, 1, 3, 3); | 79 srcRect.setXYWH(1, 1, 3, 3); |
| 80 dstRect.setXYWH(5.0f, 405.0f, 305.0f, 305.0f); | 80 dstRect.setXYWH(5, 405, 305, 305); |
| 81 SkMaskFilter* mf = SkBlurMaskFilter::Create( | 81 SkMaskFilter* mf = SkBlurMaskFilter::Create( |
| 82 SkBlurMaskFilter::kNormal_BlurStyle, | 82 SkBlurMaskFilter::kNormal_BlurStyle, |
| 83 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), | 83 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), |
| 84 SkBlurMaskFilter::kHighQuality_BlurFlag | | 84 SkBlurMaskFilter::kHighQuality_BlurFlag | |
| 85 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); | 85 SkBlurMaskFilter::kIgnoreTransform_BlurFlag); |
| 86 paint.setMaskFilter(mf)->unref(); | 86 paint.setMaskFilter(mf)->unref(); |
| 87 canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint); | 87 image->draw(canvas, &srcRect, dstRect, &paint); |
| 88 | 88 |
| 89 // Blur and a rotation + NULL src rect | 89 // Blur and a rotation + NULL src rect |
| 90 // This should not trigger the texture domain code | 90 // This should not trigger the texture domain code |
| 91 // but it will test a code path in SkGpuDevice::drawBitmap | 91 // but it will test a code path in SkGpuDevice::drawBitmap |
| 92 // that handles blurs with rects transformed to non- | 92 // that handles blurs with rects transformed to non- |
| 93 // orthogonal rects. It also tests the NULL src rect handling | 93 // orthogonal rects. It also tests the NULL src rect handling |
| 94 mf = SkBlurMaskFilter::Create( | 94 mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle, |
| 95 SkBlurMaskFilter::kNormal_BlurStyle, | 95 SkBlurMask::ConvertRadiusToSigma(5), |
| 96 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), | 96 SkBlurMaskFilter::kHighQuality_BlurFlag); |
| 97 SkBlurMaskFilter::kHighQuality_BlurFlag); | |
| 98 paint.setMaskFilter(mf)->unref(); | 97 paint.setMaskFilter(mf)->unref(); |
| 99 | 98 |
| 100 dstRect.setXYWH(-150.0f, -150.0f, 300.0f, 300.0f); | 99 dstRect.setXYWH(-150, -150, 300, 300); |
| 101 canvas->translate(550, 550); | 100 canvas->translate(550, 550); |
| 102 canvas->rotate(45); | 101 canvas->rotate(45); |
| 103 canvas->drawBitmapRect(fBM, NULL, dstRect, &paint); | 102 canvas->drawBitmapRectToRect(fBM, NULL, dstRect, &paint); |
| 104 } | 103 } |
| 105 private: | 104 private: |
| 106 typedef SkView INHERITED; | 105 typedef SkView INHERITED; |
| 107 }; | 106 }; |
| 108 | 107 |
| 109 ////////////////////////////////////////////////////////////////////////////// | 108 ////////////////////////////////////////////////////////////////////////////// |
| 110 | 109 |
| 111 static SkView* MyFactory() { return new TextureDomainView; } | 110 static SkView* MyFactory() { return new TextureDomainView; } |
| 112 static SkViewRegister reg(MyFactory); | 111 static SkViewRegister reg(MyFactory); |
| OLD | NEW |