1/*
2 * Copyright 2014 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#ifndef DMGpuSupport_DEFINED
9#define DMGpuSupport_DEFINED
10
11// Provides Ganesh to DM,
12// or if it's not available, fakes it enough so most code doesn't have to know that.
13
14#include "SkSurface.h"
15
16// This should be safe to include even in no-gpu builds. Include by relative path so it
17// can be found in non-gpu builds.
18#include "../include/gpu/GrContextOptions.h"
19
20#if SK_SUPPORT_GPU
21
22// Ganesh is available.  Yippee!
23
24#  include "GrContext.h"
25#  include "GrContextFactory.h"
26
27namespace DM {
28
29static const bool kGPUDisabled = false;
30
31static inline sk_sp<SkSurface> NewGpuSurface(
32        sk_gpu_test::GrContextFactory* grFactory,
33        sk_gpu_test::GrContextFactory::ContextType type,
34        sk_gpu_test::GrContextFactory::ContextOverrides overrides,
35        SkImageInfo info,
36        int samples,
37        bool useDIText) {
38    uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
39    SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
40    return SkSurface::MakeRenderTarget(grFactory->get(type, overrides), SkBudgeted::kNo,
41                                       info, samples, &props);
42}
43
44}  // namespace DM
45
46#else// !SK_SUPPORT_GPU
47
48// Ganesh is not available.  Fake it.
49
50enum GrGLStandard {
51    kNone_GrGLStandard,
52    kGL_GrGLStandard,
53    kGLES_GrGLStandard
54};
55static const int kGrGLStandardCnt = 3;
56
57class GrContext {
58public:
59    void dumpCacheStats(SkString*) const {}
60    void dumpGpuStats(SkString*) const {}
61};
62
63namespace sk_gpu_test {
64class GrContextFactory {
65public:
66    GrContextFactory() {}
67    explicit GrContextFactory(const GrContextOptions&) {}
68
69    typedef int ContextType;
70
71    static const ContextType kANGLE_ContextType         = 0,
72                             kANGLE_GL_ContextType      = 0,
73                             kCommandBuffer_ContextType = 0,
74                             kDebugGL_ContextType       = 0,
75                             kNVPR_ContextType          = 0,
76                             kNativeGL_ContextType      = 0,
77                             kGL_ContextType            = 0,
78                             kGLES_ContextType          = 0,
79                             kNullGL_ContextType        = 0,
80                             kVulkan_ContextType        = 0,
81                             kMetal_ContextType         = 0;
82    static const int kContextTypeCnt = 1;
83    enum class ContextOverrides {};
84    void destroyContexts() {}
85
86    void abandonContexts() {}
87
88    void releaseResourcesAndAbandonContexts() {}
89};
90}  // namespace sk_gpu_test
91
92namespace DM {
93
94static const bool kGPUDisabled = true;
95
96static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
97                                       sk_gpu_test::GrContextFactory::ContextType,
98                                       sk_gpu_test::GrContextFactory::ContextOverrides,
99                                       SkImageInfo,
100                                       int,
101                                       bool) {
102    return nullptr;
103}
104
105}  // namespace DM
106
107#endif//SK_SUPPORT_GPU
108
109#endif//DMGpuSupport_DEFINED
110