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(GrContextFactory * grFactory,GrContextFactory::GLContextType type,GrContextFactory::GLContextOptions options,SkImageInfo info,int samples,bool useDIText)31 static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory,
32                                        GrContextFactory::GLContextType type,
33                                        GrContextFactory::GLContextOptions options,
34                                        SkImageInfo info,
35                                        int samples,
36                                        bool useDIText) {
37     uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
38     SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
39     return SkSurface::NewRenderTarget(grFactory->get(type, options), SkBudgeted::kNo,
40                                       info, samples, &props);
41 }
42 
43 }  // namespace DM
44 
45 #else// !SK_SUPPORT_GPU
46 
47 // Ganesh is not available.  Fake it.
48 
49 enum GrGLStandard {
50     kNone_GrGLStandard,
51     kGL_GrGLStandard,
52     kGLES_GrGLStandard
53 };
54 static const int kGrGLStandardCnt = 3;
55 
56 class GrContext {
57 public:
dumpCacheStats(SkString *)58     void dumpCacheStats(SkString*) const {}
dumpGpuStats(SkString *)59     void dumpGpuStats(SkString*) const {}
60 };
61 
62 class GrContextFactory {
63 public:
GrContextFactory()64     GrContextFactory() {};
GrContextFactory(const GrContextOptions &)65     explicit GrContextFactory(const GrContextOptions&) {}
66 
67     typedef int GLContextType;
68 
69     static const GLContextType kANGLE_GLContextType         = 0,
70                                kANGLE_GL_GLContextType      = 0,
71                                kCommandBufferES2_GLContextType = 0,
72                                kCommandBufferES3_GLContextType = 0,
73                                kDebug_GLContextType         = 0,
74                                kMESA_GLContextType          = 0,
75                                kNVPR_GLContextType          = 0,
76                                kNative_GLContextType        = 0,
77                                kNull_GLContextType          = 0;
78     static const int kGLContextTypeCnt = 1;
79     enum GLContextOptions {
80         kNone_GLContextOptions = 0,
81         kEnableNVPR_GLContextOptions = 0x1,
82     };
destroyContexts()83     void destroyContexts() {}
84 
abandonContexts()85     void abandonContexts() {}
86 };
87 
88 namespace DM {
89 
90 static const bool kGPUDisabled = true;
91 
NewGpuSurface(GrContextFactory *,GrContextFactory::GLContextType,GrContextFactory::GLContextOptions,SkImageInfo,int,bool)92 static inline SkSurface* NewGpuSurface(GrContextFactory*,
93                                        GrContextFactory::GLContextType,
94                                        GrContextFactory::GLContextOptions,
95                                        SkImageInfo,
96                                        int,
97                                        bool) {
98     return nullptr;
99 }
100 
101 }  // namespace DM
102 
103 #endif//SK_SUPPORT_GPU
104 
105 #endif//DMGpuSupport_DEFINED
106