[Android WebView] Disable fallback ticks when paused or window invisible
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer.h
blobf54420c6422e1fe4f4c31be6a5a864125e779ce4
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_H_
6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
8 #include "base/android/scoped_java_ref.h"
9 #include "skia/ext/refptr.h"
10 #include "ui/gfx/point.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/vector2d_f.h"
14 class SkPicture;
15 struct AwDrawGLInfo;
16 struct AwDrawSWFunctionTable;
18 namespace content {
19 class ContentViewCore;
22 namespace android_webview {
24 // Interface for all the WebView-specific content rendering operations.
25 // Provides software and hardware rendering and the Capture Picture API.
26 class BrowserViewRenderer {
27 public:
28 class Client {
29 public:
30 // Request DrawGL be called. Passing null canvas implies the request
31 // will be of AwDrawGLInfo::kModeProcess type. The callback
32 // may never be made, and the mode may be promoted to kModeDraw.
33 virtual bool RequestDrawGL(jobject canvas) = 0;
35 // Called when a new Picture is available. Needs to be enabled
36 // via the EnableOnNewPicture method.
37 virtual void OnNewPicture() = 0;
39 // Called to trigger view invalidations.
40 virtual void PostInvalidate() = 0;
42 // Synchronously call back to SetGlobalVisibleRect with current value.
43 virtual void UpdateGlobalVisibleRect() = 0;
45 // Called to get view's absolute location on the screen.
46 virtual gfx::Point GetLocationOnScreen() = 0;
48 // Try to set the view's scroll offset to |new_value|.
49 virtual void ScrollContainerViewTo(gfx::Vector2d new_value) = 0;
51 // Handle overscroll.
52 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) = 0;
54 protected:
55 virtual ~Client() {}
58 // Delegate to perform rendering actions involving Java objects.
59 class JavaHelper {
60 public:
61 // Creates a RGBA_8888 Java Bitmap object of the requested size.
62 virtual base::android::ScopedJavaLocalRef<jobject> CreateBitmap(
63 JNIEnv* env,
64 int width,
65 int height,
66 const base::android::JavaRef<jobject>& jcanvas,
67 void* owner_key) = 0;
69 // Draws the provided Java Bitmap into the provided Java Canvas.
70 virtual void DrawBitmapIntoCanvas(
71 JNIEnv* env,
72 const base::android::JavaRef<jobject>& jbitmap,
73 const base::android::JavaRef<jobject>& jcanvas,
74 int x,
75 int y) = 0;
77 // Creates a Java Picture object that records drawing the provided Bitmap.
78 virtual base::android::ScopedJavaLocalRef<jobject> RecordBitmapIntoPicture(
79 JNIEnv* env,
80 const base::android::JavaRef<jobject>& jbitmap) = 0;
82 protected:
83 virtual ~JavaHelper() {}
86 // Global hookup methods.
87 static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table);
88 static AwDrawSWFunctionTable* GetAwDrawSWFunctionTable();
90 // Rendering methods.
92 // Main handler for view drawing: performs a SW draw immediately, or sets up
93 // a subsequent GL Draw (via Client::RequestDrawGL) and returns true. A false
94 // return value indicates nothing was or will be drawn.
95 // |java_canvas| is the target of the draw. |is_hardware_canvas| indicates
96 // a GL Draw maybe possible on this canvas. |scroll| if the view's current
97 // scroll offset. |clip| is the canvas's clip bounds. |visible_rect| is the
98 // intersection of the view size and the window in window coordinates.
99 virtual bool OnDraw(jobject java_canvas,
100 bool is_hardware_canvas,
101 const gfx::Vector2d& scroll,
102 const gfx::Rect& clip) = 0;
104 // Called in response to a prior Client::RequestDrawGL() call. See
105 // AwDrawGLInfo documentation for more details of the contract.
106 virtual void DrawGL(AwDrawGLInfo* draw_info) = 0;
108 // The global visible rect changed and this is the new value.
109 virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) = 0;
111 // CapturePicture API methods.
112 virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0;
113 virtual void EnableOnNewPicture(bool enabled) = 0;
115 // View update notifications.
116 virtual void SetIsPaused(bool paused) = 0;
117 virtual void SetViewVisibility(bool visible) = 0;
118 virtual void SetWindowVisibility(bool visible) = 0;
119 virtual void OnSizeChanged(int width, int height) = 0;
120 virtual void OnAttachedToWindow(int width, int height) = 0;
121 virtual void OnDetachedFromWindow() = 0;
123 // Sets the scale for logical<->physical pixel conversions.
124 virtual void SetDipScale(float dip_scale) = 0;
125 virtual void SetPageScaleFactor(float page_scale_factor) = 0;
127 // Set the root layer scroll offset to |new_value|.
128 virtual void ScrollTo(gfx::Vector2d new_value) = 0;
130 // Android views hierarchy gluing.
131 virtual bool IsAttachedToWindow() = 0;
132 virtual bool IsVisible() = 0;
133 virtual gfx::Rect GetScreenRect() = 0;
135 virtual ~BrowserViewRenderer() {}
138 } // namespace android_webview
140 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_