• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "gm.h"
9 
10 #include "Resources.h"
11 #include "SkCanvas.h"
12 #include "SkData.h"
13 #include "SkDiscardableMemoryPool.h"
14 #include "SkDiscardablePixelRef.h"
15 #include "SkImageDecoder.h"
16 #include "SkImageGeneratorPriv.h"
17 #include "SkOSFile.h"
18 #include "SkStream.h"
19 
20 namespace skiagm {
21 
22 /**
23  *  Draw a PNG created by SkBitmapFactory.
24  */
25 class FactoryGM : public GM {
26 public:
FactoryGM()27     FactoryGM() {}
28 
29 protected:
onOnceBeforeDraw()30     void onOnceBeforeDraw() override {
31         // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
32         SkString pngFilename = GetResourcePath("plane.png");
33         SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str()));
34         if (data.get()) {
35             // Create a cache which will boot the pixels out anytime the
36             // bitmap is unlocked.
37             SkAutoTUnref<SkDiscardableMemoryPool> pool(
38                 SkDiscardableMemoryPool::Create(1));
39             SkAssertResult(SkDEPRECATED_InstallDiscardablePixelRef(
40                                                         SkImageGenerator::NewFromEncoded(data),
41                                                         nullptr, &fBitmap, pool));
42         }
43     }
44 
onShortName()45     SkString onShortName() override {
46         return SkString("factory");
47     }
48 
onISize()49     SkISize onISize() override {
50         return SkISize::Make(640, 480);
51     }
52 
onDraw(SkCanvas * canvas)53     void onDraw(SkCanvas* canvas) override {
54         canvas->drawBitmap(fBitmap, 0, 0);
55     }
56 
57 private:
58     SkBitmap fBitmap;
59 
60     typedef GM INHERITED;
61 };
62 
63 //////////////////////////////////////////////////////////////////////////////
64 
MyFactory(void *)65 static GM* MyFactory(void*) { return new FactoryGM; }
66 static GMRegistry reg(MyFactory);
67 
68 }  // namespace skiagm
69