2012-08-07 14:05:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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"
|
|
|
|
#include "SkCanvas.h"
|
2013-10-24 17:52:07 +00:00
|
|
|
#include "SkGradientShader.h"
|
2012-08-07 14:05:14 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) {
|
2012-08-07 14:05:14 +00:00
|
|
|
bm->setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
|
|
|
bm->allocPixels();
|
2013-10-24 17:52:07 +00:00
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2};
|
|
|
|
SkScalar radius = 40;
|
|
|
|
SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, NULL, 2,
|
|
|
|
SkShader::kMirror_TileMode);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(shader)->unref();
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
|
|
|
canvas.drawPaint(paint);
|
2012-08-07 14:05:14 +00:00
|
|
|
bm->setImmutable();
|
|
|
|
}
|
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
|
2012-08-07 14:05:14 +00:00
|
|
|
SkBitmap bm;
|
2013-10-24 17:52:07 +00:00
|
|
|
make_bm(&bm, width, height, colors);
|
2012-08-07 14:05:14 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect r;
|
|
|
|
SkIRect ir;
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
ir.set(0, 0, 128, 128);
|
|
|
|
r.set(ir);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(r);
|
|
|
|
canvas->drawBitmap(bm, 0, 0, NULL);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
r.offset(SkIntToScalar(150), 0);
|
|
|
|
// exercises extract bitmap, but not shader
|
|
|
|
canvas->drawBitmapRect(bm, &ir, r, NULL);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
r.offset(SkIntToScalar(150), 0);
|
|
|
|
// exercises bitmapshader
|
|
|
|
canvas->drawBitmapRect(bm, NULL, r, NULL);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
class VeryLargeBitmapGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
VeryLargeBitmapGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
|
|
|
return SkString("verylargebitmap");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2013-10-24 17:52:07 +00:00
|
|
|
return SkISize::Make(500, 600);
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2013-07-15 15:48:48 +00:00
|
|
|
int veryBig = 70*1024; // 64K < size
|
2013-10-24 17:52:07 +00:00
|
|
|
int big = 60*1024; // 32K < size < 64K
|
|
|
|
// smaller than many max texture sizes, but large enough to gpu-tile for memory reasons.
|
|
|
|
int medium = 7*1024;
|
2013-07-15 15:48:48 +00:00
|
|
|
int small = 150;
|
2012-08-07 14:05:14 +00:00
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
SkColor colors[2];
|
|
|
|
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
|
2013-10-24 17:52:07 +00:00
|
|
|
colors[0] = SK_ColorRED;
|
|
|
|
colors[1] = SK_ColorGREEN;
|
|
|
|
show_bm(canvas, small, small, colors);
|
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
|
|
|
|
colors[0] = SK_ColorBLUE;
|
|
|
|
colors[1] = SK_ColorMAGENTA;
|
|
|
|
show_bm(canvas, big, small, colors);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
colors[0] = SK_ColorMAGENTA;
|
|
|
|
colors[1] = SK_ColorYELLOW;
|
|
|
|
// as of this writing, the raster code will fail to draw the scaled version
|
|
|
|
// since it has a 64K limit on x,y coordinates... (but gpu should succeed)
|
|
|
|
show_bm(canvas, medium, medium, colors);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
colors[0] = SK_ColorGREEN;
|
|
|
|
colors[1] = SK_ColorYELLOW;
|
2012-08-07 14:05:14 +00:00
|
|
|
// as of this writing, the raster code will fail to draw the scaled version
|
|
|
|
// since it has a 64K limit on x,y coordinates... (but gpu should succeed)
|
2013-10-24 17:52:07 +00:00
|
|
|
show_bm(canvas, veryBig, small, colors);
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-07 14:46:05 +00:00
|
|
|
// This GM allocates more memory than Android devices are capable of fulfilling.
|
|
|
|
#ifndef SK_BUILD_FOR_ANDROID
|
2012-08-07 14:05:14 +00:00
|
|
|
static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
|
|
|
|
static skiagm::GMRegistry reg(MyFactory);
|
2012-08-07 14:46:05 +00:00
|
|
|
#endif
|