1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Image_isLazyGenerated_a, 256, 80, false, 0) {
5 class TestImageGenerator : public SkImageGenerator {
6 public:
TestImageGenerator()7 TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
~TestImageGenerator()8 ~TestImageGenerator() override {}
9 protected:
onGetPixels(const SkImageInfo & info,void * pixelPtr,size_t rowBytes,const Options & options)10 bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes,
11 const Options& options) override {
12 SkPMColor* pixels = static_cast<SkPMColor*>(pixelPtr);
13 for (int y = 0; y < info.height(); ++y) {
14 for (int x = 0; x < info.width(); ++x) {
15 pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811;
16 }
17 }
18 return true;
19 }
20 };
21
draw(SkCanvas * canvas)22 void draw(SkCanvas* canvas) {
23 auto gen = std::unique_ptr<TestImageGenerator>(new TestImageGenerator());
24 sk_sp<SkImage> image(SkImages::DeferredFromGenerator(std::move(gen)));
25 SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy");
26 canvas->scale(8, 8);
27 canvas->drawImage(image, 0, 0);
28 SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {}), 4);
29 SkPaint paint;
30 canvas->drawString(lazy, 2, 5, font, paint);
31 }
32 } // END FIDDLE
33