- add sources.
[platform/framework/web/crosswalk.git] / src / cc / output / context_provider.h
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.
4
5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_
6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "cc/base/cc_export.h"
11
12 class GrContext;
13 namespace WebKit { class WebGraphicsContext3D; }
14 namespace gpu { class ContextSupport; }
15
16 namespace cc {
17 struct ManagedMemoryPolicy;
18
19 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
20  public:
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;
26
27   virtual WebKit::WebGraphicsContext3D* Context3d() = 0;
28   virtual gpu::ContextSupport* ContextSupport() = 0;
29   virtual class GrContext* GrContext() = 0;
30
31   struct Capabilities {
32     bool bind_uniform_location;
33     bool discard_backbuffer;
34     bool egl_image_external;
35     bool fast_npot_mo8_textures;
36     bool iosurface;
37     bool map_image;
38     bool map_sub;
39     bool post_sub_buffer;
40     bool set_visibility;
41     bool shallow_flush;
42     bool swapbuffers_complete_callback;
43     bool texture_format_bgra8888;
44     bool texture_format_etc1;
45     bool texture_rectangle;
46     bool texture_storage;
47     bool texture_usage;
48     bool discard_framebuffer;
49     size_t max_transfer_buffer_usage_bytes;
50
51     CC_EXPORT Capabilities();
52   };
53   // Returns the capabilities of the currently bound 3d context.
54   virtual Capabilities ContextCapabilities() = 0;
55
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
58   // one.
59   virtual void VerifyContexts() = 0;
60
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;
64
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;
72
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;
78
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;
85
86  protected:
87   friend class base::RefCountedThreadSafe<ContextProvider>;
88   virtual ~ContextProvider() {}
89 };
90
91 }  // namespace cc
92
93 #endif  // CC_OUTPUT_CONTEXT_PROVIDER_H_