Send compressed histograms with system logs when sending feedback.
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer.h
blob9ae4e8ee57515a40260c88c5b5e8f98f01770db9
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 // Set the view's scroll offset cap to |new_value|.
52 virtual void SetMaxContainerViewScrollOffset(gfx::Vector2d new_value) = 0;
54 // Is a WebView-managed fling in progress?
55 virtual bool IsFlingActive() const = 0;
57 // Set the current page scale to |page_scale_factor|.
58 virtual void SetPageScaleFactor(float page_scale_factor) = 0;
60 // Set the current contents_size to |contents_size_dip|.
61 virtual void SetContentsSize(gfx::SizeF contents_size_dip) = 0;
63 // Handle overscroll.
64 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) = 0;
66 protected:
67 virtual ~Client() {}
70 // Delegate to perform rendering actions involving Java objects.
71 class JavaHelper {
72 public:
73 // Creates a RGBA_8888 Java Bitmap object of the requested size.
74 virtual base::android::ScopedJavaLocalRef<jobject> CreateBitmap(
75 JNIEnv* env,
76 int width,
77 int height,
78 const base::android::JavaRef<jobject>& jcanvas,
79 void* owner_key) = 0;
81 // Draws the provided Java Bitmap into the provided Java Canvas.
82 virtual void DrawBitmapIntoCanvas(
83 JNIEnv* env,
84 const base::android::JavaRef<jobject>& jbitmap,
85 const base::android::JavaRef<jobject>& jcanvas,
86 int x,
87 int y) = 0;
89 // Creates a Java Picture object that records drawing the provided Bitmap.
90 virtual base::android::ScopedJavaLocalRef<jobject> RecordBitmapIntoPicture(
91 JNIEnv* env,
92 const base::android::JavaRef<jobject>& jbitmap) = 0;
94 protected:
95 virtual ~JavaHelper() {}
98 // Global hookup methods.
99 static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table);
100 static AwDrawSWFunctionTable* GetAwDrawSWFunctionTable();
102 // Rendering methods.
104 // Main handler for view drawing: performs a SW draw immediately, or sets up
105 // a subsequent GL Draw (via Client::RequestDrawGL) and returns true. A false
106 // return value indicates nothing was or will be drawn.
107 // |java_canvas| is the target of the draw. |is_hardware_canvas| indicates
108 // a GL Draw maybe possible on this canvas. |scroll| if the view's current
109 // scroll offset. |clip| is the canvas's clip bounds. |visible_rect| is the
110 // intersection of the view size and the window in window coordinates.
111 virtual bool OnDraw(jobject java_canvas,
112 bool is_hardware_canvas,
113 const gfx::Vector2d& scroll,
114 const gfx::Rect& clip) = 0;
116 // Called in response to a prior Client::RequestDrawGL() call. See
117 // AwDrawGLInfo documentation for more details of the contract.
118 virtual void DrawGL(AwDrawGLInfo* draw_info) = 0;
120 // The global visible rect changed and this is the new value.
121 virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) = 0;
123 // CapturePicture API methods.
124 virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0;
125 virtual void EnableOnNewPicture(bool enabled) = 0;
127 // View update notifications.
128 virtual void SetIsPaused(bool paused) = 0;
129 virtual void SetViewVisibility(bool visible) = 0;
130 virtual void SetWindowVisibility(bool visible) = 0;
131 virtual void OnSizeChanged(int width, int height) = 0;
132 virtual void OnAttachedToWindow(int width, int height) = 0;
133 virtual void OnDetachedFromWindow() = 0;
135 // Sets the scale for logical<->physical pixel conversions.
136 virtual void SetDipScale(float dip_scale) = 0;
138 // Set the root layer scroll offset to |new_value|.
139 virtual void ScrollTo(gfx::Vector2d new_value) = 0;
141 // Android views hierarchy gluing.
142 virtual bool IsAttachedToWindow() = 0;
143 virtual bool IsVisible() = 0;
144 virtual gfx::Rect GetScreenRect() = 0;
146 // ComponentCallbacks2.onTrimMemory callback.
147 virtual void TrimMemory(int level) = 0;
149 virtual ~BrowserViewRenderer() {}
152 } // namespace android_webview
154 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_