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 ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_
6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_
10 #include "android_webview/browser/gl_view_renderer_manager.h"
11 #include "android_webview/browser/shared_renderer_state.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/android/synchronous_compositor.h"
17 namespace android_webview
{
20 class BrowserViewRendererClient
;
23 class DeferredGpuCommandService
;
24 } // namespace internal
26 class HardwareRenderer
{
28 explicit HardwareRenderer(SharedRendererState
* state
);
31 static void CalculateTileMemoryPolicy();
33 bool DrawGL(AwDrawGLInfo
* draw_info
, DrawGLResult
* result
);
34 bool TrimMemory(int level
, bool visible
);
37 friend class internal::DeferredGpuCommandService
;
39 void SetMemoryPolicy(content::SynchronousCompositorMemoryPolicy
& new_policy
);
41 SharedRendererState
* shared_renderer_state_
;
43 typedef void* EGLContext
;
44 EGLContext last_egl_context_
;
46 scoped_refptr
<AwGLSurface
> gl_surface_
;
47 content::SynchronousCompositorMemoryPolicy memory_policy_
;
49 GLViewRendererManager::Key manager_key_
;
51 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer
);
61 static bool IsAllowed();
66 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL
);
69 // TODO(boliu): Teach this class about RT.
70 class DeferredGpuCommandService
71 : public gpu::InProcessCommandBuffer::Service
,
72 public base::RefCountedThreadSafe
<DeferredGpuCommandService
> {
74 DeferredGpuCommandService();
76 virtual void ScheduleTask(const base::Closure
& task
) OVERRIDE
;
77 virtual void ScheduleIdleWork(const base::Closure
& task
) OVERRIDE
;
78 virtual bool UseVirtualizedGLContexts() OVERRIDE
;
82 virtual void AddRef() const OVERRIDE
;
83 virtual void Release() const OVERRIDE
;
86 virtual ~DeferredGpuCommandService();
87 friend class base::RefCountedThreadSafe
<DeferredGpuCommandService
>;
90 static void RequestProcessGLOnUIThread();
92 base::Lock tasks_lock_
;
93 std::queue
<base::Closure
> tasks_
;
94 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService
);
97 } // namespace internal
99 } // namespace android_webview
101 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_