skia2/samplecode/SampleIdentityScale.cpp
Mike Reed 0933bc9b67 Revert "Revert "resources: remove most uses of GetResourcePath()""
This reverts commit cca2300559.

Reason for revert: think I guessed wrong about g32 -- unreverting

Original change's description:
> Revert "resources: remove most uses of GetResourcePath()"
> 
> This reverts commit 5093a539de.
> 
> Reason for revert: google3 seems broken
> 
> Original change's description:
> > resources: remove most uses of GetResourcePath()
> > 
> > Going forward, we will standardize on GetResourceAsData(), which will
> > make it easier to run tests in environments without access to the
> > filesystem.
> > 
> > Also: GetResourceAsData() complains when a resource is missing.
> > This is usually an error.
> > 
> > Change-Id: Iaf70b71b0ca5ed8cd1a5538a60ef185ae8736188
> > Reviewed-on: https://skia-review.googlesource.com/82642
> > Reviewed-by: Hal Canary <halcanary@google.com>
> > Commit-Queue: Hal Canary <halcanary@google.com>
> 
> TBR=halcanary@google.com,scroggo@google.com
> 
> Change-Id: Ic5a7c0167c995a672e6b06dc92abe00564432214
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/83001
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>

TBR=halcanary@google.com,scroggo@google.com,reed@google.com

Change-Id: I5a46e4de61186a8a5eb9cacd3275e24e311d5a07
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/82942
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2017-12-09 01:27:50 +00:00

84 lines
2.2 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "DecodeFile.h"
#include "gm.h"
#include "Resources.h"
#include "SampleCode.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkPath.h"
#include "SkRandom.h"
#include "SkStream.h"
#include "SkTime.h"
#include "SkClipOpPriv.h"
// 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[]) {
if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) {
fBM.allocN32Pixels(1, 1);
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
}
}
protected:
SkBitmap fBM;
// overrides from SkEventSink
bool onQuery(SkEvent* evt) override {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "IdentityScale");
return true;
}
return this->INHERITED::onQuery(evt);
}
void onDrawContent(SkCanvas* canvas) override {
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(48);
paint.setFilterQuality(kHigh_SkFilterQuality);
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));
canvas->clipPath(clipPath, kIntersect_SkClipOp, true);
text = "Scaled = 0";
}
canvas->drawBitmap( fBM, 100, 100, &paint );
canvas->restore();
canvas->drawString(text, 100, 400, paint );
}
private:
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new IdentityScaleView("images/mandrill_256.png"); }
static SkViewRegister reg(MyFactory);