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
|
|
|
|
2011-05-17 15:47:10 +00:00
|
|
|
#include "SampleCode.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bm.unlockPixels();
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TextureDomainView : public SampleView {
|
|
|
|
SkBitmap fBM;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TextureDomainView(){
|
|
|
|
fBM = make_bitmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
2011-07-28 20:10:09 +00:00
|
|
|
SampleCode::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);
|
|
|
|
canvas->drawBitmapRectToRect(fBM, &srcRect, dstRect, &paint);
|
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);
|
|
|
|
SkAutoTUnref<SkSurface> surface(canvas->newSurface(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);
|
|
|
|
surface->getCanvas()->drawBitmapRectToRect(fBM, &srcRect, dstRect,
|
|
|
|
&paint);
|
2011-06-02 20:30:02 +00:00
|
|
|
|
2014-02-05 15:32:21 +00:00
|
|
|
SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
|
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);
|
2014-09-24 20:03:30 +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);
|
2011-06-27 20:48:23 +00:00
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
|
2011-07-28 20:10:09 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag |
|
|
|
|
SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
|
2011-06-27 20:48:23 +00:00
|
|
|
paint.setMaskFilter(mf)->unref();
|
2014-09-24 20:03:30 +00:00
|
|
|
canvas->drawImageRect(image, &srcRect, dstRect, &paint);
|
2011-06-27 20:48:23 +00:00
|
|
|
|
2011-07-01 21:12:20 +00:00
|
|
|
// Blur and a rotation + NULL 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-
|
|
|
|
// orthogonal rects. It also tests the NULL src rect handling
|
2014-04-28 16:25:35 +00:00
|
|
|
mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
|
2014-02-05 15:32:21 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(5),
|
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
2011-07-28 20:10:09 +00:00
|
|
|
paint.setMaskFilter(mf)->unref();
|
|
|
|
|
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);
|
2014-02-05 15:32:21 +00:00
|
|
|
canvas->drawBitmapRectToRect(fBM, NULL, dstRect, &paint);
|
2011-05-17 15:47:10 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef SkView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new TextureDomainView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|