mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	Implement off-screen rendering support using delegated rendering (issue #1257).
This implementation supports both GPU compositing and software compositing (used when GPU is not supported or when passing `--disable-gpu --disable-gpu-compositing` command-line flags). GPU-accelerated features (WebGL and 3D CSS) that did not work with the previous off-screen rendering implementation do work with this implementation when GPU support is available. Rendering now operates on a per-frame basis. The frame rate is configurable via CefBrowserSettings.windowless_frame_rate up to a maximum of 60fps (potentially limited by how fast the system can generate new frames). CEF generates a bitmap from the compositor backing and passes it to CefRenderHandler::OnPaint. The previous CefRenderHandler/CefBrowserHost API for off-screen rendering has been restored mostly as-is with some minor changes: - CefBrowserHost::Invalidate no longer accepts a CefRect region argument. Instead of invalidating a specific region it now triggers generation of a new frame. - The |dirtyRects| argument to CefRenderHandler::OnPaint will now always be a single CefRect representing the whole view (frame) size. Previously, invalidated regions were listed separately. - Linux: CefBrowserHost::SendKeyEvent now expects X11 event information instead of GTK event information. See cefclient for an example of converting GTK events to the necessary format. - Sizes passed to the CefRenderHandler OnPaint and OnPopupSize methods are now already DPI scaled. Previously, the client had to perform DPI scaling. - Includes drag&drop implementation from issue #1032. - Includes unit test fixes from issue #1245. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1751 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
		| @@ -2,55 +2,127 @@ | ||||
| // reserved. Use of this source code is governed by a BSD-style license that | ||||
| // can be found in the LICENSE file. | ||||
|  | ||||
| #include <string> | ||||
|  | ||||
| #include "libcef/browser/stream_impl.h" | ||||
| #include "libcef/common/drag_data_impl.h" | ||||
| #include "base/files/file_path.h" | ||||
| #include "net/base/filename_util.h" | ||||
| #include "net/base/net_util.h" | ||||
|  | ||||
| #define CHECK_READONLY_RETURN_VOID() \ | ||||
|   if (read_only_) { \ | ||||
|     NOTREACHED() << "object is read only"; \ | ||||
|     return; \ | ||||
|   } | ||||
|  | ||||
| CefDragDataImpl::CefDragDataImpl(const content::DropData& data) | ||||
|   : data_(data) { | ||||
|     : data_(data), | ||||
|       read_only_(false) { | ||||
| } | ||||
|  | ||||
| CefDragDataImpl::CefDragDataImpl() | ||||
|     : read_only_(false) { | ||||
| } | ||||
|  | ||||
| CefRefPtr<CefDragData> CefDragData::Create() { | ||||
|   return new CefDragDataImpl(); | ||||
| } | ||||
|  | ||||
| CefRefPtr<CefDragData> CefDragDataImpl::Clone() { | ||||
|   CefDragDataImpl* drag_data = NULL; | ||||
|   { | ||||
|     AutoLock lock_scope(this); | ||||
|     drag_data = new CefDragDataImpl(data_); | ||||
|   } | ||||
|   return drag_data; | ||||
| } | ||||
|  | ||||
| bool CefDragDataImpl::IsReadOnly() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return read_only_; | ||||
| } | ||||
|  | ||||
| bool CefDragDataImpl::IsLink() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return (data_.url.is_valid() && data_.file_description_filename.empty()); | ||||
| } | ||||
|  | ||||
| bool CefDragDataImpl::IsFragment() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return (!data_.url.is_valid() && data_.file_description_filename.empty() && | ||||
|           data_.filenames.empty()); | ||||
| } | ||||
|  | ||||
| bool CefDragDataImpl::IsFile() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return (!data_.file_description_filename.empty() || !data_.filenames.empty()); | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetLinkURL() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return data_.url.spec(); | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetLinkTitle() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return data_.url_title; | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetLinkMetadata() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return data_.download_metadata; | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetFragmentText() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return data_.text.is_null() ? CefString() : CefString(data_.text.string()); | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetFragmentHtml() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return data_.html.is_null() ? CefString() : CefString(data_.html.string()); | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetFragmentBaseURL() { | ||||
|   AutoLock lock_scope(this); | ||||
|   return data_.html_base_url.spec(); | ||||
| } | ||||
|  | ||||
| CefString CefDragDataImpl::GetFileName() { | ||||
|   return data_.file_description_filename; | ||||
|   AutoLock lock_scope(this); | ||||
|   if (data_.file_description_filename.empty()) | ||||
|     return CefString(); | ||||
|  | ||||
|   base::FilePath file_name(CefString(data_.file_description_filename)); | ||||
|   // Images without ALT text will only have a file extension so we need to | ||||
|   // synthesize one from the provided extension and URL. | ||||
|   if (file_name.BaseName().RemoveExtension().empty()) { | ||||
|     CefString extension = file_name.Extension(); | ||||
|     // Retrieve the name from the URL. | ||||
|     CefString suggested_file_name = | ||||
|         net::GetSuggestedFilename(data_.url, "", "", "", "", ""); | ||||
|     file_name = base::FilePath(suggested_file_name).ReplaceExtension(extension); | ||||
|   } | ||||
|   return file_name.value(); | ||||
| } | ||||
|  | ||||
| size_t CefDragDataImpl::GetFileContents(CefRefPtr<CefStreamWriter> writer) { | ||||
|   AutoLock lock_scope(this); | ||||
|   if (data_.file_contents.empty()) | ||||
|     return 0; | ||||
|  | ||||
|   char* data = const_cast<char*>(data_.file_contents.c_str()); | ||||
|   size_t size = data_.file_contents.size(); | ||||
|  | ||||
|   if (!writer.get()) | ||||
|     return size; | ||||
|  | ||||
|   return writer->Write(data, 1, size); | ||||
| } | ||||
|  | ||||
| bool CefDragDataImpl::GetFileNames(std::vector<CefString>& names) { | ||||
|   AutoLock lock_scope(this); | ||||
|   if (data_.filenames.empty()) | ||||
|     return false; | ||||
|  | ||||
| @@ -61,3 +133,62 @@ bool CefDragDataImpl::GetFileNames(std::vector<CefString>& names) { | ||||
|  | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetLinkURL(const CefString& url) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.url = GURL(url.ToString()); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetLinkTitle(const CefString& title) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.url_title = title.ToString16(); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetLinkMetadata(const CefString& data) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.download_metadata = data.ToString16(); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetFragmentText(const CefString& text) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.text = base::NullableString16(text.ToString16(), false); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetFragmentHtml(const CefString& fragment) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.html = base::NullableString16(fragment.ToString16(), false); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetFragmentBaseURL(const CefString& fragment) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.html_base_url = GURL(fragment.ToString()); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::ResetFileContents() { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.file_contents.erase(); | ||||
|   data_.file_description_filename.erase(); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::AddFile(const CefString& path, | ||||
|                               const CefString& display_name) { | ||||
|   AutoLock lock_scope(this); | ||||
|   CHECK_READONLY_RETURN_VOID(); | ||||
|   data_.filenames.push_back(ui::FileInfo(base::FilePath(path), | ||||
|                                          base::FilePath(display_name))); | ||||
| } | ||||
|  | ||||
| void CefDragDataImpl::SetReadOnly(bool read_only) { | ||||
|   AutoLock lock_scope(this); | ||||
|   if (read_only_ == read_only) | ||||
|     return; | ||||
|  | ||||
|   read_only_ = read_only; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user