Add default implementations for AppWindowRegistry::Observer notifications.
[chromium-blink-merge.git] / android_webview / browser / hardware_renderer.h
blobb290058eff410ebd136ce9dc871ab20f6f341bdf
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_
8 #include <queue>
10 #include "android_webview/browser/gl_view_renderer_manager.h"
11 #include "android_webview/browser/shared_renderer_state.h"
12 #include "base/lazy_instance.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/threading/thread_local.h"
16 struct AwDrawGLInfo;
18 namespace android_webview {
20 class AwGLSurface;
21 class BrowserViewRendererClient;
23 namespace internal {
24 class DeferredGpuCommandService;
25 } // namespace internal
27 class HardwareRenderer {
28 public:
29 explicit HardwareRenderer(SharedRendererState* state);
30 ~HardwareRenderer();
32 bool DrawGL(AwDrawGLInfo* draw_info, DrawGLResult* result);
34 private:
35 friend class internal::DeferredGpuCommandService;
37 void SetCompositorMemoryPolicy();
39 SharedRendererState* shared_renderer_state_;
41 typedef void* EGLContext;
42 EGLContext last_egl_context_;
44 scoped_refptr<AwGLSurface> gl_surface_;
46 GLViewRendererManager::Key renderer_manager_key_;
48 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer);
51 namespace internal {
53 class ScopedAllowGL {
54 public:
55 ScopedAllowGL();
56 ~ScopedAllowGL();
58 static bool IsAllowed();
60 private:
61 static base::LazyInstance<base::ThreadLocalBoolean> allow_gl;
63 DISALLOW_COPY_AND_ASSIGN(ScopedAllowGL);
66 // TODO(boliu): Teach this class about RT.
67 class DeferredGpuCommandService
68 : public gpu::InProcessCommandBuffer::Service,
69 public base::RefCountedThreadSafe<DeferredGpuCommandService> {
70 public:
71 DeferredGpuCommandService();
73 virtual void ScheduleTask(const base::Closure& task) OVERRIDE;
74 virtual void ScheduleIdleWork(const base::Closure& task) OVERRIDE;
75 virtual bool UseVirtualizedGLContexts() OVERRIDE;
76 virtual scoped_refptr<gpu::gles2::ShaderTranslatorCache>
77 shader_translator_cache() OVERRIDE;
79 void RunTasks();
81 virtual void AddRef() const OVERRIDE;
82 virtual void Release() const OVERRIDE;
84 protected:
85 virtual ~DeferredGpuCommandService();
86 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>;
88 private:
89 static void RequestProcessGLOnUIThread();
91 base::Lock tasks_lock_;
92 std::queue<base::Closure> tasks_;
94 scoped_refptr<gpu::gles2::ShaderTranslatorCache> shader_translator_cache_;
95 DISALLOW_COPY_AND_ASSIGN(DeferredGpuCommandService);
98 } // namespace internal
100 } // namespace android_webview
102 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_