• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                              kMetal_ContextType         = 0;
83     static const int kContextTypeCnt = 1;
84     enum class ContextOverrides {};
destroyContexts()85     void destroyContexts() {}
86 
abandonContexts()87     void abandonContexts() {}
88 
releaseResourcesAndAbandonContexts()89     void releaseResourcesAndAbandonContexts() {}
90 };
91 }  // namespace sk_gpu_test
92 
93 namespace DM {
94 
95 static const bool kGPUDisabled = true;
96 
NewGpuSurface(sk_gpu_test::GrContextFactory *,sk_gpu_test::GrContextFactory::ContextType,sk_gpu_test::GrContextFactory::ContextOverrides,SkImageInfo,int,bool)97 static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
98                                        sk_gpu_test::GrContextFactory::ContextType,
99                                        sk_gpu_test::GrContextFactory::ContextOverrides,
100                                        SkImageInfo,
101                                        int,
102                                        bool) {
103     return nullptr;
104 }
105 
106 }  // namespace DM
107 
108 #endif//SK_SUPPORT_GPU
109 
110 #endif//DMGpuSupport_DEFINED
111