2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-09-13 12:39:55 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
2011-05-17 15:47:10 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-02-05 15:32:21 +00:00
|
|
|
#include "SkSurface.h"
|
2011-05-17 15:47:10 +00:00
|
|
|
|
2013-09-13 12:39:55 +00:00
|
|
|
static SkBitmap make_bitmap() {
|
2011-05-17 15:47:10 +00:00
|
|
|
SkBitmap bm;
|
2014-02-17 02:55:57 +00:00
|
|
|
bm.allocN32Pixels(5, 5);
|
2011-05-17 15:47:10 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < bm.height(); y++) {
|
|
|
|
uint32_t* p = bm.getAddr32(0, y);
|
|
|
|
for (int x = 0; x < bm.width(); x++) {
|
|
|
|
p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class TextureDomainView : public Sample {
|
2011-05-17 15:47:10 +00:00
|
|
|
SkBitmap fBM;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TextureDomainView(){
|
|
|
|
fBM = make_bitmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
virtual bool onQuery(Sample::Event* evt) {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "Texture Domain");
|
2011-05-17 15:47:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2014-02-05 15:32:21 +00:00
|
|
|
SkRect srcRect;
|
2011-05-17 15:47:10 +00:00
|
|
|
SkRect dstRect;
|
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
2011-06-02 20:30:02 +00:00
|
|
|
|
|
|
|
// Test that bitmap draws from malloc-backed bitmaps respect
|
|
|
|
// the constrained texture domain.
|
|
|
|
srcRect.setXYWH(1, 1, 3, 3);
|
2014-02-05 15:32:21 +00:00
|
|
|
dstRect.setXYWH(5, 5, 305, 305);
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->drawBitmapRect(fBM, srcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
|
2011-06-02 20:30:02 +00:00
|
|
|
|
|
|
|
// Test that bitmap draws across separate devices also respect
|
|
|
|
// the constrainted texture domain.
|
|
|
|
// Note: GPU-backed bitmaps follow a different rendering path
|
|
|
|
// when copying from one GPU device to another.
|
2014-02-05 15:32:21 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(canvas->makeSurface(info));
|
2011-06-02 20:30:02 +00:00
|
|
|
|
|
|
|
srcRect.setXYWH(1, 1, 3, 3);
|
2014-02-05 15:32:21 +00:00
|
|
|
dstRect.setXYWH(1, 1, 3, 3);
|
2015-08-06 17:02:53 +00:00
|
|
|
surface->getCanvas()->drawBitmapRect(fBM, srcRect, dstRect, &paint,
|
2015-07-17 14:09:43 +00:00
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
2011-06-02 20:30:02 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
2011-06-02 20:30:02 +00:00
|
|
|
|
|
|
|
srcRect.setXYWH(1, 1, 3, 3);
|
2014-02-05 15:32:21 +00:00
|
|
|
dstRect.setXYWH(405, 5, 305, 305);
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->drawImageRect(image, srcRect, dstRect, &paint);
|
2011-06-27 20:48:23 +00:00
|
|
|
|
|
|
|
// Test that bitmap blurring using a subrect
|
2012-08-23 18:19:56 +00:00
|
|
|
// renders correctly
|
2011-06-27 20:48:23 +00:00
|
|
|
srcRect.setXYWH(1, 1, 3, 3);
|
2014-02-05 15:32:21 +00:00
|
|
|
dstRect.setXYWH(5, 405, 305, 305);
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(
|
|
|
|
kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)), false));
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->drawImageRect(image, srcRect, dstRect, &paint);
|
2011-06-27 20:48:23 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
// Blur and a rotation + nullptr src rect
|
2011-06-27 20:48:23 +00:00
|
|
|
// This should not trigger the texture domain code
|
|
|
|
// but it will test a code path in SkGpuDevice::drawBitmap
|
|
|
|
// that handles blurs with rects transformed to non-
|
2015-08-27 14:41:13 +00:00
|
|
|
// orthogonal rects. It also tests the nullptr src rect handling
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(5)));
|
2011-07-28 20:10:09 +00:00
|
|
|
|
2014-02-05 15:32:21 +00:00
|
|
|
dstRect.setXYWH(-150, -150, 300, 300);
|
2011-06-27 20:48:23 +00:00
|
|
|
canvas->translate(550, 550);
|
|
|
|
canvas->rotate(45);
|
2015-07-17 14:09:43 +00:00
|
|
|
canvas->drawBitmapRect(fBM, dstRect, &paint);
|
2011-05-17 15:47:10 +00:00
|
|
|
}
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-05-17 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new TextureDomainView(); )
|