Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(930)

Unified Diff: content/browser/renderer_host/render_message_filter.cc

Issue 77023002: gpu: Add IOSurface backed GpuMemoryBuffer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix overflow check Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/render_message_filter.h ('k') | content/common/child_process_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_message_filter.cc
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index 10a3901eeff5b89379f634a74fee10a2d95401d1..d7962cde9848b7e02d127bc3be22f16f48b63970 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -33,6 +33,7 @@
#include "content/common/child_process_messages.h"
#include "content/common/cookie_data.h"
#include "content/common/desktop_notification_messages.h"
+#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "content/common/media/media_param_traits.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_child_process_host.h"
@@ -68,7 +69,9 @@
#include "ui/gfx/color_profile.h"
#if defined(OS_MACOSX)
+#include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
#include "content/common/mac/font_descriptor.h"
+#include "ui/gl/io_surface_support_mac.h"
#else
#include "gpu/GLES2/gl2extchromium.h"
#include "third_party/khronos/GLES2/gl2.h"
@@ -204,6 +207,23 @@ class OpenChannelToPpapiBrokerCallback
int routing_id_;
};
+#if defined(OS_MACOSX)
+void AddBooleanValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ bool value) {
+ CFDictionaryAddValue(
+ dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse);
+}
+
+void AddIntegerValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ int32 value) {
+ base::ScopedCFTypeRef<CFNumberRef> number(
+ CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
+ CFDictionaryAddValue(dictionary, key, number.get());
+}
+#endif
+
} // namespace
class RenderMessageFilter::OpenChannelToNpapiPluginCallback
@@ -1156,21 +1176,78 @@ void RenderMessageFilter::OnWebAudioMediaCodec(
#endif
void RenderMessageFilter::OnAllocateGpuMemoryBuffer(
- uint32 buffer_size,
+ uint32 width,
+ uint32 height,
+ uint32 internalformat,
gfx::GpuMemoryBufferHandle* handle) {
- // TODO(reveman): Implement allocation of real GpuMemoryBuffer.
- // Currently this function creates a fake GpuMemoryBuffer that is
- // backed by shared memory and requires an upload before it can
- // be used as a texture. The plan is to instead have this function
- // allocate a real GpuMemoryBuffer in whatever form is supported
- // by platform and drivers.
- //
- // Note: |buffer_size| likely needs to be replaced by a more
- // specific buffer description but is enough for the shared memory
- // backed GpuMemoryBuffer currently returned.
+ if (!GpuMemoryBufferImpl::IsFormatValid(internalformat)) {
+ handle->type = gfx::EMPTY_BUFFER;
+ return;
+ }
+
+#if defined(OS_MACOSX)
+ if (GpuMemoryBufferImplIOSurface::IsFormatSupported(internalformat)) {
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize();
+ if (io_surface_support) {
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> properties;
+ properties.reset(
+ CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ AddIntegerValue(properties,
+ io_surface_support->GetKIOSurfaceWidth(),
+ width);
+ AddIntegerValue(properties,
+ io_surface_support->GetKIOSurfaceHeight(),
+ height);
+ AddIntegerValue(properties,
+ io_surface_support->GetKIOSurfaceBytesPerElement(),
+ GpuMemoryBufferImpl::BytesPerPixel(internalformat));
+ AddIntegerValue(properties,
+ io_surface_support->GetKIOSurfacePixelFormat(),
+ GpuMemoryBufferImplIOSurface::PixelFormat(
+ internalformat));
+ // TODO(reveman): Remove this when using a mach_port_t to transfer
+ // IOSurface to renderer process. crbug.com/323304
+ AddBooleanValue(properties,
+ io_surface_support->GetKIOSurfaceIsGlobal(),
+ true);
+
+ base::ScopedCFTypeRef<CFTypeRef> io_surface(
+ io_surface_support->IOSurfaceCreate(properties));
+ if (io_surface) {
+ handle->type = gfx::IO_SURFACE_BUFFER;
+ handle->io_surface_id = io_surface_support->IOSurfaceGetID(io_surface);
+
+ // TODO(reveman): This makes the assumption that the renderer will
+ // grab a reference to the surface before sending another message.
+ // crbug.com/325045
+ last_io_surface_ = io_surface;
+ return;
+ }
+ }
+ }
+#endif
+
+ uint64 stride = static_cast<uint64>(width) *
+ GpuMemoryBufferImpl::BytesPerPixel(internalformat);
+ if (stride > std::numeric_limits<uint32>::max()) {
+ handle->type = gfx::EMPTY_BUFFER;
+ return;
+ }
+
+ uint64 buffer_size = stride * static_cast<uint64>(height);
+ if (buffer_size > std::numeric_limits<size_t>::max()) {
+ handle->type = gfx::EMPTY_BUFFER;
+ return;
+ }
+
+ // Fallback to fake GpuMemoryBuffer that is backed by shared memory and
+ // requires an upload before it can be used as a texture.
handle->type = gfx::SHARED_MEMORY_BUFFER;
ChildProcessHostImpl::AllocateSharedMemory(
- buffer_size, PeerHandle(), &handle->handle);
+ static_cast<size_t>(buffer_size), PeerHandle(), &handle->handle);
}
} // namespace content
« no previous file with comments | « content/browser/renderer_host/render_message_filter.h ('k') | content/common/child_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698