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 WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
6 #define WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h"
11 #include "base/threading/thread_checker.h"
12 #include "cc/output/context_provider.h"
13 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
14 #include "webkit/common/gpu/webkit_gpu_export.h"
16 namespace WebKit { class WebGraphicsContext3D; }
20 class GrContextForWebGraphicsContext3D;
22 class WEBKIT_GPU_EXPORT ContextProviderInProcess
23 : NON_EXPORTED_BASE(public cc::ContextProvider) {
25 static scoped_refptr<ContextProviderInProcess> Create(
26 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d,
27 const std::string& debug_name);
29 // Calls Create() with a default factory method for creating an offscreen
31 static scoped_refptr<ContextProviderInProcess> CreateOffscreen();
33 virtual bool BindToCurrentThread() OVERRIDE;
34 virtual Capabilities ContextCapabilities() OVERRIDE;
35 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
36 virtual ::gpu::ContextSupport* ContextSupport() OVERRIDE;
37 virtual class GrContext* GrContext() OVERRIDE;
38 virtual void VerifyContexts() OVERRIDE;
39 virtual bool DestroyedOnMainThread() OVERRIDE;
40 virtual void SetLostContextCallback(
41 const LostContextCallback& lost_context_callback) OVERRIDE;
42 virtual void SetSwapBuffersCompleteCallback(
43 const SwapBuffersCompleteCallback& swap_buffers_complete_callback)
45 virtual void SetMemoryPolicyChangedCallback(
46 const MemoryPolicyChangedCallback& memory_policy_changed_callback)
50 ContextProviderInProcess(
51 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d,
52 const std::string& debug_name);
53 virtual ~ContextProviderInProcess();
56 void OnSwapBuffersComplete();
59 base::ThreadChecker main_thread_checker_;
60 base::ThreadChecker context_thread_checker_;
62 scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl>
64 scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_;
66 LostContextCallback lost_context_callback_;
67 SwapBuffersCompleteCallback swap_buffers_complete_callback_;
69 base::Lock destroyed_lock_;
72 std::string debug_name_;
73 class LostContextCallbackProxy;
74 scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_;
76 class SwapBuffersCompleteCallbackProxy;
77 scoped_ptr<SwapBuffersCompleteCallbackProxy>
78 swap_buffers_complete_callback_proxy_;
80 DISALLOW_COPY_AND_ASSIGN(ContextProviderInProcess);
86 #endif // WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_