1 // Copyright 2014 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 COMPONENTS_VIEW_MANAGER_SURFACES_SURFACES_CONTEXT_PROVIDER_H_
6 #define COMPONENTS_VIEW_MANAGER_SURFACES_SURFACES_CONTEXT_PROVIDER_H_
8 #include "base/macros.h"
9 #include "base/synchronization/lock.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "cc/output/context_provider.h"
12 #include "components/view_manager/gles2/command_buffer_local_client.h"
13 #include "ui/gfx/native_widget_types.h"
21 class GLES2Implementation
;
27 class CommandBufferDriver
;
28 class CommandBufferImpl
;
29 class CommandBufferLocal
;
35 class SurfacesContextProviderDelegate
;
37 class SurfacesContextProvider
: public cc::ContextProvider
,
38 public gles2::CommandBufferLocalClient
,
39 public base::NonThreadSafe
{
41 SurfacesContextProvider(SurfacesContextProviderDelegate
* delegate
,
42 gfx::AcceleratedWidget widget
,
43 const scoped_refptr
<gles2::GpuState
>& state
);
45 // cc::ContextProvider implementation.
46 bool BindToCurrentThread() override
;
47 gpu::gles2::GLES2Interface
* ContextGL() override
;
48 gpu::ContextSupport
* ContextSupport() override
;
49 class GrContext
* GrContext() override
;
50 void InvalidateGrContext(uint32_t state
) override
;
51 Capabilities
ContextCapabilities() override
;
52 void VerifyContexts() override
{}
53 void DeleteCachedResources() override
{}
54 bool DestroyedOnMainThread() override
;
55 void SetLostContextCallback(
56 const LostContextCallback
& lost_context_callback
) override
;
57 void SetMemoryPolicyChangedCallback(
58 const MemoryPolicyChangedCallback
& memory_policy_changed_callback
)
60 void SetupLock() override
;
61 base::Lock
* GetLock() override
;
64 friend class base::RefCountedThreadSafe
<SurfacesContextProvider
>;
65 ~SurfacesContextProvider() override
;
68 // CommandBufferLocalClient:
69 void UpdateVSyncParameters(int64_t timebase
, int64_t interval
) override
;
70 void DidLoseContext() override
;
73 // Initialized in BindToCurrentThread.
74 scoped_ptr
<gpu::gles2::GLES2CmdHelper
> gles2_helper_
;
75 scoped_ptr
<gpu::TransferBuffer
> transfer_buffer_
;
76 scoped_ptr
<gpu::gles2::GLES2Implementation
> implementation_
;
78 cc::ContextProvider::Capabilities capabilities_
;
79 LostContextCallback lost_context_callback_
;
81 SurfacesContextProviderDelegate
* delegate_
;
82 scoped_refptr
<gles2::GpuState
> state_
;
83 gfx::AcceleratedWidget widget_
;
84 scoped_ptr
<gles2::CommandBufferLocal
> command_buffer_local_
;
86 base::Lock context_lock_
;
88 DISALLOW_COPY_AND_ASSIGN(SurfacesContextProvider
);
91 } // namespace surfaces
93 #endif // COMPONENTS_VIEW_MANAGER_SURFACES_SURFACES_CONTEXT_PROVIDER_H_