blob: 72a627cb7f617ce02f8932c46d1e068b16ea21a5 (
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
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_
#define CC_OUTPUT_CONTEXT_PROVIDER_H_
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "cc/base/cc_export.h"
#include "gpu/command_buffer/common/capabilities.h"
class GrContext;
namespace blink { class WebGraphicsContext3D; }
namespace gpu { class ContextSupport; }
namespace cc {
struct ManagedMemoryPolicy;
class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
public:
// Bind the 3d context to the current thread. This should be called before
// accessing the contexts. Calling it more than once should have no effect.
// Once this function has been called, the class should only be accessed
// from the same thread.
virtual bool BindToCurrentThread() = 0;
virtual blink::WebGraphicsContext3D* Context3d() = 0;
virtual gpu::ContextSupport* ContextSupport() = 0;
virtual class GrContext* GrContext() = 0;
struct Capabilities {
bool discard_backbuffer : 1;
bool egl_image_external : 1;
bool fast_npot_mo8_textures : 1;
bool iosurface : 1;
bool map_image : 1;
bool map_sub : 1;
bool post_sub_buffer : 1;
bool set_visibility : 1;
bool shallow_flush : 1;
bool swapbuffers_complete_callback : 1;
bool texture_format_bgra8888 : 1;
bool texture_format_etc1 : 1;
bool texture_rectangle : 1;
bool texture_storage : 1;
bool texture_usage : 1;
bool discard_framebuffer : 1;
size_t max_transfer_buffer_usage_bytes;
CC_EXPORT Capabilities();
// TODO(boliu): Compose a gpu::Capabilities instead and remove this
// constructor.
explicit CC_EXPORT Capabilities(const gpu::Capabilities& gpu_capabilities);
};
// Returns the capabilities of the currently bound 3d context.
virtual Capabilities ContextCapabilities() = 0;
// Checks if the context is currently known to be lost.
virtual bool IsContextLost() = 0;
// Ask the provider to check if the contexts are valid or lost. If they are,
// this should invalidate the provider so that it can be replaced with a new
// one.
virtual void VerifyContexts() = 0;
// A method to be called from the main thread that should return true if
// the context inside the provider is no longer valid.
virtual bool DestroyedOnMainThread() = 0;
// Sets a callback to be called when the context is lost. This should be
// called from the same thread that the context is bound to. To avoid races,
// it should be called before BindToCurrentThread(), or VerifyContexts()
// should be called after setting the callback.
typedef base::Closure LostContextCallback;
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) = 0;
// Sets a callback to be called when swap buffers completes. This should be
// called from the same thread that the context is bound to.
typedef base::Closure SwapBuffersCompleteCallback;
virtual void SetSwapBuffersCompleteCallback(
const SwapBuffersCompleteCallback& swap_buffers_complete_callback) = 0;
// Sets a callback to be called when the memory policy changes. This should be
// called from the same thread that the context is bound to.
typedef base::Callback<void(const cc::ManagedMemoryPolicy& policy)>
MemoryPolicyChangedCallback;
virtual void SetMemoryPolicyChangedCallback(
const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
protected:
friend class base::RefCountedThreadSafe<ContextProvider>;
virtual ~ContextProvider() {}
};
} // namespace cc
#endif // CC_OUTPUT_CONTEXT_PROVIDER_H_
|