• 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 #if SK_SUPPORT_GPU
17 
18 // Ganesh is available.  Yippee!
19 
20 #  include "GrContext.h"
21 #  include "GrContextFactory.h"
22 
23 namespace DM {
24 
25 static const bool kGPUDisabled = false;
26 
NewGpuSurface(GrContextFactory * grFactory,GrContextFactory::GLContextType type,GrGLStandard gpuAPI,SkImageInfo info,int samples,bool useDFText)27 static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory,
28                                        GrContextFactory::GLContextType type,
29                                        GrGLStandard gpuAPI,
30                                        SkImageInfo info,
31                                        int samples,
32                                        bool useDFText) {
33     uint32_t flags = useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
34     SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
35     return SkSurface::NewRenderTarget(grFactory->get(type, gpuAPI), SkSurface::kNo_Budgeted,
36                                       info, samples, &props);
37 }
38 
39 }  // namespace DM
40 
41 #else// !SK_SUPPORT_GPU
42 
43 // Ganesh is not available.  Fake it.
44 
45 enum GrGLStandard {
46     kNone_GrGLStandard,
47     kGL_GrGLStandard,
48     kGLES_GrGLStandard
49 };
50 static const int kGrGLStandardCnt = 3;
51 
52 class GrContext {
53 public:
dumpCacheStats(SkString *)54     void dumpCacheStats(SkString*) const {}
dumpGpuStats(SkString *)55     void dumpGpuStats(SkString*) const {}
56 };
57 
58 class GrContextFactory {
59 public:
60     typedef int GLContextType;
61 
62     static const GLContextType kANGLE_GLContextType  = 0,
63                                kDebug_GLContextType  = 0,
64                                kMESA_GLContextType   = 0,
65                                kNVPR_GLContextType   = 0,
66                                kNative_GLContextType = 0,
67                                kNull_GLContextType   = 0;
68     static const int kGLContextTypeCnt = 1;
destroyContexts()69     void destroyContexts() {}
70 
abandonContexts()71     void abandonContexts() {}
72 };
73 
74 namespace DM {
75 
76 static const bool kGPUDisabled = true;
77 
NewGpuSurface(GrContextFactory *,GrContextFactory::GLContextType,GrGLStandard,SkImageInfo,int,bool)78 static inline SkSurface* NewGpuSurface(GrContextFactory*,
79                                        GrContextFactory::GLContextType,
80                                        GrGLStandard,
81                                        SkImageInfo,
82                                        int,
83                                        bool) {
84     return NULL;
85 }
86 
87 }  // namespace DM
88 
89 #endif//SK_SUPPORT_GPU
90 
91 #endif//DMGpuSupport_DEFINED
92