summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'gpu')
-rwxr-xr-xgpu/command_buffer/build_gles2_cmd_buffer.py8
-rw-r--r--gpu/command_buffer/client/gles2_c_lib_autogen.h4
-rw-r--r--gpu/command_buffer/client/gles2_cmd_helper_autogen.h5
-rw-r--r--gpu/command_buffer/client/gles2_demo.cc4
-rw-r--r--gpu/command_buffer/client/gles2_implementation_autogen.h4
-rw-r--r--gpu/command_buffer/common/gl_mock.h2
-rw-r--r--gpu/command_buffer/common/gles2_cmd_format_autogen.h34
-rw-r--r--gpu/command_buffer/common/gles2_cmd_format_test_autogen.h13
-rw-r--r--gpu/command_buffer/common/gles2_cmd_ids_autogen.h1
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc56
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.h9
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_autogen.h7
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_mock.h4
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc41
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h1
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc3
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h6
-rw-r--r--gpu/command_buffer/service/gpu_scheduler.cc7
-rw-r--r--gpu/command_buffer/service/gpu_scheduler.h8
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_linux.cc12
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_mac.cc8
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_win.cc12
-rw-r--r--gpu/command_buffer/service/surface_manager.cc15
-rw-r--r--gpu/command_buffer/service/surface_manager.h31
-rw-r--r--gpu/command_buffer/service/surface_manager_mock.h23
-rw-r--r--gpu/demos/framework/window.cc2
-rw-r--r--gpu/gles2_conform_support/egl/display.cc2
-rw-r--r--gpu/gpu.gyp3
28 files changed, 275 insertions, 50 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py
index cf36ade..4d8d924 100755
--- a/gpu/command_buffer/build_gles2_cmd_buffer.py
+++ b/gpu/command_buffer/build_gles2_cmd_buffer.py
@@ -214,6 +214,7 @@ GL_APICALL void GL_APIENTRY glRequestExtensionCHROMIUM (const char* exte
GL_APICALL void GL_APIENTRY glSetLatchCHROMIUM (GLuint latch_id);
GL_APICALL void GL_APIENTRY glWaitLatchCHROMIUM (GLuint latch_id);
GL_APICALL void GL_APIENTRY glRateLimitOffscreenContextCHROMIUM (void);
+GL_APICALL void GL_APIENTRY glSetSurfaceCHROMIUM (GLint surface_id);
"""
# This is the list of all commmands that will be generated and their Id.
@@ -419,6 +420,7 @@ _CMD_ID_TABLE = {
'RequestExtensionCHROMIUM': 450,
'SetLatchCHROMIUM': 451,
'WaitLatchCHROMIUM': 452,
+ 'SetSurfaceCHROMIUM': 453,
}
# This is a list of enum names and their valid values. It is used to map
@@ -1490,6 +1492,12 @@ _FUNCTION_INFO = {
'decoder_func': 'DoReleaseShaderCompiler',
'unit_test': False,
},
+ 'SetSurfaceCHROMIUM': {
+ 'decoder_func': 'DoSetSurfaceCHROMIUM',
+ 'extension': True,
+ 'chromium': True,
+ 'unit_test': False,
+ },
'ShaderBinary': {'type': 'Custom'},
'ShaderSource': {
'type': 'Manual',
diff --git a/gpu/command_buffer/client/gles2_c_lib_autogen.h b/gpu/command_buffer/client/gles2_c_lib_autogen.h
index 889a243..663d162 100644
--- a/gpu/command_buffer/client/gles2_c_lib_autogen.h
+++ b/gpu/command_buffer/client/gles2_c_lib_autogen.h
@@ -889,6 +889,10 @@ void GLES2RateLimitOffscreenContextCHROMIUM() {
GPU_CLIENT_LOG("RateLimitOffscreenContextCHROMIUM" << "(" << ")");
gles2::GetGLContext()->RateLimitOffscreenContextCHROMIUM();
}
+void GLES2SetSurfaceCHROMIUM(GLint surface_id) {
+ GPU_CLIENT_LOG("SetSurfaceCHROMIUM" << "(" << surface_id << ")");
+ gles2::GetGLContext()->SetSurfaceCHROMIUM(surface_id);
+}
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_C_LIB_AUTOGEN_H_
diff --git a/gpu/command_buffer/client/gles2_cmd_helper_autogen.h b/gpu/command_buffer/client/gles2_cmd_helper_autogen.h
index e6568da..c8deb23 100644
--- a/gpu/command_buffer/client/gles2_cmd_helper_autogen.h
+++ b/gpu/command_buffer/client/gles2_cmd_helper_autogen.h
@@ -1227,5 +1227,10 @@
c.Init(latch_id);
}
+ void SetSurfaceCHROMIUM(GLint surface_id) {
+ gles2::SetSurfaceCHROMIUM& c = GetCmdSpace<gles2::SetSurfaceCHROMIUM>();
+ c.Init(surface_id);
+ }
+
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_CMD_HELPER_AUTOGEN_H_
diff --git a/gpu/command_buffer/client/gles2_demo.cc b/gpu/command_buffer/client/gles2_demo.cc
index 78768dd..90825b09 100644
--- a/gpu/command_buffer/client/gles2_demo.cc
+++ b/gpu/command_buffer/client/gles2_demo.cc
@@ -56,7 +56,9 @@ bool GLES2Demo::Setup(void* hwnd, int32 size) {
if (!command_buffer->Initialize(size))
return NULL;
- GpuScheduler* gpu_scheduler = new GpuScheduler(command_buffer.get(), NULL);
+ GpuScheduler* gpu_scheduler = new GpuScheduler(command_buffer.get(),
+ NULL,
+ NULL);
if (!gpu_scheduler->Initialize(reinterpret_cast<HWND>(hwnd),
gfx::Size(),
gpu::gles2::DisallowedExtensions(),
diff --git a/gpu/command_buffer/client/gles2_implementation_autogen.h b/gpu/command_buffer/client/gles2_implementation_autogen.h
index 97704a1..f389920 100644
--- a/gpu/command_buffer/client/gles2_implementation_autogen.h
+++ b/gpu/command_buffer/client/gles2_implementation_autogen.h
@@ -899,5 +899,9 @@ void WaitLatchCHROMIUM(GLuint latch_id) {
void RateLimitOffscreenContextCHROMIUM();
+void SetSurfaceCHROMIUM(GLint surface_id) {
+ helper_->SetSurfaceCHROMIUM(surface_id);
+}
+
#endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_AUTOGEN_H_
diff --git a/gpu/command_buffer/common/gl_mock.h b/gpu/command_buffer/common/gl_mock.h
index 1a7e474..b91cb5b 100644
--- a/gpu/command_buffer/common/gl_mock.h
+++ b/gpu/command_buffer/common/gl_mock.h
@@ -426,6 +426,8 @@ class MockGLInterface : public GLInterface {
MOCK_METHOD1(IsFenceNV, GLboolean(GLuint fence));
MOCK_METHOD3(GetFenceivNV, void(GLuint fence, GLenum pname, GLint *params));
+
+ MOCK_METHOD1(SetSurfaceCHROMIUM, void(GLuint));
};
} // namespace gfx
diff --git a/gpu/command_buffer/common/gles2_cmd_format_autogen.h b/gpu/command_buffer/common/gles2_cmd_format_autogen.h
index 0536887..67bbc36 100644
--- a/gpu/command_buffer/common/gles2_cmd_format_autogen.h
+++ b/gpu/command_buffer/common/gles2_cmd_format_autogen.h
@@ -8979,6 +8979,40 @@ COMPILE_ASSERT(offsetof(WaitLatchCHROMIUM, header) == 0,
COMPILE_ASSERT(offsetof(WaitLatchCHROMIUM, latch_id) == 4,
OffsetOf_WaitLatchCHROMIUM_latch_id_not_4);
+struct SetSurfaceCHROMIUM {
+ typedef SetSurfaceCHROMIUM ValueType;
+ static const CommandId kCmdId = kSetSurfaceCHROMIUM;
+ static const cmd::ArgFlags kArgFlags = cmd::kFixed;
+
+ static uint32 ComputeSize() {
+ return static_cast<uint32>(sizeof(ValueType)); // NOLINT
+ }
+
+ void SetHeader() {
+ header.SetCmd<ValueType>();
+ }
+
+ void Init(GLint _surface_id) {
+ SetHeader();
+ surface_id = _surface_id;
+ }
+
+ void* Set(void* cmd, GLint _surface_id) {
+ static_cast<ValueType*>(cmd)->Init(_surface_id);
+ return NextCmdAddress<ValueType>(cmd);
+ }
+
+ gpu::CommandHeader header;
+ int32 surface_id;
+};
+
+COMPILE_ASSERT(sizeof(SetSurfaceCHROMIUM) == 8,
+ Sizeof_SetSurfaceCHROMIUM_is_not_8);
+COMPILE_ASSERT(offsetof(SetSurfaceCHROMIUM, header) == 0,
+ OffsetOf_SetSurfaceCHROMIUM_header_not_0);
+COMPILE_ASSERT(offsetof(SetSurfaceCHROMIUM, surface_id) == 4,
+ OffsetOf_SetSurfaceCHROMIUM_surface_id_not_4);
+
#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_AUTOGEN_H_
diff --git a/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h b/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
index 77660e2..0f18f94 100644
--- a/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
+++ b/gpu/command_buffer/common/gles2_cmd_format_test_autogen.h
@@ -3534,5 +3534,18 @@ TEST(GLES2FormatTest, WaitLatchCHROMIUM) {
EXPECT_EQ(static_cast<GLuint>(11), cmd.latch_id);
}
+TEST(GLES2FormatTest, SetSurfaceCHROMIUM) {
+ SetSurfaceCHROMIUM cmd = { { 0 } };
+ void* next_cmd = cmd.Set(
+ &cmd,
+ static_cast<GLint>(11));
+ EXPECT_EQ(static_cast<uint32>(SetSurfaceCHROMIUM::kCmdId),
+ cmd.header.command);
+ EXPECT_EQ(sizeof(cmd), cmd.header.size * 4u);
+ EXPECT_EQ(static_cast<char*>(next_cmd),
+ reinterpret_cast<char*>(&cmd) + sizeof(cmd));
+ EXPECT_EQ(static_cast<GLint>(11), cmd.surface_id);
+}
+
#endif // GPU_COMMAND_BUFFER_COMMON_GLES2_CMD_FORMAT_TEST_AUTOGEN_H_
diff --git a/gpu/command_buffer/common/gles2_cmd_ids_autogen.h b/gpu/command_buffer/common/gles2_cmd_ids_autogen.h
index 7566beb..5a3dc2d 100644
--- a/gpu/command_buffer/common/gles2_cmd_ids_autogen.h
+++ b/gpu/command_buffer/common/gles2_cmd_ids_autogen.h
@@ -205,6 +205,7 @@
OP(RequestExtensionCHROMIUM) /* 450 */ \
OP(SetLatchCHROMIUM) /* 451 */ \
OP(WaitLatchCHROMIUM) /* 452 */ \
+ OP(SetSurfaceCHROMIUM) /* 453 */ \
enum CommandId {
kStartPoint = cmd::kLastCommonId, // All GLES2 commands start after this.
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 25b6696..dec7c34 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -34,6 +34,7 @@
#include "gpu/command_buffer/service/renderbuffer_manager.h"
#include "gpu/command_buffer/service/shader_manager.h"
#include "gpu/command_buffer/service/shader_translator.h"
+#include "gpu/command_buffer/service/surface_manager.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/GLES2/gles2_command_buffer.h"
#include "ui/gfx/gl/gl_context.h"
@@ -661,7 +662,8 @@ bool VertexAttribManager::Enable(GLuint index, bool enable) {
class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
public GLES2Decoder {
public:
- explicit GLES2DecoderImpl(ContextGroup* group);
+ explicit GLES2DecoderImpl(SurfaceManager* surface_manager,
+ ContextGroup* group);
// Overridden from AsyncAPIInterface.
virtual Error DoCommand(unsigned int command,
@@ -672,8 +674,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
virtual const char* GetCommandName(unsigned int command_id) const;
// Overridden from GLES2Decoder.
- virtual bool Initialize(gfx::GLSurface* surface,
- gfx::GLContext* context,
+ virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
+ const scoped_refptr<gfx::GLContext>& context,
const gfx::Size& size,
const DisallowedExtensions& disallowed_extensions,
const char* allowed_extensions,
@@ -1229,6 +1231,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
void DoResizeCHROMIUM(GLuint width, GLuint height);
+ void DoSetSurfaceCHROMIUM(GLint surface_id);
+
// Gets the number of values that will be returned by glGetXXX. Returns
// false if pname is unknown.
bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values);
@@ -1339,9 +1343,12 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
#undef GLES2_CMD_OP
+ // Maps surface IDs to GLSurface.
+ gpu::SurfaceManager* surface_manager_;
+
// The GL context this decoder renders to on behalf of the client.
- scoped_ptr<gfx::GLSurface> surface_;
- scoped_ptr<gfx::GLContext> context_;
+ scoped_refptr<gfx::GLSurface> surface_;
+ scoped_refptr<gfx::GLContext> context_;
// The ContextGroup for this decoder uses to track resources.
ContextGroup::Ref group_;
@@ -1767,12 +1774,15 @@ GLenum FrameBuffer::CheckStatus() {
return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
}
-GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) {
- return new GLES2DecoderImpl(group);
+GLES2Decoder* GLES2Decoder::Create(SurfaceManager* surface_manager,
+ ContextGroup* group) {
+ return new GLES2DecoderImpl(surface_manager, group);
}
-GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group)
+GLES2DecoderImpl::GLES2DecoderImpl(SurfaceManager* surface_manager,
+ ContextGroup* group)
: GLES2Decoder(),
+ surface_manager_(surface_manager),
group_(ContextGroup::Ref(group ? group : new ContextGroup())),
error_bits_(0),
util_(0), // TODO(gman): Set to actual num compress texture formats.
@@ -1831,8 +1841,8 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group)
}
bool GLES2DecoderImpl::Initialize(
- gfx::GLSurface* surface,
- gfx::GLContext* context,
+ const scoped_refptr<gfx::GLSurface>& surface,
+ const scoped_refptr<gfx::GLContext>& context,
const gfx::Size& size,
const DisallowedExtensions& disallowed_extensions,
const char* allowed_extensions,
@@ -1842,13 +1852,15 @@ bool GLES2DecoderImpl::Initialize(
DCHECK(context);
DCHECK(!context_.get());
- // Take ownership of the GLSurface. TODO(apatrick): the decoder should not
- // own the surface. It should be possible to freely switch the surface the
- // context renders to.
- surface_.reset(surface);
+ // Take ownership of the GLSurface. TODO(apatrick): once the parent / child
+ // context is retired, the decoder should not take an initial surface as
+ // an argument to this function.
+ // Maybe create a short lived offscreen GLSurface for the purpose of
+ // initializing the decoder's GLContext.
+ surface_ = surface;
// Take ownership of the GLContext.
- context_.reset(context);
+ context_ = context;
// Keep only a weak pointer to the parent so we don't unmap its client
// frame buffer after it has been destroyed.
@@ -2567,7 +2579,7 @@ void GLES2DecoderImpl::Destroy() {
if (context_.get())
context_->Destroy();
- context_.reset();
+ context_ = NULL;
offscreen_target_frame_buffer_.reset();
offscreen_target_color_texture_.reset();
@@ -2627,6 +2639,14 @@ void GLES2DecoderImpl::DoResizeCHROMIUM(GLuint width, GLuint height) {
}
}
+void GLES2DecoderImpl::DoSetSurfaceCHROMIUM(GLint surface_id) {
+ gfx::GLSurface* surface = surface_manager_->LookupSurface(surface_id);
+ if (!surface)
+ return;
+
+ surface_ = surface;
+}
+
const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const {
if (command_id > kStartPoint && command_id < kNumCommands) {
return gles2::GetCommandName(static_cast<CommandId>(command_id));
@@ -6428,7 +6448,9 @@ error::Error GLES2DecoderImpl::HandleSetLatchCHROMIUM(
if (!latch) {
return error::kOutOfBounds;
}
- base::subtle::NoBarrier_Store(latch, 1);
+ base::subtle::Atomic32 old =
+ base::subtle::NoBarrier_CompareAndSwap(latch, 0, 1);
+ DCHECK(old == 0);
if (!latch_callback_.is_null())
latch_callback_.Run(true);
return error::kNoError;
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h
index 7236cc0..699f85e 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.h
@@ -22,6 +22,8 @@ class GLSurface;
namespace gpu {
+class SurfaceManager;
+
namespace gles2 {
class ContextGroup;
@@ -40,7 +42,8 @@ class GLES2Decoder : public CommonDecoder {
typedef error::Error Error;
// Creates a decoder.
- static GLES2Decoder* Create(ContextGroup* group);
+ static GLES2Decoder* Create(SurfaceManager* surface_manager,
+ ContextGroup* group);
virtual ~GLES2Decoder();
@@ -68,8 +71,8 @@ class GLES2Decoder : public CommonDecoder {
// parent's namespace.
// Returns:
// true if successful.
- virtual bool Initialize(gfx::GLSurface* surface,
- gfx::GLContext* context,
+ virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
+ const scoped_refptr<gfx::GLContext>& context,
const gfx::Size& size,
const DisallowedExtensions& disallowed_extensions,
const char* allowed_extensions,
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
index 2ae8a03..9f7711a 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_autogen.h
@@ -2600,5 +2600,12 @@ error::Error GLES2DecoderImpl::HandleResizeCHROMIUM(
return error::kNoError;
}
+error::Error GLES2DecoderImpl::HandleSetSurfaceCHROMIUM(
+ uint32 immediate_data_size, const gles2::SetSurfaceCHROMIUM& c) {
+ GLint surface_id = static_cast<GLint>(c.surface_id);
+ DoSetSurfaceCHROMIUM(surface_id);
+ return error::kNoError;
+}
+
#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_AUTOGEN_H_
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h
index 425fdce..f775625 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h
@@ -30,8 +30,8 @@ class MockGLES2Decoder : public GLES2Decoder {
virtual ~MockGLES2Decoder();
MOCK_METHOD8(Initialize,
- bool(gfx::GLSurface* surface,
- gfx::GLContext* context,
+ bool(const scoped_refptr<gfx::GLSurface>& surface,
+ const scoped_refptr<gfx::GLContext>& context,
const gfx::Size& size,
const DisallowedExtensions& disallowed_extensions,
const char* allowed_extensions,
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
index 298640a..274d495 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
@@ -16,6 +16,7 @@
#include "gpu/command_buffer/service/test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/gl/gl_implementation.h"
+#include "ui/gfx/gl/gl_surface_stub.h"
using ::gfx::MockGLInterface;
using ::testing::_;
@@ -2933,6 +2934,46 @@ TEST_F(GLES2DecoderTest, WaitLatch) {
EXPECT_EQ(0, latches[kLastValidLatchId]);
}
+TEST_F(GLES2DecoderTest, SetSurfaceCHROMIUMChangesSurfaceForExistentSurface) {
+ const int kSurfaceId = 1;
+ scoped_refptr<gfx::GLSurfaceStub> surface(new gfx::GLSurfaceStub);
+
+ EXPECT_CALL(*surface_manager_.get(), LookupSurface(kSurfaceId))
+ .WillOnce(Return(surface.get()))
+ .RetiresOnSaturation();
+
+ SetSurfaceCHROMIUM cmd;
+ cmd.Init(kSurfaceId);
+ EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
+
+ EXPECT_EQ(surface.get(), decoder_->GetGLSurface());
+}
+
+TEST_F(GLES2DecoderTest,
+ SetSurfaceCHROMIUMDoesNotChangeSurfaceWhenSurfaceDoesNotExist) {
+ const int kExistentSurfaceId = 1;
+ const int kNonexistentSurfaceId = 2;
+ scoped_refptr<gfx::GLSurfaceStub> surface(new gfx::GLSurfaceStub);
+
+ EXPECT_CALL(*surface_manager_.get(), LookupSurface(kExistentSurfaceId))
+ .WillOnce(Return(surface.get()))
+ .RetiresOnSaturation();
+
+ EXPECT_CALL(*surface_manager_.get(), LookupSurface(kNonexistentSurfaceId))
+ .WillOnce(Return(static_cast<gfx::GLSurface*>(NULL)))
+ .RetiresOnSaturation();
+
+ SetSurfaceCHROMIUM cmd;
+ cmd.Init(kExistentSurfaceId);
+ EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
+
+ cmd.Init(kNonexistentSurfaceId);
+ EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
+
+ EXPECT_EQ(surface.get(), decoder_->GetGLSurface());
+}
+
+
// TODO(gman): BufferData
// TODO(gman): BufferDataImmediate
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h
index 72cd0c3..94c5ffc 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_3_autogen.h
@@ -10,5 +10,6 @@
// TODO(gman): WaitLatchCHROMIUM
+// TODO(gman): SetSurfaceCHROMIUM
#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_UNITTEST_3_AUTOGEN_H_
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
index a38ab8b..7dbc98c 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
@@ -55,6 +55,7 @@ void GLES2DecoderTestBase::InitDecoder(
const char* extensions, bool has_alpha_backbuffer) {
gl_.reset(new StrictMock<MockGLInterface>());
::gfx::GLInterface::SetGLInterface(gl_.get());
+ surface_manager_.reset(new StrictMock<MockSurfaceManager>);
group_ = ContextGroup::Ref(new ContextGroup());
InSequence sequence;
@@ -133,7 +134,7 @@ void GLES2DecoderTestBase::InitDecoder(
context_ = new gfx::GLContextStub;
- decoder_.reset(GLES2Decoder::Create(group_.get()));
+ decoder_.reset(GLES2Decoder::Create(surface_manager_.get(), group_.get()));
decoder_->Initialize(
surface_, context_, surface_->GetSize(), DisallowedExtensions(),
NULL, std::vector<int32>(), NULL, 0);
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
index dc195c8..d939e4f8 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
@@ -16,6 +16,7 @@
#include "gpu/command_buffer/service/program_manager.h"
#include "gpu/command_buffer/service/renderbuffer_manager.h"
#include "gpu/command_buffer/service/shader_manager.h"
+#include "gpu/command_buffer/service/surface_manager_mock.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/GLES2/gles2_command_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -256,9 +257,10 @@ class GLES2DecoderTestBase : public testing::Test {
// Use StrictMock to make 100% sure we know how GL will be called.
scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
- gfx::GLSurfaceStub* surface_;
- gfx::GLContextStub* context_;
+ scoped_refptr<gfx::GLSurfaceStub> surface_;
+ scoped_refptr<gfx::GLContextStub> context_;
scoped_ptr<GLES2Decoder> decoder_;
+ scoped_ptr<MockSurfaceManager> surface_manager_;
GLuint client_buffer_id_;
GLuint client_framebuffer_id_;
diff --git a/gpu/command_buffer/service/gpu_scheduler.cc b/gpu/command_buffer/service/gpu_scheduler.cc
index 4c54773..151ff9a 100644
--- a/gpu/command_buffer/service/gpu_scheduler.cc
+++ b/gpu/command_buffer/service/gpu_scheduler.cc
@@ -19,6 +19,7 @@ using ::base::SharedMemory;
namespace gpu {
GpuScheduler::GpuScheduler(CommandBuffer* command_buffer,
+ SurfaceManager* surface_manager,
gles2::ContextGroup* group)
: command_buffer_(command_buffer),
commands_per_update_(100),
@@ -29,7 +30,7 @@ GpuScheduler::GpuScheduler(CommandBuffer* command_buffer,
#endif
method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(command_buffer);
- decoder_.reset(gles2::GLES2Decoder::Create(group));
+ decoder_.reset(gles2::GLES2Decoder::Create(surface_manager, group));
decoder_->set_engine(this);
}
@@ -55,8 +56,8 @@ GpuScheduler::~GpuScheduler() {
}
bool GpuScheduler::InitializeCommon(
- gfx::GLSurface* surface,
- gfx::GLContext* context,
+ const scoped_refptr<gfx::GLSurface>& surface,
+ const scoped_refptr<gfx::GLContext>& context,
const gfx::Size& size,
const gles2::DisallowedExtensions& disallowed_extensions,
const char* allowed_extensions,
diff --git a/gpu/command_buffer/service/gpu_scheduler.h b/gpu/command_buffer/service/gpu_scheduler.h
index ebbcc88..d75beae 100644
--- a/gpu/command_buffer/service/gpu_scheduler.h
+++ b/gpu/command_buffer/service/gpu_scheduler.h
@@ -40,7 +40,9 @@ class ContextGroup;
class GpuScheduler : public CommandBufferEngine {
public:
// If a group is not passed in one will be created.
- GpuScheduler(CommandBuffer* command_buffer, gles2::ContextGroup* group);
+ GpuScheduler(CommandBuffer* command_buffer,
+ SurfaceManager* surface_manager,
+ gles2::ContextGroup* group);
// This constructor is for unit tests.
GpuScheduler(CommandBuffer* command_buffer,
@@ -139,8 +141,8 @@ class GpuScheduler : public CommandBufferEngine {
protected:
// Perform common initialization. Takes ownership of GLSurface and GLContext.
bool InitializeCommon(
- gfx::GLSurface* surface,
- gfx::GLContext* context,
+ const scoped_refptr<gfx::GLSurface>& surface,
+ const scoped_refptr<gfx::GLContext>& context,
const gfx::Size& size,
const gles2::DisallowedExtensions& disallowed_extensions,
const char* allowed_extensions,
diff --git a/gpu/command_buffer/service/gpu_scheduler_linux.cc b/gpu/command_buffer/service/gpu_scheduler_linux.cc
index 3ed89e4..f1d49da 100644
--- a/gpu/command_buffer/service/gpu_scheduler_linux.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_linux.cc
@@ -31,13 +31,13 @@ bool GpuScheduler::Initialize(
}
// Create either a view or pbuffer based GLSurface.
- scoped_ptr<gfx::GLSurface> surface;
+ scoped_refptr<gfx::GLSurface> surface;
if (window) {
DCHECK(!parent_handle);
- surface.reset(gfx::GLSurface::CreateViewGLSurface(window));
+ surface = gfx::GLSurface::CreateViewGLSurface(window);
} else {
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
+ surface = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
}
if (!surface.get()) {
@@ -47,7 +47,7 @@ bool GpuScheduler::Initialize(
}
// Create a GLContext and attach the surface.
- scoped_ptr<gfx::GLContext> context(
+ scoped_refptr<gfx::GLContext> context(
gfx::GLContext::CreateGLContext(parent_context, surface.get()));
if (!context.get()) {
LOG(ERROR) << "CreateGLContext failed.\n";
@@ -55,8 +55,8 @@ bool GpuScheduler::Initialize(
return false;
}
- return InitializeCommon(surface.release(),
- context.release(),
+ return InitializeCommon(surface,
+ context,
size,
disallowed_extensions,
allowed_extensions,
diff --git a/gpu/command_buffer/service/gpu_scheduler_mac.cc b/gpu/command_buffer/service/gpu_scheduler_mac.cc
index 1e323ec..449a90f 100644
--- a/gpu/command_buffer/service/gpu_scheduler_mac.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_mac.cc
@@ -29,7 +29,7 @@ bool GpuScheduler::Initialize(
DCHECK(parent_context);
}
- scoped_ptr<gfx::GLSurface> surface(
+ scoped_refptr<gfx::GLSurface> surface(
gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
if (!surface.get()) {
LOG(ERROR) << "CreateOffscreenGLSurface failed.\n";
@@ -38,7 +38,7 @@ bool GpuScheduler::Initialize(
}
// Create a GLContext and attach the surface.
- scoped_ptr<gfx::GLContext> context(
+ scoped_refptr<gfx::GLContext> context(
gfx::GLContext::CreateGLContext(parent_context, surface.get()));
if (!context.get()) {
LOG(ERROR) << "CreateGLContext failed.\n";
@@ -66,8 +66,8 @@ bool GpuScheduler::Initialize(
}
}
- return InitializeCommon(surface.release(),
- context.release(),
+ return InitializeCommon(surface,
+ context,
size,
disallowed_extensions,
allowed_extensions,
diff --git a/gpu/command_buffer/service/gpu_scheduler_win.cc b/gpu/command_buffer/service/gpu_scheduler_win.cc
index a6dcc73..81ab10b 100644
--- a/gpu/command_buffer/service/gpu_scheduler_win.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_win.cc
@@ -32,11 +32,11 @@ bool GpuScheduler::Initialize(
}
// Create either a view or pbuffer based GLSurface.
- scoped_ptr<gfx::GLSurface> surface;
+ scoped_refptr<gfx::GLSurface> surface;
if (window) {
- surface.reset(gfx::GLSurface::CreateViewGLSurface(window));
+ surface = gfx::GLSurface::CreateViewGLSurface(window);
} else {
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
+ surface = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
}
if (!surface.get()) {
@@ -46,7 +46,7 @@ bool GpuScheduler::Initialize(
}
// Create a GLContext and attach the surface.
- scoped_ptr<gfx::GLContext> context(
+ scoped_refptr<gfx::GLContext> context(
gfx::GLContext::CreateGLContext(parent_context, surface.get()));
if (!context.get()) {
LOG(ERROR) << "CreateGLContext failed.\n";
@@ -54,8 +54,8 @@ bool GpuScheduler::Initialize(
return false;
}
- return InitializeCommon(surface.release(),
- context.release(),
+ return InitializeCommon(surface,
+ context,
size,
disallowed_extensions,
allowed_extensions,
diff --git a/gpu/command_buffer/service/surface_manager.cc b/gpu/command_buffer/service/surface_manager.cc
new file mode 100644
index 0000000..2fca939
--- /dev/null
+++ b/gpu/command_buffer/service/surface_manager.cc
@@ -0,0 +1,15 @@
+// Copyright (c) 2011 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/surface_manager.h"
+
+namespace gpu {
+
+SurfaceManager::SurfaceManager() {
+}
+
+SurfaceManager::~SurfaceManager() {
+}
+
+} // namespace gpu
diff --git a/gpu/command_buffer/service/surface_manager.h b/gpu/command_buffer/service/surface_manager.h
new file mode 100644
index 0000000..4caa4ac
--- /dev/null
+++ b/gpu/command_buffer/service/surface_manager.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2011 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.
+
+#ifndef GPU_COMMAND_BUFFER_SERVICE_SURFACE_MANAGER_H_
+#define GPU_COMMAND_BUFFER_SERVICE_SURFACE_MANAGER_H_
+
+#include "base/basictypes.h"
+
+namespace gfx {
+class GLSurface;
+}
+
+namespace gpu {
+
+// Interface used to get the GLSurface corresponding to an ID communicated
+// through the command buffer.
+class SurfaceManager {
+ public:
+ SurfaceManager();
+ virtual ~SurfaceManager();
+
+ virtual gfx::GLSurface* LookupSurface(int id) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SurfaceManager);
+};
+
+} // namespace gpu
+
+#endif // GPU_COMMAND_BUFFER_SERVICE_SURFACE_MANAGER_H_
diff --git a/gpu/command_buffer/service/surface_manager_mock.h b/gpu/command_buffer/service/surface_manager_mock.h
new file mode 100644
index 0000000..f707ed8
--- /dev/null
+++ b/gpu/command_buffer/service/surface_manager_mock.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 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.
+
+#ifndef GPU_COMMAND_BUFFER_SERVICE_SURFACE_MANAGER_MOCK_H_
+#define GPU_COMMAND_BUFFER_SERVICE_SURFACE_MANAGER_MOCK_H_
+
+#include "gpu/command_buffer/service/surface_manager.h"
+
+namespace gpu {
+
+class MockSurfaceManager : public SurfaceManager {
+ public:
+ MockSurfaceManager() {}
+ MOCK_METHOD1(LookupSurface, gfx::GLSurface*(int id));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockSurfaceManager);
+};
+
+} // namespace gpu
+
+#endif // GPU_COMMAND_BUFFER_SERVICE_SURFACE_MANAGER_MOCK_H_
diff --git a/gpu/demos/framework/window.cc b/gpu/demos/framework/window.cc
index a0eedcc..4cbfbf6 100644
--- a/gpu/demos/framework/window.cc
+++ b/gpu/demos/framework/window.cc
@@ -60,7 +60,7 @@ bool Window::CreateRenderContext(gfx::PluginWindowHandle hwnd) {
}
GpuScheduler* gpu_scheduler(
- new GpuScheduler(command_buffer.get(), NULL));
+ new GpuScheduler(command_buffer.get(), NULL, NULL));
if (!gpu_scheduler->Initialize(hwnd, gfx::Size(),
gpu::gles2::DisallowedExtensions(),
NULL, std::vector<int32>(),
diff --git a/gpu/gles2_conform_support/egl/display.cc b/gpu/gles2_conform_support/egl/display.cc
index 7bfded1..2308196 100644
--- a/gpu/gles2_conform_support/egl/display.cc
+++ b/gpu/gles2_conform_support/egl/display.cc
@@ -109,7 +109,7 @@ EGLSurface Display::CreateWindowSurface(EGLConfig config,
using gpu::GpuScheduler;
std::vector<int32> attribs;
scoped_ptr<GpuScheduler> gpu_scheduler(
- new GpuScheduler(command_buffer_.get(), NULL));
+ new GpuScheduler(command_buffer_.get(), NULL, NULL));
if (!gpu_scheduler->Initialize(
win, gfx::Size(), gpu::gles2::DisallowedExtensions(), NULL,
attribs, NULL, 0))
diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp
index f59e6f9..0a5dd31 100644
--- a/gpu/gpu.gyp
+++ b/gpu/gpu.gyp
@@ -226,6 +226,8 @@
'command_buffer/service/shader_manager.cc',
'command_buffer/service/shader_translator.h',
'command_buffer/service/shader_translator.cc',
+ 'command_buffer/service/surface_manager.cc',
+ 'command_buffer/service/surface_manager.h',
'command_buffer/service/texture_manager.h',
'command_buffer/service/texture_manager.cc',
],
@@ -293,6 +295,7 @@
'command_buffer/service/renderbuffer_manager_unittest.cc',
'command_buffer/service/shader_manager_unittest.cc',
'command_buffer/service/shader_translator_unittest.cc',
+ 'command_buffer/service/surface_manager_mock.h',
'command_buffer/service/test_helper.cc',
'command_buffer/service/test_helper.h',
'command_buffer/service/texture_manager_unittest.cc',