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 UI_COMPOSITOR_TEST_IN_PROCESS_CONTEXT_PROVIDER_H_
6 #define UI_COMPOSITOR_TEST_IN_PROCESS_CONTEXT_PROVIDER_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_checker.h"
14 #include "cc/output/context_provider.h"
15 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
16 #include "skia/ext/refptr.h"
17 #include "ui/gfx/native_widget_types.h"
20 class GLInProcessContext
;
25 class InProcessContextProvider
: public cc::ContextProvider
{
27 static scoped_refptr
<InProcessContextProvider
> Create(
28 const gpu::gles2::ContextCreationAttribHelper
& attribs
,
29 bool lose_context_when_out_of_memory
,
30 gfx::AcceleratedWidget window
,
31 const std::string
& debug_name
);
33 // Uses default attributes for creating an offscreen context.
34 static scoped_refptr
<InProcessContextProvider
> CreateOffscreen(
35 bool lose_context_when_out_of_memory
);
38 InProcessContextProvider(
39 const gpu::gles2::ContextCreationAttribHelper
& attribs
,
40 bool lose_context_when_out_of_memory
,
41 gfx::AcceleratedWidget window
,
42 const std::string
& debug_name
);
43 ~InProcessContextProvider() override
;
45 // cc::ContextProvider:
46 bool BindToCurrentThread() override
;
47 Capabilities
ContextCapabilities() override
;
48 gpu::gles2::GLES2Interface
* ContextGL() override
;
49 gpu::ContextSupport
* ContextSupport() override
;
50 class GrContext
* GrContext() override
;
51 void SetupLock() override
;
52 base::Lock
* GetLock() override
;
53 bool IsContextLost() override
;
54 void VerifyContexts() override
;
55 void DeleteCachedResources() override
;
56 bool DestroyedOnMainThread() override
;
57 void SetLostContextCallback(
58 const LostContextCallback
& lost_context_callback
) override
;
59 void SetMemoryPolicyChangedCallback(
60 const MemoryPolicyChangedCallback
& memory_policy_changed_callback
)
65 base::ThreadChecker main_thread_checker_
;
66 base::ThreadChecker context_thread_checker_
;
68 scoped_ptr
<gpu::GLInProcessContext
> context_
;
69 skia::RefPtr
<class GrContext
> gr_context_
;
71 gpu::gles2::ContextCreationAttribHelper attribs_
;
72 bool lose_context_when_out_of_memory_
;
73 gfx::AcceleratedWidget window_
;
74 std::string debug_name_
;
75 cc::ContextProvider::Capabilities capabilities_
;
77 LostContextCallback lost_context_callback_
;
79 base::Lock destroyed_lock_
;
82 base::Lock context_lock_
;
84 DISALLOW_COPY_AND_ASSIGN(InProcessContextProvider
);
89 #endif // UI_COMPOSITOR_TEST_IN_PROCESS_CONTEXT_PROVIDER_H_