browser_view_renderer.h revision ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16
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.
4
5#ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
6#define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
7
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"
13
14class SkPicture;
15struct AwDrawGLInfo;
16struct AwDrawSWFunctionTable;
17
18namespace content {
19class ContentViewCore;
20}
21
22namespace android_webview {
23
24// Interface for all the WebView-specific content rendering operations.
25// Provides software and hardware rendering and the Capture Picture API.
26class 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;
34
35    // Called when a new Picture is available. Needs to be enabled
36    // via the EnableOnNewPicture method.
37    virtual void OnNewPicture() = 0;
38
39    // Called to trigger view invalidations.
40    virtual void PostInvalidate() = 0;
41
42    // Synchronously call back to SetGlobalVisibleRect with current value.
43    virtual void UpdateGlobalVisibleRect() = 0;
44
45    // Called to get view's absolute location on the screen.
46    virtual gfx::Point GetLocationOnScreen() = 0;
47
48    // Try to set the view's scroll offset to |new_value|.
49    virtual void ScrollContainerViewTo(gfx::Vector2d new_value) = 0;
50
51    // Handle overscroll.
52    virtual void DidOverscroll(gfx::Vector2d overscroll_delta) = 0;
53
54   protected:
55    virtual ~Client() {}
56  };
57
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;
68
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;
76
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;
81
82   protected:
83    virtual ~JavaHelper() {}
84  };
85
86  // Global hookup methods.
87  static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table);
88  static AwDrawSWFunctionTable* GetAwDrawSWFunctionTable();
89
90  // Rendering methods.
91
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;
103
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;
107
108  // The global visible rect changed and this is the new value.
109  virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) = 0;
110
111  // CapturePicture API methods.
112  virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0;
113  virtual void EnableOnNewPicture(bool enabled) = 0;
114
115  // View update notifications.
116  virtual void OnVisibilityChanged(bool visible) = 0;
117  virtual void OnSizeChanged(int width, int height) = 0;
118  virtual void OnAttachedToWindow(int width, int height) = 0;
119  virtual void OnDetachedFromWindow() = 0;
120
121  // Sets the scale for logical<->physical pixel conversions.
122  virtual void SetDipScale(float dip_scale) = 0;
123  virtual void SetPageScaleFactor(float page_scale_factor) = 0;
124
125  // Set the root layer scroll offset to |new_value|.
126  virtual void ScrollTo(gfx::Vector2d new_value) = 0;
127
128  // Android views hierarchy gluing.
129  virtual bool IsAttachedToWindow() = 0;
130  virtual bool IsViewVisible() = 0;
131  virtual gfx::Rect GetScreenRect() = 0;
132
133  virtual ~BrowserViewRenderer() {}
134};
135
136}  // namespace android_webview
137
138#endif  // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
139