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"
13 namespace WebKit { class WebGraphicsContext3D; }
14 namespace gpu { class ContextSupport; }
17 struct ManagedMemoryPolicy;
19 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
21 // Bind the 3d context to the current thread. This should be called before
22 // accessing the contexts. Calling it more than once should have no effect.
23 // Once this function has been called, the class should only be accessed
24 // from the same thread.
25 virtual bool BindToCurrentThread() = 0;
27 virtual WebKit::WebGraphicsContext3D* Context3d() = 0;
28 virtual gpu::ContextSupport* ContextSupport() = 0;
29 virtual class GrContext* GrContext() = 0;
32 bool bind_uniform_location;
33 bool discard_backbuffer;
34 bool egl_image_external;
35 bool fast_npot_mo8_textures;
42 bool swapbuffers_complete_callback;
43 bool texture_format_bgra8888;
44 bool texture_format_etc1;
45 bool texture_rectangle;
48 bool discard_framebuffer;
49 size_t max_transfer_buffer_usage_bytes;
51 CC_EXPORT Capabilities();
53 // Returns the capabilities of the currently bound 3d context.
54 virtual Capabilities ContextCapabilities() = 0;
56 // Ask the provider to check if the contexts are valid or lost. If they are,
57 // this should invalidate the provider so that it can be replaced with a new
59 virtual void VerifyContexts() = 0;
61 // A method to be called from the main thread that should return true if
62 // the context inside the provider is no longer valid.
63 virtual bool DestroyedOnMainThread() = 0;
65 // Sets a callback to be called when the context is lost. This should be
66 // called from the same thread that the context is bound to. To avoid races,
67 // it should be called before BindToCurrentThread(), or VerifyContexts()
68 // should be called after setting the callback.
69 typedef base::Closure LostContextCallback;
70 virtual void SetLostContextCallback(
71 const LostContextCallback& lost_context_callback) = 0;
73 // Sets a callback to be called when swap buffers completes. This should be
74 // called from the same thread that the context is bound to.
75 typedef base::Closure SwapBuffersCompleteCallback;
76 virtual void SetSwapBuffersCompleteCallback(
77 const SwapBuffersCompleteCallback& swap_buffers_complete_callback) = 0;
79 // Sets a callback to be called when the memory policy changes. This should be
80 // called from the same thread that the context is bound to.
81 typedef base::Callback<void(const cc::ManagedMemoryPolicy& policy)>
82 MemoryPolicyChangedCallback;
83 virtual void SetMemoryPolicyChangedCallback(
84 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
87 friend class base::RefCountedThreadSafe<ContextProvider>;
88 virtual ~ContextProvider() {}
93 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_