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
27 namespace DM {
28
29 static const bool kGPUDisabled = false;
30
NewGpuSurface(sk_gpu_test::GrContextFactory * grFactory,sk_gpu_test::GrContextFactory::ContextType type,sk_gpu_test::GrContextFactory::ContextOverrides overrides,SkImageInfo info,int samples,bool useDIText)31 static 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
50 enum GrGLStandard {
51 kNone_GrGLStandard,
52 kGL_GrGLStandard,
53 kGLES_GrGLStandard
54 };
55 static const int kGrGLStandardCnt = 3;
56
57 class GrContext {
58 public:
dumpCacheStats(SkString *)59 void dumpCacheStats(SkString*) const {}
dumpGpuStats(SkString *)60 void dumpGpuStats(SkString*) const {}
61 };
62
63 namespace sk_gpu_test {
64 class GrContextFactory {
65 public:
GrContextFactory()66 GrContextFactory() {}
GrContextFactory(const GrContextOptions &)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 kMESA_ContextType = 0,
76 kNVPR_ContextType = 0,
77 kNativeGL_ContextType = 0,
78 kGL_ContextType = 0,
79 kGLES_ContextType = 0,
80 kNullGL_ContextType = 0,
81 kVulkan_ContextType = 0;
82 static const int kContextTypeCnt = 1;
83 enum class ContextOverrides {};
destroyContexts()84 void destroyContexts() {}
85
abandonContexts()86 void abandonContexts() {}
87
releaseResourcesAndAbandonContexts()88 void releaseResourcesAndAbandonContexts() {}
89 };
90 } // namespace sk_gpu_test
91
92 namespace DM {
93
94 static const bool kGPUDisabled = true;
95
NewGpuSurface(sk_gpu_test::GrContextFactory *,sk_gpu_test::GrContextFactory::ContextType,sk_gpu_test::GrContextFactory::ContextOverrides,SkImageInfo,int,bool)96 static 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