Extended the iOS platform policy loader to load an additional key.
[chromium-blink-merge.git] / android_webview / browser / hardware_renderer.h
blob13800e42e53903852359e0b131541af4a7152720
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/memory/ref_counted.h"
13 #include "content/public/browser/android/synchronous_compositor.h"
15 struct AwDrawGLInfo;
17 namespace android_webview {
19 class AwGLSurface;
20 class BrowserViewRendererClient;
22 namespace internal {
23 class DeferredGpuCommandService;
24 } // namespace internal
26 class HardwareRenderer {
27 public:
28 explicit HardwareRenderer(SharedRendererState* state);
29 ~HardwareRenderer();
31 static void CalculateTileMemoryPolicy();
33 bool DrawGL(AwDrawGLInfo* draw_info, DrawGLResult* result);
34 bool TrimMemory(int level, bool visible);
36 private:
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);
54 namespace internal {
56 class ScopedAllowGL {
57 public:
58 ScopedAllowGL();
59 ~ScopedAllowGL();
61 static bool IsAllowed();
63 private:
64 static bool allow_gl;
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> {
73 public:
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;
80 void RunTasks();
82 virtual void AddRef() const OVERRIDE;
83 virtual void Release() const OVERRIDE;
85 protected:
86 virtual ~DeferredGpuCommandService();
87 friend class base::RefCountedThreadSafe<DeferredGpuCommandService>;
89 private:
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_