aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMGpuSupport.h
blob: 7b1fb0d61d04ba88368ff994ece3a154967d3600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef DMGpuSupport_DEFINED
#define DMGpuSupport_DEFINED

// Provides Ganesh to DM,
// or if it's not available, fakes it enough so most code doesn't have to know that.

#include "SkSurface.h"

// This should be safe to include even in no-gpu builds. Include by relative path so it
// can be found in non-gpu builds.
#include "../include/gpu/GrContextOptions.h"

#if SK_SUPPORT_GPU

// Ganesh is available.  Yippee!

#  include "GrContext.h"
#  include "GrContextFactory.h"

namespace DM {

static const bool kGPUDisabled = false;

static inline sk_sp<SkSurface> NewGpuSurface(
        sk_gpu_test::GrContextFactory* grFactory,
        sk_gpu_test::GrContextFactory::ContextType type,
        sk_gpu_test::GrContextFactory::ContextOverrides overrides,
        SkImageInfo info,
        int samples,
        bool useDIText) {
    uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
    SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
    return SkSurface::MakeRenderTarget(grFactory->get(type, overrides), SkBudgeted::kNo,
                                       info, samples, &props);
}

}  // namespace DM

#else// !SK_SUPPORT_GPU

// Ganesh is not available.  Fake it.

enum GrGLStandard {
    kNone_GrGLStandard,
    kGL_GrGLStandard,
    kGLES_GrGLStandard
};
static const int kGrGLStandardCnt = 3;

class GrContext {
public:
    void dumpCacheStats(SkString*) const {}
    void dumpGpuStats(SkString*) const {}
};

namespace sk_gpu_test {
class GrContextFactory {
public:
    GrContextFactory() {}
    explicit GrContextFactory(const GrContextOptions&) {}

    typedef int ContextType;

    static const ContextType kANGLE_ContextType         = 0,
                             kANGLE_GL_ContextType      = 0,
                             kCommandBuffer_ContextType = 0,
                             kDebugGL_ContextType       = 0,
                             kMESA_ContextType          = 0,
                             kNVPR_ContextType          = 0,
                             kNativeGL_ContextType      = 0,
                             kGL_ContextType            = 0,
                             kGLES_ContextType          = 0,
                             kNullGL_ContextType        = 0,
                             kVulkan_ContextType        = 0,
                             kMetal_ContextType         = 0;
    static const int kContextTypeCnt = 1;
    enum class ContextOverrides {};
    void destroyContexts() {}

    void abandonContexts() {}

    void releaseResourcesAndAbandonContexts() {}
};
}  // namespace sk_gpu_test

namespace DM {

static const bool kGPUDisabled = true;

static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
                                       sk_gpu_test::GrContextFactory::ContextType,
                                       sk_gpu_test::GrContextFactory::ContextOverrides,
                                       SkImageInfo,
                                       int,
                                       bool) {
    return nullptr;
}

}  // namespace DM

#endif//SK_SUPPORT_GPU

#endif//DMGpuSupport_DEFINED