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.
|
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2018-01-23 16:24:08 +00:00
|
|
|
#include "SkBitmap.h"
|
2011-07-27 18:21:37 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkCornerPathEffect.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2011-07-27 18:21:37 +00:00
|
|
|
|
|
|
|
static void create_bitmap(SkBitmap* bitmap) {
|
|
|
|
const int W = 100;
|
|
|
|
const int H = 100;
|
2014-02-17 02:55:57 +00:00
|
|
|
bitmap->allocN32Pixels(W, H);
|
2011-07-27 18:21:37 +00:00
|
|
|
|
|
|
|
SkCanvas canvas(*bitmap);
|
|
|
|
canvas.drawColor(SK_ColorRED);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class WritePixelsView : public Sample {
|
2011-07-27 18:21:37 +00:00
|
|
|
SkPath fPath;
|
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
WritePixelsView() {}
|
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
virtual bool onQuery(Sample::Event* evt) {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "WritePixels");
|
2011-07-27 18:21:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
create_bitmap(&bitmap);
|
|
|
|
int x = bitmap.width() / 2;
|
|
|
|
int y = bitmap.height() / 2;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
SkBitmap subset;
|
|
|
|
bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
|
|
|
|
canvas->writePixels(bitmap, 0, 0);
|
|
|
|
canvas->writePixels(subset, 0, 0);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-07-27 18:21:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new WritePixelsView(); )
|