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. 4 5 #ifndef ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ 7 8 #include "android_webview/browser/parent_compositor_draw_constraints.h" 9 #include "android_webview/browser/shared_renderer_state.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "cc/layers/delegated_frame_resource_collection.h" 12 #include "cc/trees/layer_tree_host_client.h" 13 #include "cc/trees/layer_tree_host_single_thread_client.h" 14 15 struct AwDrawGLInfo; 16 17 namespace cc { 18 class DelegatedFrameProvider; 19 class DelegatedRendererLayer; 20 class Layer; 21 class LayerTreeHost; 22 } 23 24 namespace android_webview { 25 26 class AwGLSurface; 27 class ParentOutputSurface; 28 29 class HardwareRenderer : public cc::LayerTreeHostClient, 30 public cc::LayerTreeHostSingleThreadClient, 31 public cc::DelegatedFrameResourceCollectionClient { 32 public: 33 explicit HardwareRenderer(SharedRendererState* state); 34 virtual ~HardwareRenderer(); 35 36 void DrawGL(bool stencil_enabled, 37 int framebuffer_binding_ext, 38 AwDrawGLInfo* draw_info); 39 void CommitFrame(); 40 41 // cc::LayerTreeHostClient overrides. 42 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} 43 virtual void DidBeginMainFrame() OVERRIDE; 44 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE {} 45 virtual void Layout() OVERRIDE {} 46 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, 47 float page_scale) OVERRIDE {} 48 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( 49 bool fallback) OVERRIDE; 50 virtual void DidInitializeOutputSurface() OVERRIDE {} 51 virtual void WillCommit() OVERRIDE {} 52 virtual void DidCommit() OVERRIDE {} 53 virtual void DidCommitAndDrawFrame() OVERRIDE {} 54 virtual void DidCompleteSwapBuffers() OVERRIDE {} 55 56 // cc::LayerTreeHostSingleThreadClient overrides. 57 virtual void ScheduleComposite() OVERRIDE {} 58 virtual void ScheduleAnimation() OVERRIDE {} 59 virtual void DidPostSwapBuffers() OVERRIDE {} 60 virtual void DidAbortSwapBuffers() OVERRIDE {} 61 62 // cc::DelegatedFrameResourceCollectionClient overrides. 63 virtual void UnusedResourcesAreAvailable() OVERRIDE; 64 65 private: 66 SharedRendererState* shared_renderer_state_; 67 68 typedef void* EGLContext; 69 EGLContext last_egl_context_; 70 71 // Information about last delegated frame. 72 gfx::Size frame_size_; 73 gfx::Vector2d scroll_offset_; 74 75 // Information from draw. 76 gfx::Size viewport_; 77 gfx::Rect clip_; 78 bool stencil_enabled_; 79 bool viewport_clip_valid_for_dcheck_; 80 81 scoped_refptr<AwGLSurface> gl_surface_; 82 83 scoped_ptr<cc::LayerTreeHost> layer_tree_host_; 84 scoped_refptr<cc::Layer> root_layer_; 85 86 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_; 87 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_; 88 scoped_refptr<cc::DelegatedRendererLayer> delegated_layer_; 89 90 // This is owned indirectly by |layer_tree_host_|. 91 ParentOutputSurface* output_surface_; 92 93 ParentCompositorDrawConstraints draw_constraints_; 94 95 DISALLOW_COPY_AND_ASSIGN(HardwareRenderer); 96 }; 97 98 } // namespace android_webview 99 100 #endif // ANDROID_WEBVIEW_BROWSER_HARDWARE_RENDERER_H_ 101