summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 02:28:48 +0000
committerkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 02:28:48 +0000
commit43f28f83bc268dea720843a2616058b64b3e8810 (patch)
tree3c3c4fc9c43dad15246fae82cb5b965e6b217281 /gpu
parent2d48004e1f2c8cecd015144c179f993d883aba9c (diff)
downloadchromium_src-43f28f83bc268dea720843a2616058b64b3e8810.zip
chromium_src-43f28f83bc268dea720843a2616058b64b3e8810.tar.gz
chromium_src-43f28f83bc268dea720843a2616058b64b3e8810.tar.bz2
[GPU] Get GPU process running on the mac
Initial port of GPU process / plugin to Mac OS X. Uses new IOSurface APIs and therefore currently runs only on 10.6. Alternate strategy will need to be devised for 10.5. Slight UI issues remain such as GPU plugins initially showing up in the wrong place on the page. These will be fixed in follow-on bugs. Minimal changes made to command buffer code to get it to compile on Mac OS X. Commented out use of nested anonymous namespaces in gles2_cmd_decoder.cc which were causing the linker to crash with a seg fault. Refactored gyp files so the OS test enabling the GPU plugin is in one place, common.gypi, and other files test only the variable enable_gpu. Slight change to gles2_demo_cc.cc to add some simple animation to verify that updates from the GPU plugin are reaching the screen. Changed Pepper test plugin to use 3D view by default and commented out use of audio context because of recent issues. TEST=none (ran Pepper Test Plugin with 3D view enabled) BUG=http://crbug.com/25988 Review URL: http://codereview.chromium.org/558035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37934 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r--gpu/DEPS4
-rw-r--r--gpu/command_buffer/client/gles2_demo_cc.cc40
-rw-r--r--gpu/command_buffer/common/cmd_buffer_common.cc6
-rw-r--r--gpu/command_buffer/common/cmd_buffer_common.h2
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc255
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.h6
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_mock.h1
-rw-r--r--gpu/command_buffer/service/gpu_processor.cc11
-rw-r--r--gpu/command_buffer/service/gpu_processor.h13
-rw-r--r--gpu/command_buffer/service/gpu_processor_mac.cc39
-rw-r--r--gpu/gpu.gyp16
-rw-r--r--gpu/gpu_plugin/gpu_plugin.cc4
-rw-r--r--gpu/gpu_plugin/gpu_plugin.h2
13 files changed, 381 insertions, 18 deletions
diff --git a/gpu/DEPS b/gpu/DEPS
index 2cdc222..5d1e2af 100644
--- a/gpu/DEPS
+++ b/gpu/DEPS
@@ -4,4 +4,8 @@ include_rules = [
# For gfx::PluginWindowHandle
"+app/gfx",
+
+ # For IOSurfaceSupport on Mac OS X, service-side code only.
+ # Can consider moving these files if this dependency is undesirable.
+ "+chrome/common",
]
diff --git a/gpu/command_buffer/client/gles2_demo_cc.cc b/gpu/command_buffer/client/gles2_demo_cc.cc
index 0478e32..2544f42 100644
--- a/gpu/command_buffer/client/gles2_demo_cc.cc
+++ b/gpu/command_buffer/client/gles2_demo_cc.cc
@@ -5,6 +5,7 @@
// This file is here so other GLES2 related files can have a common set of
// includes where appropriate.
+#include <math.h>
#include <GLES2/gl2.h>
#include "gpu/command_buffer/client/gles2_demo_cc.h"
@@ -13,8 +14,10 @@ namespace {
GLuint g_texture = 0;
int g_textureLoc = -1;
GLuint g_programObject = 0;
+GLuint g_worldMatrixLoc = 0;
GLuint g_vbo = 0;
GLsizei g_texCoordOffset = 0;
+int g_angle = 0;
void CheckGLError() {
GLenum error = glGetError();
@@ -49,12 +52,14 @@ GLuint LoadShader(GLenum type, const char* shaderSrc) {
void InitShaders() {
static const char* vShaderStr =
+ "uniform mat4 worldMatrix;\n"
"attribute vec3 g_Position;\n"
"attribute vec2 g_TexCoord0;\n"
"varying vec2 texCoord;\n"
"void main()\n"
"{\n"
- " gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);\n"
+ " gl_Position = worldMatrix *\n"
+ " vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);\n"
" texCoord = g_TexCoord0;\n"
"}\n";
static const char* fShaderStr =
@@ -94,6 +99,7 @@ void InitShaders() {
return;
}
g_programObject = programObject;
+ g_worldMatrixLoc = glGetUniformLocation(g_programObject, "worldMatrix");
g_textureLoc = glGetUniformLocation(g_programObject, "tex");
glGenBuffers(1, &g_vbo);
glBindBuffer(GL_ARRAY_BUFFER, g_vbo);
@@ -124,7 +130,36 @@ void InitShaders() {
CheckGLError();
}
+#define PI 3.1415926535897932384626433832795f
+
void Draw() {
+ // TODO(kbr): base the angle on time rather than on ticks
+ g_angle = (g_angle + 1) % 360;
+ // Rotate about the Z axis
+ GLfloat rot_matrix[16];
+ GLfloat cos_angle = cosf(static_cast<GLfloat>(g_angle) * PI / 180.0f);
+ GLfloat sin_angle = sinf(static_cast<GLfloat>(g_angle) * PI / 180.0f);
+ // OpenGL matrices are column-major
+ rot_matrix[0] = cos_angle;
+ rot_matrix[1] = sin_angle;
+ rot_matrix[2] = 0.0f;
+ rot_matrix[3] = 0.0f;
+
+ rot_matrix[4] = -sin_angle;
+ rot_matrix[5] = cos_angle;
+ rot_matrix[6] = 0.0f;
+ rot_matrix[7] = 0.0f;
+
+ rot_matrix[8] = 0.0f;
+ rot_matrix[9] = 0.0f;
+ rot_matrix[10] = 1.0f;
+ rot_matrix[11] = 0.0f;
+
+ rot_matrix[12] = 0.0f;
+ rot_matrix[13] = 0.0f;
+ rot_matrix[14] = 0.0f;
+ rot_matrix[15] = 1.0f;
+
// Note: the viewport is automatically set up to cover the entire Canvas.
// Clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);
@@ -132,6 +167,9 @@ void Draw() {
// Use the program object
glUseProgram(g_programObject);
CheckGLError();
+ // Set up the model matrix
+ glUniformMatrix4fv(g_worldMatrixLoc, 1, GL_FALSE, rot_matrix);
+
// Load the vertex data
glBindBuffer(GL_ARRAY_BUFFER, g_vbo);
glEnableVertexAttribArray(0);
diff --git a/gpu/command_buffer/common/cmd_buffer_common.cc b/gpu/command_buffer/common/cmd_buffer_common.cc
index 936d67c..bf965cc 100644
--- a/gpu/command_buffer/common/cmd_buffer_common.cc
+++ b/gpu/command_buffer/common/cmd_buffer_common.cc
@@ -8,8 +8,10 @@
#include "gpu/command_buffer/common/cmd_buffer_common.h"
namespace gpu {
-const int32 CommandHeader::kMaxSize = (1 << 21) - 1;
-
+#if !defined(OS_WIN)
+// gcc needs this to link, but MSVC requires it not be present
+const int32 CommandHeader::kMaxSize;
+#endif
namespace cmd {
const char* GetCommandName(CommandId command_id) {
diff --git a/gpu/command_buffer/common/cmd_buffer_common.h b/gpu/command_buffer/common/cmd_buffer_common.h
index 7ae59e7..5b23620 100644
--- a/gpu/command_buffer/common/cmd_buffer_common.h
+++ b/gpu/command_buffer/common/cmd_buffer_common.h
@@ -38,7 +38,7 @@ struct CommandHeader {
Uint32 size:21;
Uint32 command:11;
- static const int32 kMaxSize;
+ static const int32 kMaxSize = (1 << 21) - 1;
void Init(uint32 _command, int32 _size) {
DCHECK_LE(_size, kMaxSize);
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index e708a69..ddfc358 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -17,9 +17,18 @@
#include "gpu/command_buffer/service/cmd_buffer_engine.h"
#include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/command_buffer/service/gles2_cmd_validation.h"
-#if defined(OS_LINUX) && !defined(UNIT_TEST)
+#if defined(UNIT_TEST)
+#elif defined(OS_LINUX)
// XWindowWrapper is stubbed out for unit-tests.
#include "gpu/command_buffer/service/x_utils.h"
+#elif defined(OS_MACOSX)
+// The following two #includes CAN NOT go above the inclusion of
+// gl_utils.h and therefore glew.h regardless of what the Google C++
+// style guide says.
+#include <CoreFoundation/CoreFoundation.h> // NOLINT
+#include <OpenGL/OpenGL.h> // NOLINT
+#include "base/scoped_cftyperef.h"
+#include "chrome/common/io_surface_support_mac.h"
#endif
namespace gpu {
@@ -38,9 +47,11 @@ COMPILE_ASSERT(sizeof(GLsizei) == sizeof(uint32), // NOLINT
COMPILE_ASSERT(sizeof(GLfloat) == sizeof(float), // NOLINT
GLfloat_not_same_size_as_float);
-namespace {
+// TODO(kbr): the use of this anonymous namespace core dumps the
+// linker on Mac OS X 10.6 when the symbol ordering file is used
+// namespace {
-size_t GetGLTypeSize(GLenum type) {
+static size_t GetGLTypeSize(GLenum type) {
switch (type) {
case GL_BYTE:
return sizeof(GLbyte); // NOLINT
@@ -147,7 +158,7 @@ GLenum GLErrorBitToGLError(uint32 error_bit) {
}
}
-} // anonymous namespace.
+// } // anonymous namespace.
#if defined(UNIT_TEST)
GLES2Decoder::GLES2Decoder()
@@ -551,6 +562,13 @@ class GLES2DecoderImpl : public GLES2Decoder {
virtual bool MakeCurrent();
virtual uint32 GetServiceIdForTesting(uint32 client_id);
+#if !defined(UNIT_TEST) && defined(OS_MACOSX)
+ // Overridden from GLES2Decoder.
+ virtual uint64 SetWindowSize(int32 width, int32 height);
+#endif
+
+ virtual void SetSwapBuffersCallback(Callback0::Type* callback);
+
// Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used
// on glDeleteBuffers so we can make sure the user does not try to render
// with deleted buffers.
@@ -729,10 +747,25 @@ class GLES2DecoderImpl : public GLES2Decoder {
#elif defined(OS_WIN)
HDC device_context_;
HGLRC gl_context_;
+#elif defined(OS_MACOSX)
+ CGLContextObj gl_context_;
+ CGLPBufferObj pbuffer_;
+ scoped_cftyperef<CFTypeRef> io_surface_;
+ int32 surface_width_;
+ int32 surface_height_;
+ GLuint texture_;
+ GLuint fbo_;
+ GLuint depth_renderbuffer_;
+ // For tracking whether the default framebuffer / renderbuffer or
+ // ones created by the end user are currently bound
+ GLuint bound_fbo_;
+ GLuint bound_renderbuffer_;
#endif
bool anti_aliased_;
+ scoped_ptr<Callback0::Type> swap_buffers_callback_;
+
DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl);
};
@@ -754,6 +787,16 @@ GLES2DecoderImpl::GLES2DecoderImpl()
#elif defined(OS_WIN)
device_context_(NULL),
gl_context_(NULL),
+#elif defined(OS_MACOSX)
+ gl_context_(NULL),
+ pbuffer_(NULL),
+ surface_width_(0),
+ surface_height_(0),
+ texture_(0),
+ fbo_(0),
+ depth_renderbuffer_(0),
+ bound_fbo_(0),
+ bound_renderbuffer_(0),
#endif
anti_aliased_(false) {
}
@@ -790,7 +833,9 @@ bool GLES2DecoderImpl::Initialize() {
return success;
}
-namespace {
+// TODO(kbr): the use of this anonymous namespace core dumps the
+// linker on Mac OS X 10.6 when the symbol ordering file is used
+// namespace {
#if defined(UNIT_TEST)
#elif defined(OS_WIN)
@@ -1007,7 +1052,7 @@ void GLDeleteTexturesHelper(
glDeleteTextures(n, ids);
}
-} // anonymous namespace
+// } // anonymous namespace
bool GLES2DecoderImpl::MakeCurrent() {
#if defined(UNIT_TEST)
@@ -1024,6 +1069,14 @@ bool GLES2DecoderImpl::MakeCurrent() {
return true;
#elif defined(OS_LINUX)
return window()->MakeCurrent();
+#elif defined(OS_MACOSX)
+ if (CGLGetCurrentContext() != gl_context_) {
+ if (CGLSetCurrentContext(gl_context_) != kCGLNoError) {
+ DLOG(ERROR) << "Unable to make gl context current.";
+ return false;
+ }
+ }
+ return true;
#else
NOTREACHED();
return false;
@@ -1103,6 +1156,49 @@ bool GLES2DecoderImpl::InitPlatformSpecific() {
DCHECK(window());
if (!window()->Initialize())
return false;
+#elif defined(OS_MACOSX)
+ // Create a 1x1 pbuffer and associated context to bootstrap things
+ static const CGLPixelFormatAttribute attribs[] = {
+ (CGLPixelFormatAttribute) kCGLPFAPBuffer,
+ (CGLPixelFormatAttribute) 0
+ };
+ CGLPixelFormatObj pixelFormat;
+ GLint numPixelFormats;
+ if (CGLChoosePixelFormat(attribs,
+ &pixelFormat,
+ &numPixelFormats) != kCGLNoError) {
+ DLOG(ERROR) << "Error choosing pixel format.";
+ return false;
+ }
+ if (!pixelFormat) {
+ return false;
+ }
+ CGLContextObj context;
+ CGLError res = CGLCreateContext(pixelFormat, 0, &context);
+ CGLDestroyPixelFormat(pixelFormat);
+ if (res != kCGLNoError) {
+ DLOG(ERROR) << "Error creating context.";
+ return false;
+ }
+ CGLPBufferObj pbuffer;
+ if (CGLCreatePBuffer(1, 1,
+ GL_TEXTURE_2D, GL_RGBA,
+ 0, &pbuffer) != kCGLNoError) {
+ CGLDestroyContext(context);
+ DLOG(ERROR) << "Error creating pbuffer.";
+ return false;
+ }
+ if (CGLSetPBuffer(context, pbuffer, 0, 0, 0) != kCGLNoError) {
+ CGLDestroyContext(context);
+ CGLDestroyPBuffer(pbuffer);
+ DLOG(ERROR) << "Error attaching pbuffer to context.";
+ return false;
+ }
+ gl_context_ = context;
+ pbuffer_ = pbuffer;
+ // Now we're ready to handle SetWindowSize calls, which will
+ // allocate and/or reallocate the IOSurface and associated offscreen
+ // OpenGL structures for rendering.
#endif
return true;
@@ -1164,11 +1260,141 @@ bool GLES2DecoderImpl::InitGlew() {
return true;
}
+#if !defined(UNIT_TEST) && defined(OS_MACOSX)
+static void AddBooleanValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ bool value) {
+ CFDictionaryAddValue(dictionary, key,
+ (value ? kCFBooleanTrue : kCFBooleanFalse));
+}
+
+static void AddIntegerValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ int32 value) {
+ CFNumberRef number = CFNumberCreate(NULL, kCFNumberSInt32Type, &value);
+ CFDictionaryAddValue(dictionary, key, number);
+}
+
+uint64 GLES2DecoderImpl::SetWindowSize(int32 width, int32 height) {
+ if (surface_width_ == width && surface_height_ == height) {
+ // Return 0 to indicate to the caller that no new backing store
+ // allocation occurred.
+ return 0;
+ }
+
+ IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize();
+ if (!io_surface_support)
+ return 0;
+
+ if (!MakeCurrent())
+ return 0;
+
+ // GL_TEXTURE_RECTANGLE_ARB is the best supported render target on
+ // Mac OS X and is required for IOSurface interoperability.
+ GLenum target = GL_TEXTURE_RECTANGLE_ARB;
+
+ if (!texture_) {
+ // Generate the texture object.
+ glGenTextures(1, &texture_);
+ glBindTexture(target, texture_);
+ glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ // Generate and bind the framebuffer object.
+ glGenFramebuffersEXT(1, &fbo_);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_);
+ bound_fbo_ = fbo_;
+ // Generate (but don't bind) the depth buffer -- we don't need
+ // this bound in order to do offscreen rendering.
+ glGenRenderbuffersEXT(1, &depth_renderbuffer_);
+ }
+
+ // Allocate a new IOSurface, which is the GPU resource that can be
+ // shared across processes.
+ scoped_cftyperef<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(), 4);
+ AddBooleanValue(properties,
+ io_surface_support->GetKIOSurfaceIsGlobal(), true);
+ // I believe we should be able to unreference the IOSurfaces without
+ // synchronizing with the browser process because they are
+ // ultimately reference counted by the operating system.
+ io_surface_.reset(io_surface_support->IOSurfaceCreate(properties));
+
+ // Reallocate the depth buffer.
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_renderbuffer_);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
+ GL_DEPTH_COMPONENT,
+ width,
+ height);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, bound_renderbuffer_);
+
+ // Reallocate the texture object.
+ glBindTexture(target, texture_);
+ // Don't think we need to identify a plane.
+ GLuint plane = 0;
+ io_surface_support->CGLTexImageIOSurface2D(gl_context_,
+ target,
+ GL_RGBA,
+ width,
+ height,
+ GL_BGRA,
+ GL_UNSIGNED_INT_8_8_8_8_REV,
+ io_surface_.get(),
+ plane);
+
+ // Set up the frame buffer object.
+ if (bound_fbo_ != fbo_) {
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_);
+ }
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+ GL_COLOR_ATTACHMENT0_EXT,
+ target,
+ texture_,
+ 0);
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+ GL_DEPTH_ATTACHMENT_EXT,
+ GL_RENDERBUFFER_EXT,
+ depth_renderbuffer_);
+ if (bound_fbo_ != fbo_) {
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_);
+ }
+
+ surface_width_ = width;
+ surface_height_ = height;
+
+ // Now send back an identifier for the IOSurface. We originally
+ // intended to send back a mach port from IOSurfaceCreateMachPort
+ // but it looks like Chrome IPC would need to be modified to
+ // properly send mach ports between processes. For the time being we
+ // make our IOSurfaces global and send back their identifiers. On
+ // the browser process side the identifier is reconstituted into an
+ // IOSurface for on-screen rendering.
+ return io_surface_support->IOSurfaceGetID(io_surface_);
+}
+#endif // !defined(UNIT_TEST) && defined(OS_MACOSX)
+
+void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
+ swap_buffers_callback_.reset(callback);
+}
+
void GLES2DecoderImpl::Destroy() {
#if defined(UNIT_TEST)
#elif defined(OS_LINUX)
DCHECK(window());
window()->Destroy();
+#elif defined(OS_MACOSX)
+ if (gl_context_)
+ CGLDestroyContext(gl_context_);
+ if (pbuffer_)
+ CGLDestroyPBuffer(pbuffer_);
#endif
}
@@ -1332,7 +1558,18 @@ void GLES2DecoderImpl::DoSwapBuffers() {
#elif defined(OS_LINUX)
DCHECK(window());
window()->SwapBuffers();
+#elif defined(OS_MACOSX)
+ if (bound_fbo_ == fbo_) {
+ // Bind and unbind the framebuffer to make changes to the
+ // IOSurface show up in the other process.
+ glFlush();
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_);
+ }
#endif
+ if (swap_buffers_callback_.get()) {
+ swap_buffers_callback_->Run();
+ }
}
void GLES2DecoderImpl::DoUseProgram(GLuint program) {
@@ -1476,7 +1713,9 @@ error::Error GLES2DecoderImpl::HandleDrawElements(
return error::kNoError;
}
-namespace {
+// TODO(kbr): the use of this anonymous namespace core dumps the
+// linker on Mac OS X 10.6 when the symbol ordering file is used
+// namespace {
// Calls glShaderSource for the various versions of the ShaderSource command.
// Assumes that data / data_size points to a piece of memory that is in range
@@ -1505,7 +1744,7 @@ error::Error ShaderSourceHelper(
return error::kNoError;
}
-} // anonymous namespace.
+// } // anonymous namespace.
error::Error GLES2DecoderImpl::HandleShaderSource(
uint32 immediate_data_size, const gles2::ShaderSource& c) {
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h
index db91d55..9e6b9c8 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.h
@@ -11,6 +11,7 @@
#if defined(OS_WIN)
#include <windows.h>
#endif
+#include "base/task.h"
#include "gpu/command_buffer/service/common_decoder.h"
namespace gpu {
@@ -55,6 +56,8 @@ class GLES2Decoder : public CommonDecoder {
HWND hwnd() const {
return hwnd_;
}
+#elif !defined(UNIT_TEST) && defined(OS_MACOSX)
+ virtual uint64 SetWindowSize(int32 width, int32 height) = 0;
#endif
// Initializes the graphics context.
@@ -71,6 +74,9 @@ class GLES2Decoder : public CommonDecoder {
// Gets a service id by client id.
virtual uint32 GetServiceIdForTesting(uint32 client_id) = 0;
+ // Sets a callback which is called when a SwapBuffers command is processed.
+ virtual void SetSwapBuffersCallback(Callback0::Type* callback) = 0;
+
protected:
GLES2Decoder();
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h
index dba1043..fa60d41 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h
@@ -26,6 +26,7 @@ class MockGLES2Decoder : public GLES2Decoder {
MOCK_METHOD0(Destroy, void());
MOCK_METHOD0(MakeCurrent, bool());
MOCK_METHOD1(GetServiceIdForTesting, uint32(uint32 client_id));
+ MOCK_METHOD1(SetSwapBuffersCallback, void(Callback0::Type*));
MOCK_METHOD3(DoCommand, error::Error(unsigned int command,
unsigned int arg_count,
const void* cmd_data));
diff --git a/gpu/command_buffer/service/gpu_processor.cc b/gpu/command_buffer/service/gpu_processor.cc
index c9b8c6f..7272115 100644
--- a/gpu/command_buffer/service/gpu_processor.cc
+++ b/gpu/command_buffer/service/gpu_processor.cc
@@ -82,4 +82,15 @@ int32 GPUProcessor::GetGetOffset() {
return parser_->get();
}
+#if defined(OS_MACOSX)
+uint64 GPUProcessor::SetWindowSize(int32 width, int32 height) {
+ return decoder_->SetWindowSize(width, height);
+}
+#endif
+
+void GPUProcessor::SetSwapBuffersCallback(
+ Callback0::Type* callback) {
+ decoder_->SetSwapBuffersCallback(callback);
+}
+
} // namespace gpu
diff --git a/gpu/command_buffer/service/gpu_processor.h b/gpu/command_buffer/service/gpu_processor.h
index dd22ac4..f22f249 100644
--- a/gpu/command_buffer/service/gpu_processor.h
+++ b/gpu/command_buffer/service/gpu_processor.h
@@ -44,6 +44,19 @@ class GPUProcessor : public base::RefCounted<GPUProcessor>,
virtual bool SetGetOffset(int32 offset);
virtual int32 GetGetOffset();
+#if defined(OS_MACOSX)
+ // Needed only on Mac OS X, which does not render into an on-screen
+ // window and therefore requires the backing store to be resized
+ // manually. Returns an opaque identifier for the new backing store.
+ virtual uint64 SetWindowSize(int32 width, int32 height);
+
+#endif
+
+ // Sets a callback which is called when a SwapBuffers command is processed.
+ // Must be called after Initialize().
+ // It is not defined on which thread this callback is called.
+ virtual void SetSwapBuffersCallback(Callback0::Type* callback);
+
private:
// The GPUProcessor holds a weak reference to the CommandBuffer. The
// CommandBuffer owns the GPUProcessor and holds a strong reference to it
diff --git a/gpu/command_buffer/service/gpu_processor_mac.cc b/gpu/command_buffer/service/gpu_processor_mac.cc
new file mode 100644
index 0000000..a36560c
--- /dev/null
+++ b/gpu/command_buffer/service/gpu_processor_mac.cc
@@ -0,0 +1,39 @@
+// Copyright (c) 2010 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 "gpu/command_buffer/service/gpu_processor.h"
+
+using ::base::SharedMemory;
+
+namespace gpu {
+
+bool GPUProcessor::Initialize(gfx::PluginWindowHandle handle) {
+ // At this level we do not need the PluginWindowHandle. It is only
+ // needed at the CommandBufferStub level to identify which GPU
+ // plugin instance is creating a new backing store in response to a
+ // resize event.
+
+ // Map the ring buffer and create the parser.
+ Buffer ring_buffer = command_buffer_->GetRingBuffer();
+ if (ring_buffer.ptr) {
+ parser_.reset(new CommandParser(ring_buffer.ptr,
+ ring_buffer.size,
+ 0,
+ ring_buffer.size,
+ 0,
+ decoder_.get()));
+ } else {
+ parser_.reset(new CommandParser(NULL, 0, 0, 0, 0,
+ decoder_.get()));
+ }
+
+ // Initialize GAPI.
+ return decoder_->Initialize();
+}
+
+void GPUProcessor::Destroy() {
+ decoder_->Destroy();
+}
+} // namespace gpu
+
diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp
index c20338e..df0a25f 100644
--- a/gpu/gpu.gyp
+++ b/gpu/gpu.gyp
@@ -19,9 +19,6 @@
'command_buffer/service/gl_utils.h',
],
},
- 'includes': [
- '../build/common.gypi',
- ],
'targets': [
{
'target_name': 'gl_libs',
@@ -138,6 +135,12 @@
'dependencies': [
'gles2_cmd_helper',
],
+ 'all_dependent_settings': {
+ 'include_dirs': [
+ # For GLES2/gl2.h
+ 'command_buffer/common',
+ ],
+ },
'sources': [
'command_buffer/client/gles2_implementation_autogen.h',
'command_buffer/client/gles2_implementation.cc',
@@ -266,6 +269,13 @@
],
},
],
+ ['OS == "mac"',
+ {
+ 'sources': [
+ 'command_buffer/service/gpu_processor_mac.cc',
+ ],
+ },
+ ],
],
},
{
diff --git a/gpu/gpu_plugin/gpu_plugin.cc b/gpu/gpu_plugin/gpu_plugin.cc
index 5bccbe4..d274936 100644
--- a/gpu/gpu_plugin/gpu_plugin.cc
+++ b/gpu/gpu_plugin/gpu_plugin.cc
@@ -120,7 +120,7 @@ NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs) {
return NPERR_NO_ERROR;
}
-#if defined(OS_LINUX)
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs,
NPPluginFuncs* plugin_funcs) {
#else
@@ -129,7 +129,7 @@ NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs) {
if (!browser_funcs)
return NPERR_INVALID_FUNCTABLE_ERROR;
-#if defined(OS_LINUX)
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
NP_GetEntryPoints(plugin_funcs);
#endif
diff --git a/gpu/gpu_plugin/gpu_plugin.h b/gpu/gpu_plugin/gpu_plugin.h
index b6bfc89..b973d7cf 100644
--- a/gpu/gpu_plugin/gpu_plugin.h
+++ b/gpu/gpu_plugin/gpu_plugin.h
@@ -17,7 +17,7 @@ namespace gpu_plugin {
NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* funcs);
-#if defined(OS_LINUX)
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
NPError API_CALL NP_Initialize(NPNetscapeFuncs *browser_funcs,
NPPluginFuncs* plugin_funcs);
#else