2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "Resources.h"
11 #include "SampleCode.h"
12 #include "SkBlurMaskFilter.h"
14 #include "SkColorPriv.h"
15 #include "SkImageDecoder.h"
20 // Intended to exercise pixel snapping observed with scaled images (and
21 // with non-scaled images, but for a different reason): Bug 1145
23 class IdentityScaleView : public SampleView {
25 IdentityScaleView(const char imageFilename[]) {
26 SkString resourcePath = GetResourcePath(imageFilename);
27 SkImageDecoder* codec = NULL;
28 SkFILEStream stream(resourcePath.c_str());
29 if (stream.isValid()) {
30 codec = SkImageDecoder::Factory(&stream);
34 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
37 fBM.allocN32Pixels(1, 1);
38 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
45 // overrides from SkEventSink
46 bool onQuery(SkEvent* evt) SK_OVERRIDE {
47 if (SampleCode::TitleQ(*evt)) {
48 SampleCode::TitleR(evt, "IdentityScale");
51 return this->INHERITED::onQuery(evt);
54 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
58 paint.setAntiAlias(true);
59 paint.setTextSize(48);
60 paint.setFilterQuality(kHigh_SkFilterQuality);
62 SkTime::DateTime time;
63 SkTime::GetDateTime(&time);
65 bool use_scale = (time.fSecond % 2 == 1);
73 SkRect r = { 100, 100, 356, 356 };
75 clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5));
76 canvas->clipPath(clipPath, SkRegion::kIntersect_Op, SkToBool(1));
79 canvas->drawBitmap( fBM, 100, 100, &paint );
81 canvas->drawText( text, strlen(text), 100, 400, paint );
86 typedef SampleView INHERITED;
89 //////////////////////////////////////////////////////////////////////////////
91 static SkView* MyFactory() { return new IdentityScaleView("mandrill_256.png"); }
92 static SkViewRegister reg(MyFactory);