Empty picture shaders should draw nothing.
BUG=skia: Review URL: https://codereview.chromium.org/1142053004
This commit is contained in:
parent
7be0ce0ab1
commit
cfa90a1aaf
@ -114,10 +114,10 @@ SkPictureShader::~SkPictureShader() {
|
||||
fPicture->unref();
|
||||
}
|
||||
|
||||
SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy,
|
||||
SkShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy,
|
||||
const SkMatrix* localMatrix, const SkRect* tile) {
|
||||
if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) {
|
||||
return NULL;
|
||||
return SkShader::CreateEmptyShader();
|
||||
}
|
||||
return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile));
|
||||
}
|
||||
@ -185,7 +185,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
|
||||
|
||||
SkISize tileSize = scaledSize.toRound();
|
||||
if (tileSize.isEmpty()) {
|
||||
return NULL;
|
||||
return SkShader::CreateEmptyShader();
|
||||
}
|
||||
|
||||
// The actual scale, compensating for rounding & clamping.
|
||||
@ -204,7 +204,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
|
||||
SkBitmap bm;
|
||||
bm.setInfo(SkImageInfo::MakeN32Premul(tileSize));
|
||||
if (!cache_try_alloc_pixels(&bm)) {
|
||||
return NULL;
|
||||
return SkShader::CreateEmptyShader();
|
||||
}
|
||||
bm.eraseColor(SK_ColorTRANSPARENT);
|
||||
|
||||
|
@ -21,7 +21,7 @@ class SkPicture;
|
||||
*/
|
||||
class SkPictureShader : public SkShader {
|
||||
public:
|
||||
static SkPictureShader* Create(const SkPicture*, TileMode, TileMode, const SkMatrix*,
|
||||
static SkShader* Create(const SkPicture*, TileMode, TileMode, const SkMatrix*,
|
||||
const SkRect*);
|
||||
virtual ~SkPictureShader();
|
||||
|
||||
|
@ -5,22 +5,38 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
#include "SkShader.h"
|
||||
#include "Test.h"
|
||||
|
||||
// Test that attempting to create a picture shader with a NULL picture or
|
||||
// empty picture returns NULL.
|
||||
// empty picture returns a shader that draws nothing.
|
||||
DEF_TEST(PictureShader_empty, reporter) {
|
||||
SkShader* shader = SkShader::CreatePictureShader(NULL,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NULL);
|
||||
REPORTER_ASSERT(reporter, NULL == shader);
|
||||
SkPaint paint;
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocN32Pixels(1,1);
|
||||
|
||||
SkCanvas canvas(bitmap);
|
||||
canvas.clear(SK_ColorGREEN);
|
||||
|
||||
SkShader* shader = SkShader::CreatePictureShader(
|
||||
NULL, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NULL);
|
||||
paint.setShader(shader)->unref();
|
||||
|
||||
canvas.drawRect(SkRect::MakeWH(1,1), paint);
|
||||
REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
|
||||
|
||||
|
||||
SkPictureRecorder factory;
|
||||
factory.beginRecording(0, 0, NULL, 0);
|
||||
SkAutoTUnref<SkPicture> picture(factory.endRecording());
|
||||
shader = SkShader::CreatePictureShader(picture.get(),
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NULL);
|
||||
REPORTER_ASSERT(reporter, NULL == shader);
|
||||
shader = SkShader::CreatePictureShader(
|
||||
picture.get(), SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, NULL, NULL);
|
||||
paint.setShader(shader)->unref();
|
||||
|
||||
canvas.drawRect(SkRect::MakeWH(1,1), paint);
|
||||
REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user