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"
|
2011-06-02 20:30:02 +00:00
|
|
|
#include "SkDevice.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;
|
2011-06-02 20:30:02 +00:00
|
|
|
bm.setConfig(SkBitmap::kARGB_8888_Config , 5, 5);
|
2011-05-17 15:47:10 +00:00
|
|
|
bm.allocPixels();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
SkIRect srcRect;
|
|
|
|
SkRect dstRect;
|
|
|
|
SkPaint paint;
|
2013-10-31 17:28:30 +00:00
|
|
|
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
|
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);
|
|
|
|
dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f);
|
2011-05-17 15:47:10 +00:00
|
|
|
canvas->drawBitmapRect(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.
|
2013-08-29 11:54:56 +00:00
|
|
|
SkAutoTUnref<SkBaseDevice> secondDevice(canvas->createCompatibleDevice(
|
2011-06-16 19:10:39 +00:00
|
|
|
SkBitmap::kARGB_8888_Config, 5, 5, true));
|
2011-06-02 20:30:02 +00:00
|
|
|
SkCanvas secondCanvas(secondDevice.get());
|
|
|
|
|
|
|
|
srcRect.setXYWH(1, 1, 3, 3);
|
|
|
|
dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f);
|
|
|
|
secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint);
|
|
|
|
|
|
|
|
SkBitmap deviceBitmap = secondDevice->accessBitmap(false);
|
|
|
|
|
|
|
|
srcRect.setXYWH(1, 1, 3, 3);
|
|
|
|
dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f);
|
|
|
|
canvas->drawBitmapRect(deviceBitmap, &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);
|
|
|
|
dstRect.setXYWH(5.0f, 405.0f, 305.0f, 305.0f);
|
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(
|
|
|
|
SkBlurMaskFilter::kNormal_BlurStyle,
|
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();
|
|
|
|
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
|
|
|
|
|
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
|
2012-08-23 18:19:56 +00:00
|
|
|
mf = SkBlurMaskFilter::Create(
|
2011-07-28 20:10:09 +00:00
|
|
|
SkBlurMaskFilter::kNormal_BlurStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
|
2011-07-28 20:10:09 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
|
|
|
paint.setMaskFilter(mf)->unref();
|
|
|
|
|
2011-06-27 20:48:23 +00:00
|
|
|
dstRect.setXYWH(-150.0f, -150.0f, 300.0f, 300.0f);
|
|
|
|
canvas->translate(550, 550);
|
|
|
|
canvas->rotate(45);
|
|
|
|
canvas->drawBitmapRect(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);
|