1 // Copyright (c) 2013 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_BROWSER_VIEW_RENDERER_IMPL_H_
6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_IMPL_H_
8 #include "android_webview/browser/browser_view_renderer.h"
9 #include "android_webview/browser/renderer_host/view_renderer_host.h"
10 #include "content/public/browser/android/compositor.h"
11 #include "content/public/browser/android/content_view_core.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "skia/ext/refptr.h"
14 #include "ui/gfx/point.h"
15 #include "ui/gfx/size.h"
16 #include "ui/gfx/size_f.h"
18 typedef void* EGLContext
;
19 struct AwDrawSWFunctionTable
;
32 namespace android_webview
{
34 class BrowserViewRendererImpl
35 : public BrowserViewRenderer
,
36 public ViewRendererHost::Client
,
37 public content::Compositor::Client
{
39 static BrowserViewRendererImpl
* Create(BrowserViewRenderer::Client
* client
,
40 JavaHelper
* java_helper
);
41 static BrowserViewRendererImpl
* FromWebContents(
42 content::WebContents
* contents
);
43 static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable
* table
);
45 virtual ~BrowserViewRendererImpl();
47 // BrowserViewRenderer implementation.
48 virtual void SetContents(
49 content::ContentViewCore
* content_view_core
) OVERRIDE
;
50 virtual void DrawGL(AwDrawGLInfo
* draw_info
) OVERRIDE
;
51 virtual void SetScrollForHWFrame(int x
, int y
) OVERRIDE
;
52 virtual bool DrawSW(jobject java_canvas
, const gfx::Rect
& clip
) OVERRIDE
;
53 virtual base::android::ScopedJavaLocalRef
<jobject
> CapturePicture() OVERRIDE
;
54 virtual void EnableOnNewPicture(OnNewPictureMode mode
) OVERRIDE
;
55 virtual void OnVisibilityChanged(
56 bool view_visible
, bool window_visible
) OVERRIDE
;
57 virtual void OnSizeChanged(int width
, int height
) OVERRIDE
;
58 virtual void OnAttachedToWindow(int width
, int height
) OVERRIDE
;
59 virtual void OnDetachedFromWindow() OVERRIDE
;
60 virtual bool IsAttachedToWindow() OVERRIDE
;
61 virtual bool IsViewVisible() OVERRIDE
;
62 virtual gfx::Rect
GetScreenRect() OVERRIDE
;
64 // content::Compositor::Client implementation.
65 virtual void ScheduleComposite() OVERRIDE
;
67 // ViewRendererHost::Client implementation.
68 virtual void OnPictureUpdated(int process_id
, int render_view_id
) OVERRIDE
;
69 virtual void OnPageScaleFactorChanged(int process_id
,
71 float page_scale_factor
) OVERRIDE
;
74 BrowserViewRendererImpl(BrowserViewRenderer::Client
* client
,
75 JavaHelper
* java_helper
);
79 friend class UserData
;
81 // Returns the latest locally available picture if any.
82 // If none is available will synchronously request the latest one
83 // and block until the result is received.
84 skia::RefPtr
<SkPicture
> GetLastCapturedPicture();
85 void OnPictureUpdated();
87 void SetCompositorVisibility(bool visible
);
88 void ResetCompositor();
90 bool RenderSW(SkCanvas
* canvas
);
91 bool RenderPicture(SkCanvas
* canvas
);
93 void OnFrameInfoUpdated(const gfx::SizeF
& content_size
,
94 const gfx::Vector2dF
& scroll_offset
,
95 float page_scale_factor
);
97 // Called when |web_contents_| is disconnected from |this| object.
98 void WebContentsGone();
100 BrowserViewRenderer::Client
* client_
;
101 BrowserViewRenderer::JavaHelper
* java_helper_
;
103 scoped_ptr
<ViewRendererHost
> view_renderer_host_
;
104 scoped_ptr
<content::Compositor
> compositor_
;
106 // Ensures content keeps clipped within the view during transformations.
107 scoped_refptr
<cc::Layer
> view_clip_layer_
;
109 // Applies the transformation matrix.
110 scoped_refptr
<cc::Layer
> transform_layer_
;
112 // Ensures content is drawn within the scissor clip rect provided by the
113 // Android framework.
114 scoped_refptr
<cc::Layer
> scissor_clip_layer_
;
116 // Last View scroll before hardware rendering is triggered.
117 gfx::Point hw_rendering_scroll_
;
121 bool compositor_visible_
;
122 bool is_composite_pending_
;
125 gfx::Size view_size_
;
126 gfx::SizeF content_size_css_
;
127 OnNewPictureMode on_new_picture_mode_
;
129 // Used only for detecting Android View System context changes.
130 // Not to be used between draw calls.
131 EGLContext last_frame_context_
;
133 // Set via SetContents. Used to recognize updates to the local WebView.
134 content::WebContents
* web_contents_
;
136 // Used to observe frame metadata updates.
137 content::ContentViewCore::UpdateFrameInfoCallback update_frame_info_callback_
;
139 bool prevent_client_invalidate_
;
141 DISALLOW_COPY_AND_ASSIGN(BrowserViewRendererImpl
);
144 } // namespace android_webview
146 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_IMPL_H_