Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / gm / factory.cpp
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 "SkDecodingImageGenerator.h"
14 #include "SkDiscardableMemoryPool.h"
15 #include "SkDiscardablePixelRef.h"
16 #include "SkImageDecoder.h"
17 #include "SkImageGeneratorPriv.h"
18 #include "SkOSFile.h"
19 #include "SkStream.h"
20
21 namespace skiagm {
22
23 /**
24  *  Draw a PNG created by SkBitmapFactory.
25  */
26 class FactoryGM : public GM {
27 public:
28     FactoryGM() {}
29
30 protected:
31     virtual void onOnceBeforeDraw() SK_OVERRIDE {
32         SkString resourcePath = GetResourcePath();
33         // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
34         SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "plane.png");
35         SkAutoDataUnref data(SkData::NewFromFileName(filename.c_str()));
36         if (NULL != data.get()) {
37             // Create a cache which will boot the pixels out anytime the
38             // bitmap is unlocked.
39             SkAutoTUnref<SkDiscardableMemoryPool> pool(
40                 SkDiscardableMemoryPool::Create(1));
41             SkAssertResult(SkInstallDiscardablePixelRef(
42                 SkDecodingImageGenerator::Create(
43                     data, SkDecodingImageGenerator::Options()),
44                 &fBitmap, pool));
45         }
46     }
47
48     virtual SkString onShortName() {
49         return SkString("factory");
50     }
51
52     virtual SkISize onISize() {
53         return SkISize::Make(640, 480);
54     }
55
56     virtual void onDraw(SkCanvas* canvas) {
57         canvas->drawBitmap(fBitmap, 0, 0);
58     }
59
60     // Skip cross process pipe due to https://code.google.com/p/skia/issues/detail?id=1520
61     virtual uint32_t onGetFlags() const {
62         return INHERITED::onGetFlags() | kSkipPipeCrossProcess_Flag;
63     }
64
65 private:
66     SkBitmap fBitmap;
67
68     typedef GM INHERITED;
69 };
70
71 //////////////////////////////////////////////////////////////////////////////
72
73 static GM* MyFactory(void*) { return new FactoryGM; }
74 static GMRegistry reg(MyFactory);
75
76 }  // namespace skiagm