Move prefs::kLastPolicyStatisticsUpdate to the policy component.
[chromium-blink-merge.git] / cc / output / context_provider.h
blob0e21a3e6bba6c6a212d3442c125cb6985975ee32
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_
6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "cc/base/cc_export.h"
12 class GrContext;
13 namespace WebKit { class WebGraphicsContext3D; }
15 namespace cc {
16 struct ManagedMemoryPolicy;
18 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
19 public:
20 // Bind the 3d context to the current thread. This should be called before
21 // accessing the contexts. Calling it more than once should have no effect.
22 // Once this function has been called, the class should only be accessed
23 // from the same thread.
24 virtual bool BindToCurrentThread() = 0;
26 virtual WebKit::WebGraphicsContext3D* Context3d() = 0;
27 virtual class GrContext* GrContext() = 0;
29 struct Capabilities {
30 bool bind_uniform_location;
31 bool discard_backbuffer;
32 bool egl_image_external;
33 bool fast_npot_mo8_textures;
34 bool iosurface;
35 bool map_image;
36 bool map_sub;
37 bool post_sub_buffer;
38 bool set_visibility;
39 bool shallow_flush;
40 bool swapbuffers_complete_callback;
41 bool texture_format_bgra8888;
42 bool texture_rectangle;
43 bool texture_storage;
44 bool texture_usage;
45 bool discard_framebuffer;
46 size_t max_transfer_buffer_usage_bytes;
48 CC_EXPORT Capabilities();
50 // Returns the capabilities of the currently bound 3d context.
51 virtual Capabilities ContextCapabilities() = 0;
53 // Ask the provider to check if the contexts are valid or lost. If they are,
54 // this should invalidate the provider so that it can be replaced with a new
55 // one.
56 virtual void VerifyContexts() = 0;
58 // A method to be called from the main thread that should return true if
59 // the context inside the provider is no longer valid.
60 virtual bool DestroyedOnMainThread() = 0;
62 // Sets a callback to be called when the context is lost. This should be
63 // called from the same thread that the context is bound to. To avoid races,
64 // it should be called before BindToCurrentThread(), or VerifyContexts()
65 // should be called after setting the callback.
66 typedef base::Closure LostContextCallback;
67 virtual void SetLostContextCallback(
68 const LostContextCallback& lost_context_callback) = 0;
70 // Sets a callback to be called when the context is lost. This should be
71 // called from the same thread that the context is bound to.
72 typedef base::Closure SwapBuffersCompleteCallback;
73 virtual void SetSwapBuffersCompleteCallback(
74 const SwapBuffersCompleteCallback& swap_buffers_complete_callback) = 0;
76 // Sets a callback to be called when the memory policy changes. This should be
77 // called from the same thread that the context is bound to.
78 typedef base::Callback<void(
79 const cc::ManagedMemoryPolicy& policy,
80 bool discard_backbuffer_when_not_visible)> MemoryPolicyChangedCallback;
81 virtual void SetMemoryPolicyChangedCallback(
82 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
84 protected:
85 friend class base::RefCountedThreadSafe<ContextProvider>;
86 virtual ~ContextProvider() {}
89 } // namespace cc
91 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_