blob: 2cfdbdcc2c178d86a9d4cc301c5ca3e92770d587 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
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
commit-bot@chromium.org787227d2014-03-26 21:26:15 +00008#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
bsalomon6dea83f2015-12-03 12:58:06 -080016// 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
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000020#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 SkSurface* NewGpuSurface(GrContextFactory* grFactory,
32 GrContextFactory::GLContextType type,
kkinnunen5219fd92015-12-10 06:28:13 -080033 GrContextFactory::GLContextOptions options,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000034 SkImageInfo info,
jvanverth4736e142014-11-07 07:12:46 -080035 int samples,
bsalomonafcd7cd2015-08-31 12:39:41 -070036 bool useDIText) {
37 uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
jvanverth4736e142014-11-07 07:12:46 -080038 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
kkinnunen3e980c32015-12-23 01:33:00 -080039 return SkSurface::NewRenderTarget(grFactory->get(type, options), SkSurface::kNo_Budgeted,
40 info, samples, &props);
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000041}
42
43} // namespace DM
44
45#else// !SK_SUPPORT_GPU
46
47// Ganesh is not available. Fake it.
48
kkinnunen80549fc2014-06-30 06:36:31 -070049enum GrGLStandard {
50 kNone_GrGLStandard,
51 kGL_GrGLStandard,
52 kGLES_GrGLStandard
53};
mtklein2ecf86e2014-11-06 08:06:39 -080054static const int kGrGLStandardCnt = 3;
kkinnunen80549fc2014-06-30 06:36:31 -070055
mtkleinb9eb4ac2015-02-02 18:26:03 -080056class GrContext {
57public:
58 void dumpCacheStats(SkString*) const {}
59 void dumpGpuStats(SkString*) const {}
60};
61
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000062class GrContextFactory {
63public:
bsalomon4ee6bd82015-05-27 13:23:23 -070064 GrContextFactory() {};
65 explicit GrContextFactory(const GrContextOptions&) {}
66
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000067 typedef int GLContextType;
68
hendrikw885bf092015-08-27 10:38:39 -070069 static const GLContextType kANGLE_GLContextType = 0,
hendrikweddbefb2015-09-11 13:07:29 -070070 kANGLE_GL_GLContextType = 0,
hendrikw885bf092015-08-27 10:38:39 -070071 kCommandBuffer_GLContextType = 0,
72 kDebug_GLContextType = 0,
73 kMESA_GLContextType = 0,
74 kNVPR_GLContextType = 0,
75 kNative_GLContextType = 0,
76 kNull_GLContextType = 0;
mtklein2ecf86e2014-11-06 08:06:39 -080077 static const int kGLContextTypeCnt = 1;
kkinnunen5219fd92015-12-10 06:28:13 -080078 enum GLContextOptions {
79 kNone_GLContextOptions = 0,
80 kEnableNVPR_GLContextOptions = 0x1,
81 };
mtklein1e319f72014-07-15 08:27:06 -070082 void destroyContexts() {}
bsalomon2354f842014-07-28 13:48:36 -070083
84 void abandonContexts() {}
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000085};
86
87namespace DM {
88
89static const bool kGPUDisabled = true;
90
91static inline SkSurface* NewGpuSurface(GrContextFactory*,
92 GrContextFactory::GLContextType,
kkinnunen5219fd92015-12-10 06:28:13 -080093 GrContextFactory::GLContextOptions,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000094 SkImageInfo,
jvanverth4736e142014-11-07 07:12:46 -080095 int,
96 bool) {
halcanary96fcdcc2015-08-27 07:41:13 -070097 return nullptr;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000098}
99
100} // namespace DM
101
102#endif//SK_SUPPORT_GPU
103
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000104#endif//DMGpuSupport_DEFINED