Commit 6b7716f6 authored by Marshall Greenblatt's avatar Marshall Greenblatt

Windows: Add off-screen rendering support (issue #518).

- Popup menus, drag&drop and GPU acceleration are not currently supported.
- Testing is enabled in cefclient by passing the "off-screen-rendering-enabled" command-line flag.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@919 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
parent cd32e16c
......@@ -84,6 +84,8 @@
'-lcomctl32.lib',
'-lshlwapi.lib',
'-lrpcrt4.lib',
'-lopengl32.lib',
'-lglu32.lib',
],
},
'sources': [
......@@ -290,6 +292,11 @@
'.',
],
'conditions': [
[ 'OS=="win"', {
'sources': [
'tests/unittests/os_rendering_unittest.cc',
],
}],
[ 'OS=="mac"', {
'product_name': 'cef_unittests',
'dependencies': [
......@@ -936,11 +943,18 @@
['OS=="win"', {
'sources': [
'<@(includes_win)',
'libcef/browser/backing_store_osr.cc',
'libcef/browser/backing_store_osr.h',
'libcef/browser/backing_store_osr_win.cc',
'libcef/browser/browser_host_impl_win.cc',
'libcef/browser/browser_main_win.cc',
'libcef/browser/javascript_dialog_win.cc',
'libcef/browser/menu_creator_runner_win.cc',
'libcef/browser/menu_creator_runner_win.h',
'libcef/browser/render_widget_host_view_osr.h',
'libcef/browser/render_widget_host_view_osr.cc',
'libcef/browser/web_contents_view_osr.cc',
'libcef/browser/web_contents_view_osr.h',
# Include sources for context menu implementation.
'<(DEPTH)/ui/views/controls/menu/menu_2.cc',
'<(DEPTH)/ui/views/controls/menu/menu_2.h',
......
......@@ -39,6 +39,7 @@
'include/cef_process_message.h',
'include/cef_process_util.h',
'include/cef_proxy_handler.h',
'include/cef_render_handler.h',
'include/cef_render_process_handler.h',
'include/cef_request.h',
'include/cef_request_handler.h',
......@@ -86,6 +87,7 @@
'include/capi/cef_process_message_capi.h',
'include/capi/cef_process_util_capi.h',
'include/capi/cef_proxy_handler_capi.h',
'include/capi/cef_render_handler_capi.h',
'include/capi/cef_render_process_handler_capi.h',
'include/capi/cef_request_capi.h',
'include/capi/cef_request_handler_capi.h',
......@@ -194,6 +196,8 @@
'libcef_dll/cpptoc/quota_callback_cpptoc.h',
'libcef_dll/ctocpp/read_handler_ctocpp.cc',
'libcef_dll/ctocpp/read_handler_ctocpp.h',
'libcef_dll/ctocpp/render_handler_ctocpp.cc',
'libcef_dll/ctocpp/render_handler_ctocpp.h',
'libcef_dll/ctocpp/render_process_handler_ctocpp.cc',
'libcef_dll/ctocpp/render_process_handler_ctocpp.h',
'libcef_dll/cpptoc/request_cpptoc.cc',
......@@ -342,6 +346,8 @@
'libcef_dll/ctocpp/quota_callback_ctocpp.h',
'libcef_dll/cpptoc/read_handler_cpptoc.cc',
'libcef_dll/cpptoc/read_handler_cpptoc.h',
'libcef_dll/cpptoc/render_handler_cpptoc.cc',
'libcef_dll/cpptoc/render_handler_cpptoc.h',
'libcef_dll/cpptoc/render_process_handler_cpptoc.cc',
'libcef_dll/cpptoc/render_process_handler_cpptoc.h',
'libcef_dll/ctocpp/request_ctocpp.cc',
......
......@@ -118,8 +118,12 @@
],
'cefclient_sources_win': [
'tests/cefclient/cefclient.rc',
'tests/cefclient/cefclient_osr_widget_win.h',
'tests/cefclient/cefclient_osr_widget_win.cpp',
'tests/cefclient/cefclient_win.cpp',
'tests/cefclient/client_handler_win.cpp',
'tests/cefclient/osrenderer.h',
'tests/cefclient/osrenderer.cpp',
'tests/cefclient/resource.h',
'tests/cefclient/res/cefclient.ico',
'tests/cefclient/res/logoball.png',
......
......@@ -290,6 +290,69 @@ typedef struct _cef_browser_host_t {
enum cef_file_dialog_mode_t mode, const cef_string_t* title,
const cef_string_t* default_file_name, cef_string_list_t accept_types,
struct _cef_run_file_dialog_callback_t* callback);
///
// Returns true (1) if window rendering is disabled.
///
int (CEF_CALLBACK *is_window_rendering_disabled)(
struct _cef_browser_host_t* self);
///
// Notify the browser that the widget has been resized. The browser will first
// call cef_render_handler_t::GetViewRect to get the new size and then call
// cef_render_handler_t::OnPaint asynchronously with the updated regions. This
// function is only used when window rendering is disabled.
///
void (CEF_CALLBACK *was_resized)(struct _cef_browser_host_t* self);
///
// Invalidate the |dirtyRect| region of the view. The browser will call
// cef_render_handler_t::OnPaint asynchronously with the updated regions. This
// function is only used when window rendering is disabled.
///
void (CEF_CALLBACK *invalidate)(struct _cef_browser_host_t* self,
const cef_rect_t* dirtyRect);
///
// Send a key event to the browser.
///
void (CEF_CALLBACK *send_key_event)(struct _cef_browser_host_t* self,
const struct _cef_key_event_t* event);
///
// Send a mouse click event to the browser. The |x| and |y| coordinates are
// relative to the upper-left corner of the view.
///
void (CEF_CALLBACK *send_mouse_click_event)(struct _cef_browser_host_t* self,
int x, int y, enum cef_mouse_button_type_t type, int mouseUp,
int clickCount);
///
// Send a mouse move event to the browser. The |x| and |y| coordinates are
// relative to the upper-left corner of the view.
///
void (CEF_CALLBACK *send_mouse_move_event)(struct _cef_browser_host_t* self,
int x, int y, int mouseLeave);
///
// Send a mouse wheel event to the browser. The |x| and |y| coordinates are
// relative to the upper-left corner of the view. The |deltaX| and |deltaY|
// values represent the movement delta in the X and Y directions respectively.
///
void (CEF_CALLBACK *send_mouse_wheel_event)(struct _cef_browser_host_t* self,
int x, int y, int deltaX, int deltaY);
///
// Send a focus event to the browser.
///
void (CEF_CALLBACK *send_focus_event)(struct _cef_browser_host_t* self,
int setFocus);
///
// Send a capture lost event to the browser.
///
void (CEF_CALLBACK *send_capture_lost_event)(
struct _cef_browser_host_t* self);
} cef_browser_host_t;
......
......@@ -119,6 +119,12 @@ typedef struct _cef_client_t {
struct _cef_load_handler_t* (CEF_CALLBACK *get_load_handler)(
struct _cef_client_t* self);
///
// Return the handler for off-screen rendering events.
///
struct _cef_render_handler_t* (CEF_CALLBACK *get_render_handler)(
struct _cef_client_t* self);
///
// Return the handler for browser request events.
///
......
......@@ -80,7 +80,8 @@ typedef struct _cef_display_handler_t {
// text that will be displayed in the tooltip. To handle the display of the
// tooltip yourself return true (1). Otherwise, you can optionally modify
// |text| and then return false (0) to allow the browser to display the
// tooltip.
// tooltip. When window rendering is disabled the application is responsible
// for drawing tooltips and the return value is ignored.
///
int (CEF_CALLBACK *on_tooltip)(struct _cef_display_handler_t* self,
struct _cef_browser_t* browser, cef_string_t* text);
......
// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef CEF_INCLUDE_CAPI_CEF_RENDER_HANDLER_CAPI_H_
#define CEF_INCLUDE_CAPI_CEF_RENDER_HANDLER_CAPI_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "include/capi/cef_base_capi.h"
///
// Implement this structure to handle events when window rendering is disabled.
// The functions of this structure will be called on the UI thread.
///
typedef struct _cef_render_handler_t {
///
// Base structure.
///
cef_base_t base;
///
// Called to retrieve the root window rectangle in screen coordinates. Return
// true (1) if the rectangle was provided. Return false (0) if the screen
// rectangle is the same as the view rectangle.
///
int (CEF_CALLBACK *get_root_screen_rect)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, cef_rect_t* rect);
///
// Called to retrieve the view rectangle which is relative to screen
// coordinates. Return true (1) if the rectangle was provided.
///
int (CEF_CALLBACK *get_view_rect)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, cef_rect_t* rect);
///
// Called to retrieve the translation from view coordinates to actual screen
// coordinates. Return true (1) if the screen coordinates were provided.
///
int (CEF_CALLBACK *get_screen_point)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, int viewX, int viewY, int* screenX,
int* screenY);
///
// Called when the browser wants to show or hide the popup widget. The popup
// should be shown if |show| is true (1) and hidden if |show| is false (0).
// NOTE: Popup widgets are not yet supported.
///
void (CEF_CALLBACK *on_popup_show)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, int show);
///
// Called when the browser wants to move or resize the popup widget. |rect|
// contains the new location and size. NOTE: Popup widgets are not yet
// supported.
///
void (CEF_CALLBACK *on_popup_size)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, const cef_rect_t* rect);
///
// Called when an element should be painted. |type| indicates whether the
// element is the view or the popup widget. |buffer| contains the pixel data
// for the whole image. |dirtyRects| contains the set of rectangles that need
// to be repainted. On Windows |buffer| will be |width|*|height|*4 bytes in
// size and represents a BGRA image with an upper-left origin. NOTE: Popup
// widgets are not yet supported.
///
void (CEF_CALLBACK *on_paint)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, enum cef_paint_element_type_t type,
size_t dirtyRectsCount, cef_rect_t const* dirtyRects, const void* buffer,
int width, int height);
///
// Called when the browser window's cursor has changed.
///
void (CEF_CALLBACK *on_cursor_change)(struct _cef_render_handler_t* self,
struct _cef_browser_t* browser, cef_cursor_handle_t cursor);
} cef_render_handler_t;
#ifdef __cplusplus
}
#endif
#endif // CEF_INCLUDE_CAPI_CEF_RENDER_HANDLER_CAPI_H_
......@@ -211,6 +211,7 @@ class CefRunFileDialogCallback : public virtual CefBase {
class CefBrowserHost : public virtual CefBase {
public:
typedef cef_file_dialog_mode_t FileDialogMode;
typedef cef_mouse_button_type_t MouseButtonType;
///
// Create a new browser window using the window parameters specified by
......@@ -241,7 +242,7 @@ class CefBrowserHost : public virtual CefBase {
///
/*--cef()--*/
virtual CefRefPtr<CefBrowser> GetBrowser() =0;
///
// Call this method before destroying a contained browser window. This method
// performs any internal cleanup that may be needed before the browser window
......@@ -329,6 +330,70 @@ class CefBrowserHost : public virtual CefBase {
const CefString& default_file_name,
const std::vector<CefString>& accept_types,
CefRefPtr<CefRunFileDialogCallback> callback) =0;
///
// Returns true if window rendering is disabled.
///
/*--cef()--*/
virtual bool IsWindowRenderingDisabled() =0;
///
// Notify the browser that the widget has been resized. The browser will first
// call CefRenderHandler::GetViewRect to get the new size and then call
// CefRenderHandler::OnPaint asynchronously with the updated regions. This
// method is only used when window rendering is disabled.
///
/*--cef()--*/
virtual void WasResized() =0;
///
// Invalidate the |dirtyRect| region of the view. The browser will call
// CefRenderHandler::OnPaint asynchronously with the updated regions. This
// method is only used when window rendering is disabled.
///
/*--cef()--*/
virtual void Invalidate(const CefRect& dirtyRect) =0;
///
// Send a key event to the browser.
///
/*--cef()--*/
virtual void SendKeyEvent(const CefKeyEvent& event) =0;
///
// Send a mouse click event to the browser. The |x| and |y| coordinates are
// relative to the upper-left corner of the view.
///
/*--cef()--*/
virtual void SendMouseClickEvent(int x, int y, MouseButtonType type,
bool mouseUp, int clickCount) =0;
///
// Send a mouse move event to the browser. The |x| and |y| coordinates are
// relative to the upper-left corner of the view.
///
/*--cef()--*/
virtual void SendMouseMoveEvent(int x, int y, bool mouseLeave) =0;
///
// Send a mouse wheel event to the browser. The |x| and |y| coordinates are
// relative to the upper-left corner of the view. The |deltaX| and |deltaY|
// values represent the movement delta in the X and Y directions respectively.
///
/*--cef()--*/
virtual void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) =0;
///
// Send a focus event to the browser.
///
/*--cef()--*/
virtual void SendFocusEvent(bool setFocus) =0;
///
// Send a capture lost event to the browser.
///
/*--cef()--*/
virtual void SendCaptureLostEvent() =0;
};
#endif // CEF_INCLUDE_CEF_BROWSER_H_
......@@ -50,6 +50,7 @@
#include "include/cef_life_span_handler.h"
#include "include/cef_load_handler.h"
#include "include/cef_process_message.h"
#include "include/cef_render_handler.h"
#include "include/cef_request_handler.h"
///
......@@ -143,6 +144,14 @@ class CefClient : public virtual CefBase {
return NULL;
}
///
// Return the handler for off-screen rendering events.
///
/*--cef()--*/
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() {
return NULL;
}
///
// Return the handler for browser request events.
///
......
......@@ -78,6 +78,8 @@ class CefDisplayHandler : public virtual CefBase {
// text that will be displayed in the tooltip. To handle the display of the
// tooltip yourself return true. Otherwise, you can optionally modify |text|
// and then return false to allow the browser to display the tooltip.
// When window rendering is disabled the application is responsible for
// drawing tooltips and the return value is ignored.
///
/*--cef(optional_param=text)--*/
virtual bool OnTooltip(CefRefPtr<CefBrowser> browser,
......
// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// The contents of this file must follow a specific format in order to
// support the CEF translator tool. See the translator.README.txt file in the
// tools directory for more information.
//
#ifndef CEF_INCLUDE_CEF_RENDER_HANDLER_H_
#define CEF_INCLUDE_CEF_RENDER_HANDLER_H_
#pragma once
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include <vector>
///
// Implement this interface to handle events when window rendering is disabled.
// The methods of this class will be called on the UI thread.
///
/*--cef(source=client)--*/
class CefRenderHandler : public virtual CefBase {
public:
typedef cef_paint_element_type_t PaintElementType;
typedef std::vector<CefRect> RectList;
///
// Called to retrieve the root window rectangle in screen coordinates. Return
// true if the rectangle was provided. Return false if the screen rectangle is
// the same as the view rectangle.
///
/*--cef()--*/
virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) { return false; }
///
// Called to retrieve the view rectangle which is relative to screen
// coordinates. Return true if the rectangle was provided.
///
/*--cef()--*/
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) =0;
///
// Called to retrieve the translation from view coordinates to actual screen
// coordinates. Return true if the screen coordinates were provided.
///
/*--cef()--*/
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) { return false; }
///
// Called when the browser wants to show or hide the popup widget. The popup
// should be shown if |show| is true and hidden if |show| is false.
// NOTE: Popup widgets are not yet supported.
///
/*--cef()--*/
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) {}
///
// Called when the browser wants to move or resize the popup widget. |rect|
// contains the new location and size.
// NOTE: Popup widgets are not yet supported.
///
/*--cef()--*/
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) {}
///
// Called when an element should be painted. |type| indicates whether the
// element is the view or the popup widget. |buffer| contains the pixel data
// for the whole image. |dirtyRects| contains the set of rectangles that need
// to be repainted. On Windows |buffer| will be |width|*|height|*4 bytes
// in size and represents a BGRA image with an upper-left origin.
// NOTE: Popup widgets are not yet supported.
///
/*--cef()--*/
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width, int height) =0;
///
// Called when the browser window's cursor has changed.
///
/*--cef()--*/
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) {}
};
#endif // CEF_INCLUDE_CEF_RENDER_HANDLER_H_
......@@ -961,6 +961,23 @@ enum cef_menu_id_t {
MENU_ID_USER_LAST = 28500,
};
///
// Mouse button types.
///
enum cef_mouse_button_type_t {
MBT_LEFT = 0,
MBT_MIDDLE,
MBT_RIGHT,
};
///
// Paint element types.
///
enum cef_paint_element_type_t {
PET_VIEW = 0,
PET_POPUP,
};
///
// Supported event bit flags.
///
......
......@@ -43,7 +43,7 @@ extern "C" {
#endif
// Handle types.
#define cef_cursor_handle_t GtkCursor*
#define cef_cursor_handle_t void*
#define cef_event_handle_t GdkEvent*
#define cef_window_handle_t GtkWidget*
......
......@@ -69,6 +69,12 @@ typedef struct _cef_window_info_t {
cef_window_handle_t parent_window;
HMENU menu;
// If window rendering is disabled no browser window will be created. Set
// |parent_window| to be used for identifying monitor info
// (MonitorFromWindow). If |parent_window| is not provided the main screen
// monitor will be used.
BOOL window_rendering_disabled;
// Set to true to enable transparent painting.
BOOL transparent_painting;
......
......@@ -120,6 +120,7 @@ struct CefWindowInfoTraits {
target->menu = src->menu;
target->window = src->window;
target->transparent_painting = src->transparent_painting;
target->window_rendering_disabled = src->window_rendering_disabled;
}
};
......@@ -159,6 +160,11 @@ class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
void SetTransparentPainting(BOOL transparentPainting) {
transparent_painting = transparentPainting;
}
void SetAsOffScreen(HWND hWndParent) {
window_rendering_disabled = TRUE;
parent_window = hWndParent;
}
};
#endif // OS_WIN
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/backing_store_osr.h"
#include "ui/gfx/rect.h"
BackingStoreOSR::BackingStoreOSR(content::RenderWidgetHost* widget,
const gfx::Size& size)
: content::BackingStore(widget, size) {
bitmap_.Allocate(size.width(), size.height(), true);
}
void BackingStoreOSR::ScrollBackingStore(const gfx::Vector2d& delta,
const gfx::Rect& clip_rect,
const gfx::Size& view_size) {
SkIRect subset_rect = SkIRect::MakeXYWH(clip_rect.x(), clip_rect.y(),
clip_rect.width(), clip_rect.height());
bitmap_.GetBitmap().scrollRect(&subset_rect, delta.x(), delta.y());
}
const void* BackingStoreOSR::getPixels() const {
return const_cast<BackingStoreOSR*>(this)->bitmap_.GetBitmap().getPixels();
}