2013-07-25 21:34:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2013-08-20 16:51:20 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-10-23 18:13:01 +00:00
|
|
|
#include "SkGradientShader.h"
|
2015-07-14 17:54:12 +00:00
|
|
|
#include "SkImage.h"
|
2015-11-02 20:33:21 +00:00
|
|
|
#include "SkUtils.h"
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
2015-05-27 20:23:23 +00:00
|
|
|
#include "GrContextOptions.h"
|
2015-11-02 20:33:21 +00:00
|
|
|
#include "SkGr.h"
|
2013-07-25 21:34:00 +00:00
|
|
|
#endif
|
|
|
|
|
2015-07-14 17:54:12 +00:00
|
|
|
static void draw_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkImage*,
|
2015-08-06 17:02:53 +00:00
|
|
|
const SkRect& src, const SkRect& dst,
|
2015-07-14 17:54:12 +00:00
|
|
|
const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
|
|
|
|
canvas->drawBitmapRect(bitmap, src, dst, paint, constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_image_rect(SkCanvas* canvas, const SkBitmap&, const SkImage* image,
|
2015-08-06 17:02:53 +00:00
|
|
|
const SkRect& src, const SkRect& dst,
|
2015-07-14 17:54:12 +00:00
|
|
|
const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
|
|
|
|
canvas->drawImageRect(image, src, dst, paint, constraint);
|
|
|
|
}
|
|
|
|
|
2015-11-02 20:33:21 +00:00
|
|
|
// Upload the tight-fitting sw-backed bitmap to a loose-fitting gpu-backed texture before drawing
|
|
|
|
static void draw_texture_bitmap_rect(SkCanvas* canvas, const SkBitmap& bitmap, const SkImage*,
|
|
|
|
const SkRect& src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
|
|
|
SkCanvas::SrcRectConstraint constraint) {
|
|
|
|
GrContext* context = canvas->getGrContext();
|
|
|
|
if (!context) {
|
|
|
|
// For non-GPU canvases fallback to drawing the bitmap directly.
|
|
|
|
canvas->drawBitmapRect(bitmap, src, dst, paint, constraint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fConfig = kAlpha_8_SkColorType == bitmap.colorType() ? kAlpha_8_GrPixelConfig :
|
|
|
|
kSkia8888_GrPixelConfig;
|
|
|
|
// Add some padding to the right and beneath the bitmap contents to exercise the case where
|
|
|
|
// the texture is larger than the bitmap. Outsets chosen to be small and different.
|
|
|
|
desc.fWidth = bitmap.width() + 16;
|
|
|
|
desc.fHeight = bitmap.height() + 23;
|
|
|
|
SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, true));
|
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Init the whole texture to 0 in the alpha case or solid green in the 32bit rgba case.
|
|
|
|
SkAutoLockPixels al(bitmap);
|
|
|
|
if (kAlpha_8_GrPixelConfig == texture->config()) {
|
|
|
|
SkAutoMalloc pixels(texture->width() * texture->height());
|
|
|
|
memset(pixels.get(), 0, texture->width() * texture->height());
|
2015-11-04 12:36:12 +00:00
|
|
|
texture->writePixels(0, 0, texture->width(), texture->height(), desc.fConfig, pixels.get(),
|
|
|
|
0);
|
2015-11-02 20:33:21 +00:00
|
|
|
} else {
|
|
|
|
SkAutoMalloc pixels(texture->width() * texture->height() * sizeof(uint32_t));
|
|
|
|
SkOpts::memset32((uint32_t*)pixels.get(), 0xFF00FF00, texture->width()*texture->height());
|
2015-11-04 12:36:12 +00:00
|
|
|
texture->writePixels(0, 0, texture->width(), texture->height(), desc.fConfig, pixels.get(),
|
|
|
|
0);
|
2015-11-02 20:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Upload the bitmap contents to the upper left.
|
|
|
|
texture->writePixels(0, 0, bitmap.width(), bitmap.height(), desc.fConfig, bitmap.getPixels(),
|
|
|
|
bitmap.rowBytes());
|
|
|
|
|
|
|
|
// Wrap the texture in a bitmap and draw it.
|
|
|
|
SkBitmap textureBmp;
|
|
|
|
GrWrapTextureInBitmap(texture, bitmap.width(), bitmap.height(), true, &textureBmp);
|
|
|
|
canvas->drawBitmapRect(textureBmp, src, dst, paint, constraint);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:09:22 +00:00
|
|
|
// Create a black&white checked texture with 2 1-pixel rings
|
|
|
|
// around the outside edge. The inner ring is red and the outer ring is blue.
|
2015-10-23 18:13:01 +00:00
|
|
|
static void make_ringed_color_bitmap(SkBitmap* result, int width, int height) {
|
2013-11-08 15:09:22 +00:00
|
|
|
SkASSERT(0 == width % 2 && 0 == height % 2);
|
2013-11-09 07:02:23 +00:00
|
|
|
|
2013-11-08 15:09:22 +00:00
|
|
|
static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
|
|
|
|
static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE);
|
|
|
|
static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK);
|
|
|
|
static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2014-01-25 16:46:20 +00:00
|
|
|
result->allocN32Pixels(width, height, true);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2013-07-26 07:00:58 +00:00
|
|
|
SkPMColor* scanline = result->getAddr32(0, 0);
|
2013-07-25 21:34:00 +00:00
|
|
|
for (int x = 0; x < width; ++x) {
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[x] = kBlue;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline = result->getAddr32(0, 1);
|
|
|
|
scanline[0] = kBlue;
|
|
|
|
for (int x = 1; x < width - 1; ++x) {
|
|
|
|
scanline[x] = kRed;
|
|
|
|
}
|
|
|
|
scanline[width-1] = kBlue;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2013-11-08 15:09:22 +00:00
|
|
|
for (int y = 2; y < height/2; ++y) {
|
2013-07-25 21:34:00 +00:00
|
|
|
scanline = result->getAddr32(0, y);
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[0] = kBlue;
|
|
|
|
scanline[1] = kRed;
|
|
|
|
for (int x = 2; x < width/2; ++x) {
|
|
|
|
scanline[x] = kBlack;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2013-11-08 15:09:22 +00:00
|
|
|
for (int x = width/2; x < width-2; ++x) {
|
|
|
|
scanline[x] = kWhite;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[width-2] = kRed;
|
|
|
|
scanline[width-1] = kBlue;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 15:09:22 +00:00
|
|
|
for (int y = height/2; y < height-2; ++y) {
|
2013-07-25 21:34:00 +00:00
|
|
|
scanline = result->getAddr32(0, y);
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[0] = kBlue;
|
|
|
|
scanline[1] = kRed;
|
|
|
|
for (int x = 2; x < width/2; ++x) {
|
|
|
|
scanline[x] = kWhite;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2013-11-08 15:09:22 +00:00
|
|
|
for (int x = width/2; x < width-2; ++x) {
|
|
|
|
scanline[x] = kBlack;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[width-2] = kRed;
|
|
|
|
scanline[width-1] = kBlue;
|
|
|
|
}
|
|
|
|
|
|
|
|
scanline = result->getAddr32(0, height-2);
|
|
|
|
scanline[0] = kBlue;
|
|
|
|
for (int x = 1; x < width - 1; ++x) {
|
|
|
|
scanline[x] = kRed;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[width-1] = kBlue;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
scanline = result->getAddr32(0, height-1);
|
|
|
|
for (int x = 0; x < width; ++x) {
|
2013-11-08 15:09:22 +00:00
|
|
|
scanline[x] = kBlue;
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
result->setImmutable();
|
|
|
|
}
|
|
|
|
|
2015-11-04 12:23:45 +00:00
|
|
|
/** Makes a alpha bitmap with 1 wide rect/ring of 0s, an inset of 1s, and the interior is a 2x2
|
2015-10-23 18:13:01 +00:00
|
|
|
checker board of 3/4 and 1/2. The inner checkers are large enough to fill the interior with
|
|
|
|
the 2x2 checker grid. */
|
|
|
|
static void make_ringed_alpha_bitmap(SkBitmap* result, int width, int height) {
|
|
|
|
SkASSERT(0 == width % 2 && 0 == height % 2);
|
|
|
|
|
|
|
|
static const SkPMColor kZero = 0x00;
|
|
|
|
static const SkPMColor kHalf = 0x80;
|
|
|
|
static const SkPMColor k3Q = 0xC0;
|
|
|
|
static const SkPMColor kOne = 0xFF;
|
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(width, height);
|
|
|
|
// The 4 byte alignment seems to be necessary to allow this bmp to be converted
|
|
|
|
// to an image.
|
|
|
|
result->allocPixels(info, SkAlign4(width));
|
|
|
|
|
|
|
|
uint8_t* scanline = result->getAddr8(0, 0);
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
scanline[x] = kOne;
|
|
|
|
}
|
|
|
|
scanline = result->getAddr8(0, 1);
|
|
|
|
scanline[0] = kOne;
|
|
|
|
for (int x = 1; x < width - 1; ++x) {
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[x] = kOne;
|
2015-10-23 18:13:01 +00:00
|
|
|
}
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[width - 1] = kZero;
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
for (int y = 2; y < height / 2; ++y) {
|
|
|
|
scanline = result->getAddr8(0, y);
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[0] = kZero;
|
|
|
|
scanline[1] = kOne;
|
2015-10-23 18:13:01 +00:00
|
|
|
for (int x = 2; x < width / 2; ++x) {
|
|
|
|
scanline[x] = k3Q;
|
|
|
|
}
|
|
|
|
for (int x = width / 2; x < width - 2; ++x) {
|
|
|
|
scanline[x] = kHalf;
|
|
|
|
}
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[width - 2] = kOne;
|
|
|
|
scanline[width - 1] = kZero;
|
2015-10-23 18:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = height / 2; y < height - 2; ++y) {
|
|
|
|
scanline = result->getAddr8(0, y);
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[0] = kZero;
|
|
|
|
scanline[1] = kOne;
|
2015-10-23 18:13:01 +00:00
|
|
|
for (int x = 2; x < width / 2; ++x) {
|
|
|
|
scanline[x] = kHalf;
|
|
|
|
}
|
|
|
|
for (int x = width / 2; x < width - 2; ++x) {
|
|
|
|
scanline[x] = k3Q;
|
|
|
|
}
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[width - 2] = kOne;
|
|
|
|
scanline[width - 1] = kZero;
|
2015-10-23 18:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scanline = result->getAddr8(0, height - 2);
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[0] = kZero;
|
2015-10-23 18:13:01 +00:00
|
|
|
for (int x = 1; x < width - 1; ++x) {
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[x] = kOne;
|
2015-10-23 18:13:01 +00:00
|
|
|
}
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[width - 1] = kZero;
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
scanline = result->getAddr8(0, height - 1);
|
|
|
|
for (int x = 0; x < width; ++x) {
|
2015-11-04 12:23:45 +00:00
|
|
|
scanline[x] = kZero;
|
2015-10-23 18:13:01 +00:00
|
|
|
}
|
|
|
|
result->setImmutable();
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkShader* make_shader() {
|
|
|
|
static const SkPoint pts[] = { {0, 0}, {20, 20} };
|
|
|
|
static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW };
|
|
|
|
return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMirror_TileMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkShader* make_null_shader() { return nullptr; }
|
|
|
|
|
|
|
|
enum BleedTest {
|
|
|
|
kUseBitmap_BleedTest,
|
2015-11-02 20:33:21 +00:00
|
|
|
kUseTextureBitmap_BleedTest,
|
2015-10-23 18:13:01 +00:00
|
|
|
kUseImage_BleedTest,
|
|
|
|
kUseAlphaBitmap_BleedTest,
|
2015-11-02 20:33:21 +00:00
|
|
|
kUseAlphaTextureBitmap_BleedTest,
|
2015-10-23 18:13:01 +00:00
|
|
|
kUseAlphaImage_BleedTest,
|
|
|
|
kUseAlphaBitmapShader_BleedTest,
|
2015-11-02 20:33:21 +00:00
|
|
|
kUseAlphaTextureBitmapShader_BleedTest,
|
2015-10-23 18:13:01 +00:00
|
|
|
kUseAlphaImageShader_BleedTest,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
const char* fName;
|
|
|
|
void(*fBmpMaker)(SkBitmap* result, int width, int height);
|
|
|
|
SkShader*(*fShaderMaker)();
|
|
|
|
void(*fDraw)(SkCanvas*, const SkBitmap&, const SkImage*, const SkRect&, const SkRect&,
|
|
|
|
const SkPaint*, SkCanvas::SrcRectConstraint);
|
|
|
|
} gBleedRec[] = {
|
2015-11-02 20:33:21 +00:00
|
|
|
{ "bleed", make_ringed_color_bitmap, make_null_shader, draw_bitmap_rect },
|
|
|
|
{ "bleed_texture_bmp", make_ringed_color_bitmap, make_null_shader, draw_texture_bitmap_rect },
|
|
|
|
{ "bleed_image", make_ringed_color_bitmap, make_null_shader, draw_image_rect },
|
|
|
|
{ "bleed_alpha_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_bitmap_rect },
|
|
|
|
{ "bleed_alpha_texture_bmp", make_ringed_alpha_bitmap, make_null_shader, draw_texture_bitmap_rect },
|
|
|
|
{ "bleed_alpha_image", make_ringed_alpha_bitmap, make_null_shader, draw_image_rect },
|
|
|
|
{ "bleed_alpha_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_bitmap_rect },
|
|
|
|
{ "bleed_alpha_texture_bmp_shader", make_ringed_alpha_bitmap, make_shader, draw_texture_bitmap_rect },
|
|
|
|
{ "bleed_alpha_image_shader", make_ringed_alpha_bitmap, make_shader, draw_image_rect },
|
2015-10-23 18:13:01 +00:00
|
|
|
};
|
|
|
|
|
2015-07-14 17:54:12 +00:00
|
|
|
// This GM exercises the drawBitmapRect constraints
|
2013-07-25 21:34:00 +00:00
|
|
|
class BleedGM : public skiagm::GM {
|
|
|
|
public:
|
2015-07-14 17:54:12 +00:00
|
|
|
BleedGM(BleedTest bt) : fBT(bt) {}
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2015-07-14 17:54:12 +00:00
|
|
|
return SkString(gBleedRec[fBT].fName);
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2015-11-04 12:36:12 +00:00
|
|
|
return SkISize::Make(1200, 1080);
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2015-10-23 18:13:01 +00:00
|
|
|
gBleedRec[fBT].fBmpMaker(&fBitmapSmall, kSmallTextureSize, kSmallTextureSize);
|
2015-07-14 17:54:12 +00:00
|
|
|
fImageSmall.reset(SkImage::NewFromBitmap(fBitmapSmall));
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
// To exercise the GPU's tiling path we need a texture
|
|
|
|
// too big for the GPU to handle in one go
|
2015-11-02 19:36:52 +00:00
|
|
|
gBleedRec[fBT].fBmpMaker(&fBitmapBig, 2*kMaxTileSize, 2*kMaxTileSize);
|
2015-07-14 17:54:12 +00:00
|
|
|
fImageBig.reset(SkImage::NewFromBitmap(fBitmapBig));
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
fShader.reset(gBleedRec[fBT].fShaderMaker());
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2013-08-20 12:09:32 +00:00
|
|
|
// Draw only the center of the small bitmap
|
2015-10-23 18:13:01 +00:00
|
|
|
void drawCase1(SkCanvas* canvas, int transX, int transY, bool aa,
|
2015-07-14 17:54:12 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
|
2013-11-08 15:09:22 +00:00
|
|
|
SkRect src = SkRect::MakeXYWH(2, 2,
|
2013-11-22 20:34:59 +00:00
|
|
|
SkIntToScalar(kSmallTextureSize-4),
|
|
|
|
SkIntToScalar(kSmallTextureSize-4));
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-07-26 07:00:58 +00:00
|
|
|
|
2013-08-20 12:09:32 +00:00
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(filter);
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setShader(fShader);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-08-20 12:09:32 +00:00
|
|
|
|
2015-08-06 17:02:53 +00:00
|
|
|
gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint, constraint);
|
2013-08-20 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw almost all of the large bitmap
|
2015-10-23 18:13:01 +00:00
|
|
|
void drawCase2(SkCanvas* canvas, int transX, int transY, bool aa,
|
2015-07-14 17:54:12 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
|
2013-11-08 15:09:22 +00:00
|
|
|
SkRect src = SkRect::MakeXYWH(2, 2,
|
|
|
|
SkIntToScalar(fBitmapBig.width()-4),
|
|
|
|
SkIntToScalar(fBitmapBig.height()-4));
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(filter);
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setShader(fShader);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2015-08-06 17:02:53 +00:00
|
|
|
gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, constraint);
|
2013-08-20 12:09:32 +00:00
|
|
|
}
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2013-08-20 12:09:32 +00:00
|
|
|
// Draw ~1/4 of the large bitmap
|
2015-10-23 18:13:01 +00:00
|
|
|
void drawCase3(SkCanvas* canvas, int transX, int transY, bool aa,
|
2015-07-14 17:54:12 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
|
2013-11-08 15:09:22 +00:00
|
|
|
SkRect src = SkRect::MakeXYWH(2, 2,
|
|
|
|
SkIntToScalar(fBitmapBig.width()/2-2),
|
|
|
|
SkIntToScalar(fBitmapBig.height()/2-2));
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2013-08-20 12:09:32 +00:00
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(filter);
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setShader(fShader);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2015-08-06 17:02:53 +00:00
|
|
|
gBleedRec[fBT].fDraw(canvas, fBitmapBig, fImageBig, src, dst, &paint, constraint);
|
2013-08-20 12:09:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-04 12:36:12 +00:00
|
|
|
// Draw the center of the small bitmap with a normal blur
|
2015-10-23 18:13:01 +00:00
|
|
|
void drawCase4(SkCanvas* canvas, int transX, int transY, bool aa,
|
2015-07-14 17:54:12 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
|
2013-11-08 15:09:22 +00:00
|
|
|
SkRect src = SkRect::MakeXYWH(2, 2,
|
2013-11-22 20:34:59 +00:00
|
|
|
SkIntToScalar(kSmallTextureSize-4),
|
|
|
|
SkIntToScalar(kSmallTextureSize-4));
|
2015-07-14 17:54:12 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
2013-08-20 16:51:20 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(filter);
|
2014-04-28 16:25:35 +00:00
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
|
2015-07-14 17:54:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(3));
|
2013-08-20 16:51:20 +00:00
|
|
|
paint.setMaskFilter(mf)->unref();
|
2015-10-23 18:13:01 +00:00
|
|
|
paint.setShader(fShader);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
2013-08-20 16:51:20 +00:00
|
|
|
|
2015-08-06 17:02:53 +00:00
|
|
|
gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint, constraint);
|
2013-08-20 16:51:20 +00:00
|
|
|
}
|
|
|
|
|
2015-11-04 12:36:12 +00:00
|
|
|
// Draw the center of the small bitmap with a outer blur
|
|
|
|
void drawCase5(SkCanvas* canvas, int transX, int transY, bool aa,
|
|
|
|
SkCanvas::SrcRectConstraint constraint, SkFilterQuality filter) {
|
|
|
|
SkRect src = SkRect::MakeXYWH(2, 2,
|
|
|
|
SkIntToScalar(kSmallTextureSize - 4),
|
|
|
|
SkIntToScalar(kSmallTextureSize - 4));
|
|
|
|
SkRect dst = SkRect::MakeXYWH(SkIntToScalar(transX), SkIntToScalar(transY),
|
|
|
|
SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(filter);
|
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(kOuter_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(7));
|
|
|
|
paint.setMaskFilter(mf)->unref();
|
|
|
|
paint.setShader(fShader);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setAntiAlias(aa);
|
|
|
|
|
|
|
|
gBleedRec[fBT].fDraw(canvas, fBitmapSmall, fImageSmall, src, dst, &paint, constraint);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-08-20 12:09:32 +00:00
|
|
|
canvas->clear(SK_ColorGRAY);
|
2015-10-23 18:13:01 +00:00
|
|
|
SkTDArray<SkMatrix> matrices;
|
|
|
|
// Draw with identity
|
|
|
|
*matrices.append() = SkMatrix::I();
|
|
|
|
|
|
|
|
// Draw with rotation and scale down in x, up in y.
|
|
|
|
SkMatrix m;
|
2015-11-04 12:36:12 +00:00
|
|
|
static const SkScalar kBottom = SkIntToScalar(kRow4Y + kBlockSize + kBlockSpacing);
|
2015-10-23 18:13:01 +00:00
|
|
|
m.setTranslate(0, kBottom);
|
|
|
|
m.preRotate(15.f, 0, kBottom + kBlockSpacing);
|
|
|
|
m.preScale(0.71f, 1.22f);
|
|
|
|
*matrices.append() = m;
|
|
|
|
|
|
|
|
// Align the next set with the middle of the previous in y, translated to the right in x.
|
|
|
|
SkPoint corners[] = {{0, 0}, { 0, kBottom }, { kWidth, kBottom }, {kWidth, 0} };
|
|
|
|
matrices[matrices.count()-1].mapPoints(corners, 4);
|
|
|
|
SkScalar y = (corners[0].fY + corners[1].fY + corners[2].fY + corners[3].fY) / 4;
|
|
|
|
SkScalar x = SkTMax(SkTMax(corners[0].fX, corners[1].fX),
|
|
|
|
SkTMax(corners[2].fX, corners[3].fX));
|
|
|
|
m.setTranslate(x, y);
|
|
|
|
m.preScale(0.2f, 0.2f);
|
|
|
|
*matrices.append() = m;
|
|
|
|
|
|
|
|
SkScalar maxX = 0;
|
|
|
|
for (int antiAlias = 0; antiAlias < 2; ++antiAlias) {
|
2013-11-22 20:34:59 +00:00
|
|
|
canvas->save();
|
2015-10-23 18:13:01 +00:00
|
|
|
canvas->translate(maxX, 0);
|
|
|
|
for (int m = 0; m < matrices.count(); ++m) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->concat(matrices[m]);
|
|
|
|
bool aa = SkToBool(antiAlias);
|
|
|
|
|
|
|
|
// First draw a column with no bleeding and no filtering
|
|
|
|
this->drawCase1(canvas, kCol0X, kRow0Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
|
|
|
|
this->drawCase2(canvas, kCol0X, kRow1Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
|
|
|
|
this->drawCase3(canvas, kCol0X, kRow2Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
|
|
|
|
this->drawCase4(canvas, kCol0X, kRow3Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
|
2015-11-04 12:36:12 +00:00
|
|
|
this->drawCase5(canvas, kCol0X, kRow4Y, aa, SkCanvas::kStrict_SrcRectConstraint, kNone_SkFilterQuality);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Then draw a column with no bleeding and low filtering
|
|
|
|
this->drawCase1(canvas, kCol1X, kRow0Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
|
|
|
|
this->drawCase2(canvas, kCol1X, kRow1Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
|
|
|
|
this->drawCase3(canvas, kCol1X, kRow2Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
|
|
|
|
this->drawCase4(canvas, kCol1X, kRow3Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
|
2015-11-04 12:36:12 +00:00
|
|
|
this->drawCase5(canvas, kCol1X, kRow4Y, aa, SkCanvas::kStrict_SrcRectConstraint, kLow_SkFilterQuality);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Then draw a column with no bleeding and high filtering
|
|
|
|
this->drawCase1(canvas, kCol2X, kRow0Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
|
|
|
|
this->drawCase2(canvas, kCol2X, kRow1Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
|
|
|
|
this->drawCase3(canvas, kCol2X, kRow2Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
|
|
|
|
this->drawCase4(canvas, kCol2X, kRow3Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
|
2015-11-04 12:36:12 +00:00
|
|
|
this->drawCase5(canvas, kCol2X, kRow4Y, aa, SkCanvas::kStrict_SrcRectConstraint, kHigh_SkFilterQuality);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Then draw a column with bleeding and no filtering (bleed should have no effect w/out blur)
|
|
|
|
this->drawCase1(canvas, kCol3X, kRow0Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
|
|
|
|
this->drawCase2(canvas, kCol3X, kRow1Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
|
|
|
|
this->drawCase3(canvas, kCol3X, kRow2Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
|
|
|
|
this->drawCase4(canvas, kCol3X, kRow3Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
|
2015-11-04 12:36:12 +00:00
|
|
|
this->drawCase5(canvas, kCol3X, kRow4Y, aa, SkCanvas::kFast_SrcRectConstraint, kNone_SkFilterQuality);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Then draw a column with bleeding and low filtering
|
|
|
|
this->drawCase1(canvas, kCol4X, kRow0Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
|
|
|
|
this->drawCase2(canvas, kCol4X, kRow1Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
|
|
|
|
this->drawCase3(canvas, kCol4X, kRow2Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
|
|
|
|
this->drawCase4(canvas, kCol4X, kRow3Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
|
2015-11-04 12:36:12 +00:00
|
|
|
this->drawCase5(canvas, kCol4X, kRow4Y, aa, SkCanvas::kFast_SrcRectConstraint, kLow_SkFilterQuality);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
// Finally draw a column with bleeding and high filtering
|
|
|
|
this->drawCase1(canvas, kCol5X, kRow0Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
|
|
|
|
this->drawCase2(canvas, kCol5X, kRow1Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
|
|
|
|
this->drawCase3(canvas, kCol5X, kRow2Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
|
|
|
|
this->drawCase4(canvas, kCol5X, kRow3Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
|
2015-11-04 12:36:12 +00:00
|
|
|
this->drawCase5(canvas, kCol5X, kRow4Y, aa, SkCanvas::kFast_SrcRectConstraint, kHigh_SkFilterQuality);
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
SkPoint corners[] = { { 0, 0 },{ 0, kBottom },{ kWidth, kBottom },{ kWidth, 0 } };
|
|
|
|
matrices[m].mapPoints(corners, 4);
|
|
|
|
SkScalar x = kBlockSize + SkTMax(SkTMax(corners[0].fX, corners[1].fX),
|
|
|
|
SkTMax(corners[2].fX, corners[3].fX));
|
|
|
|
maxX = SkTMax(maxX, x);
|
|
|
|
canvas->restore();
|
2013-11-22 20:34:59 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2013-07-25 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 20:23:23 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
void modifyGrContextOptions(GrContextOptions* options) override {
|
2015-11-02 19:36:52 +00:00
|
|
|
options->fMaxTileSizeOverride = kMaxTileSize;
|
2015-05-27 20:23:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-25 21:34:00 +00:00
|
|
|
private:
|
2013-11-08 15:09:22 +00:00
|
|
|
static const int kBlockSize = 70;
|
2015-11-04 12:36:12 +00:00
|
|
|
static const int kBlockSpacing = 12;
|
2013-08-20 12:09:32 +00:00
|
|
|
|
|
|
|
static const int kCol0X = kBlockSpacing;
|
|
|
|
static const int kCol1X = 2*kBlockSpacing + kBlockSize;
|
|
|
|
static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize;
|
|
|
|
static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize;
|
2013-11-08 15:09:22 +00:00
|
|
|
static const int kCol4X = 5*kBlockSpacing + 4*kBlockSize;
|
|
|
|
static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize;
|
2015-05-27 20:23:23 +00:00
|
|
|
static const int kWidth = 7*kBlockSpacing + 6*kBlockSize;
|
2013-08-20 12:09:32 +00:00
|
|
|
|
|
|
|
static const int kRow0Y = kBlockSpacing;
|
|
|
|
static const int kRow1Y = 2*kBlockSpacing + kBlockSize;
|
|
|
|
static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize;
|
2013-08-20 16:51:20 +00:00
|
|
|
static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize;
|
2015-11-04 12:36:12 +00:00
|
|
|
static const int kRow4Y = 5*kBlockSpacing + 4*kBlockSize;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
2013-11-08 15:09:22 +00:00
|
|
|
static const int kSmallTextureSize = 6;
|
2015-11-02 19:36:52 +00:00
|
|
|
static const int kMaxTileSize = 32;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
SkBitmap fBitmapSmall;
|
|
|
|
SkBitmap fBitmapBig;
|
2015-07-14 17:54:12 +00:00
|
|
|
SkAutoTUnref<SkImage> fImageSmall;
|
|
|
|
SkAutoTUnref<SkImage> fImageBig;
|
2015-10-23 18:13:01 +00:00
|
|
|
|
|
|
|
SkAutoTUnref<SkShader> fShader;
|
|
|
|
|
2015-07-14 17:54:12 +00:00
|
|
|
const BleedTest fBT;
|
2013-07-25 21:34:00 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-11-02 20:33:21 +00:00
|
|
|
|
2015-07-14 17:54:12 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseBitmap_BleedTest); )
|
2015-11-02 20:33:21 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseTextureBitmap_BleedTest); )
|
2015-07-14 17:54:12 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseImage_BleedTest); )
|
2015-10-23 18:13:01 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseAlphaBitmap_BleedTest); )
|
2015-11-02 20:33:21 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseAlphaTextureBitmap_BleedTest); )
|
2015-10-23 18:13:01 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseAlphaImage_BleedTest); )
|
2015-11-02 20:33:21 +00:00
|
|
|
DEF_GM( return new BleedGM(kUseAlphaBitmapShader_BleedTest); )
|
|
|
|
DEF_GM( return new BleedGM(kUseAlphaTextureBitmapShader_BleedTest); )
|
|
|
|
DEF_GM( return new BleedGM(kUseAlphaImageShader_BleedTest); )
|