#ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
#define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
#include "android_webview/browser/shared_renderer_state.h"
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
#include "base/cancelable_callback.h"
#include "content/public/browser/android/synchronous_compositor_client.h"
#include "skia/ext/refptr.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/vector2d_f.h"
class SkCanvas;
class SkPicture;
struct AwDrawGLInfo;
struct AwDrawSWFunctionTable;
namespace content {
class ContentViewCore;
class SynchronousCompositor;
class WebContents;
}
namespace android_webview {
class BrowserViewRendererClient;
class BrowserViewRendererJavaHelper {
public:
static BrowserViewRendererJavaHelper* GetInstance();
typedef base::Callback<bool(SkCanvas*)> RenderMethod;
virtual bool RenderViaAuxilaryBitmapIfNeeded(
jobject java_canvas,
const gfx::Vector2d& scroll_correction,
const gfx::Rect& clip,
RenderMethod render_source) = 0;
protected:
virtual ~BrowserViewRendererJavaHelper() {}
};
class BrowserViewRenderer : public content::SynchronousCompositorClient {
public:
BrowserViewRenderer(
BrowserViewRendererClient* client,
SharedRendererState* shared_renderer_state,
content::WebContents* web_contents,
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
virtual ~BrowserViewRenderer();
bool OnDraw(jobject java_canvas,
bool is_hardware_canvas,
const gfx::Vector2d& scroll,
const gfx::Rect& global_visible_rect,
const gfx::Rect& clip);
void DidDrawGL(const DrawGLResult& result);
skia::RefPtr<SkPicture> CapturePicture(int width, int height);
void EnableOnNewPicture(bool enabled);
void ClearView();
void SetIsPaused(bool paused);
void SetViewVisibility(bool visible);
void SetWindowVisibility(bool visible);
void OnSizeChanged(int width, int height);
void OnAttachedToWindow(int width, int height);
void OnDetachedFromWindow();
void SetDipScale(float dip_scale);
void ScrollTo(gfx::Vector2d new_value);
bool IsAttachedToWindow() const;
bool IsVisible() const;
gfx::Rect GetScreenRect() const;
void ForceFakeCompositeSW();
virtual void DidInitializeCompositor(
content::SynchronousCompositor* compositor) OVERRIDE;
virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor)
OVERRIDE;
virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE;
virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE;
virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css)
OVERRIDE;
virtual void DidUpdateContent() OVERRIDE;
virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE;
virtual bool IsExternalFlingActive() const OVERRIDE;
virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor,
float min_page_scale_factor,
float max_page_scale_factor)
OVERRIDE;
virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE;
virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
gfx::Vector2dF latest_overscroll_delta,
gfx::Vector2dF current_fling_velocity) OVERRIDE;
private:
void EnsureContinuousInvalidation(bool force_invalidate);
bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds);
bool CompositeSW(SkCanvas* canvas);
void DidComposite(bool force_invalidate);
void FallbackTickFired();
gfx::Vector2d max_scroll_offset() const;
std::string ToString(AwDrawGLInfo* draw_info) const;
BrowserViewRendererClient* client_;
SharedRendererState* shared_renderer_state_;
content::WebContents* web_contents_;
base::WeakPtrFactory<BrowserViewRenderer> weak_factory_on_ui_thread_;
base::WeakPtr<BrowserViewRenderer> ui_thread_weak_ptr_;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
bool has_compositor_;
bool is_paused_;
bool view_visible_;
bool window_visible_;
bool attached_to_window_;
float dip_scale_;
float page_scale_factor_;
bool on_new_picture_enable_;
bool clear_view_;
bool compositor_needs_continuous_invalidate_;
bool block_invalidates_;
base::CancelableClosure fallback_tick_;
int width_;
int height_;
DrawGLInput draw_gl_input_;
base::Lock scroll_offset_dip_lock_;
gfx::Vector2dF scroll_offset_dip_;
gfx::Vector2dF max_scroll_offset_dip_;
gfx::Vector2dF overscroll_rounding_error_;
DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
};
}
#endif