2014-08-08 19:11:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-03-18 22:48:49 +00:00
|
|
|
#include "DecodeFile.h"
|
2014-08-08 19:11:33 +00:00
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorPriv.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2014-08-08 19:11:33 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTime.h"
|
2016-12-12 15:02:12 +00:00
|
|
|
#include "SkClipOpPriv.h"
|
2014-08-08 19:11:33 +00:00
|
|
|
|
|
|
|
// Intended to exercise pixel snapping observed with scaled images (and
|
|
|
|
// with non-scaled images, but for a different reason): Bug 1145
|
|
|
|
|
|
|
|
class IdentityScaleView : public SampleView {
|
|
|
|
public:
|
|
|
|
IdentityScaleView(const char imageFilename[]) {
|
|
|
|
SkString resourcePath = GetResourcePath(imageFilename);
|
2016-03-18 22:48:49 +00:00
|
|
|
if (!decode_file(resourcePath.c_str(), &fBM)) {
|
2014-08-08 19:11:33 +00:00
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkBitmap fBM;
|
|
|
|
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2014-08-08 19:11:33 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "IdentityScale");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2014-08-08 19:11:33 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setTextSize(48);
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kHigh_SkFilterQuality);
|
2014-08-08 19:11:33 +00:00
|
|
|
|
|
|
|
SkTime::DateTime time;
|
|
|
|
SkTime::GetDateTime(&time);
|
|
|
|
|
|
|
|
bool use_scale = (time.fSecond % 2 == 1);
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
if (use_scale) {
|
|
|
|
text = "Scaled = 1";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
SkRect r = { 100, 100, 356, 356 };
|
|
|
|
SkPath clipPath;
|
|
|
|
clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5));
|
2016-12-09 14:00:50 +00:00
|
|
|
canvas->clipPath(clipPath, kIntersect_SkClipOp, true);
|
2014-08-08 19:11:33 +00:00
|
|
|
text = "Scaled = 0";
|
|
|
|
}
|
|
|
|
canvas->drawBitmap( fBM, 100, 100, &paint );
|
|
|
|
canvas->restore();
|
|
|
|
canvas->drawText( text, strlen(text), 100, 400, paint );
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2014-08-08 19:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SampleView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new IdentityScaleView("mandrill_256.png"); }
|
|
|
|
static SkViewRegister reg(MyFactory);
|