Index: mojo/examples/pepper_container_app/graphics_3d_resource.cc |
diff --git a/mojo/examples/pepper_container_app/graphics_3d_resource.cc b/mojo/examples/pepper_container_app/graphics_3d_resource.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e5fcd0872627bf3ae8e30402b776c94676234988 |
--- /dev/null |
+++ b/mojo/examples/pepper_container_app/graphics_3d_resource.cc |
@@ -0,0 +1,170 @@ |
+// Copyright 2014 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 "mojo/examples/pepper_container_app/graphics_3d_resource.h" |
+ |
+#include "base/logging.h" |
+#include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" |
+#include "mojo/examples/pepper_container_app/plugin_instance.h" |
+#include "mojo/public/gles2/gles2.h" |
+#include "ppapi/c/pp_errors.h" |
+ |
+namespace mojo { |
+namespace examples { |
+ |
+namespace { |
+ |
+gpu::CommandBuffer::State GetErrorState() { |
+ gpu::CommandBuffer::State error_state; |
+ error_state.error = gpu::error::kGenericError; |
+ return error_state; |
+} |
+ |
+} // namespace |
+ |
+Graphics3DResource::Graphics3DResource(PP_Instance instance) |
+ : Resource(ppapi::OBJECT_IS_IMPL, instance) { |
+ ScopedMessagePipeHandle pipe = MojoPpapiGlobals::Get()->CreateGLES2Context(); |
+ context_ = MojoGLES2CreateContext(pipe.release().value(), |
+ &ContextLostThunk, |
+ &DrawAnimationFrameThunk, |
+ this); |
+} |
+ |
+Graphics3DResource::~Graphics3DResource() { |
+ MojoGLES2DestroyContext(context_); |
+} |
+ |
+bool Graphics3DResource::IsBoundGraphics() const { |
+ PluginInstance* plugin_instance = |
+ MojoPpapiGlobals::Get()->GetInstance(pp_instance()); |
+ return plugin_instance && plugin_instance->IsBoundGraphics(pp_resource()); |
+} |
+ |
+void Graphics3DResource::BindGraphics() { |
+ MojoGLES2MakeCurrent(context_); |
+} |
+ |
+ppapi::thunk::PPB_Graphics3D_API* Graphics3DResource::AsPPB_Graphics3D_API() { |
+ return this; |
+} |
+ |
+int32_t Graphics3DResource::GetAttribs(int32_t attrib_list[]) { |
+ NOTIMPLEMENTED(); |
+ return PP_ERROR_FAILED; |
+} |
+ |
+int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list[]) { |
+ NOTIMPLEMENTED(); |
+ return PP_ERROR_FAILED; |
+} |
+ |
+int32_t Graphics3DResource::GetError() { |
+ NOTIMPLEMENTED(); |
+ return PP_ERROR_FAILED; |
+} |
+ |
+int32_t Graphics3DResource::ResizeBuffers(int32_t width, int32_t height) { |
+ NOTIMPLEMENTED(); |
+ return PP_ERROR_FAILED; |
+} |
+ |
+int32_t Graphics3DResource::SwapBuffers( |
+ scoped_refptr<ppapi::TrackedCallback> callback) { |
+ if (!IsBoundGraphics()) |
+ return PP_ERROR_FAILED; |
+ |
+ MojoGLES2SwapBuffers(); |
+ return PP_OK; |
+} |
+ |
+int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute, |
+ int32_t* value) { |
+ NOTIMPLEMENTED(); |
+ return PP_ERROR_FAILED; |
+} |
+ |
+PP_Bool Graphics3DResource::SetGetBuffer(int32_t shm_id) { |
+ NOTIMPLEMENTED(); |
+ return PP_FALSE; |
+} |
+ |
+gpu::CommandBuffer::State Graphics3DResource::GetState() { |
+ NOTIMPLEMENTED(); |
+ return GetErrorState(); |
+} |
+ |
+int32_t Graphics3DResource::CreateTransferBuffer(uint32_t size) { |
+ NOTIMPLEMENTED(); |
+ return PP_FALSE; |
+} |
+ |
+PP_Bool Graphics3DResource::DestroyTransferBuffer(int32_t id) { |
+ NOTIMPLEMENTED(); |
+ return PP_FALSE; |
+} |
+ |
+PP_Bool Graphics3DResource::GetTransferBuffer(int32_t id, |
+ int* shm_handle, |
+ uint32_t* shm_size) { |
+ NOTIMPLEMENTED(); |
+ return PP_FALSE; |
+} |
+ |
+PP_Bool Graphics3DResource::Flush(int32_t put_offset) { |
+ NOTIMPLEMENTED(); |
+ return PP_FALSE; |
+} |
+ |
+gpu::CommandBuffer::State Graphics3DResource::FlushSync(int32_t put_offset) { |
+ NOTIMPLEMENTED(); |
+ return GetErrorState(); |
+} |
+ |
+gpu::CommandBuffer::State Graphics3DResource::FlushSyncFast( |
+ int32_t put_offset, |
+ int32_t last_known_get) { |
+ NOTIMPLEMENTED(); |
+ return GetErrorState(); |
+} |
+ |
+void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target, |
+ GLint level, |
+ GLint xoffset, |
+ GLint yoffset, |
+ GLsizei width, |
+ GLsizei height, |
+ GLenum format, |
+ GLenum type, |
+ GLenum access) { |
+ NOTIMPLEMENTED(); |
+ return NULL; |
+} |
+ |
+void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+uint32_t Graphics3DResource::InsertSyncPoint() { |
+ NOTIMPLEMENTED(); |
+ return 0; |
+} |
+ |
+void Graphics3DResource::ContextLostThunk(void* closure) { |
+ static_cast<Graphics3DResource*>(closure)->ContextLost(); |
+} |
+ |
+void Graphics3DResource::DrawAnimationFrameThunk(void* closure) { |
+ // Do nothing. |
darin (slow to review)
2014/03/20 23:29:35
probably worth adding a TODO here about using this
yzshen1
2014/03/21 03:22:00
Good point. Thanks!
|
+} |
+ |
+void Graphics3DResource::ContextLost() { |
+ PluginInstance* plugin_instance = |
+ MojoPpapiGlobals::Get()->GetInstance(pp_instance()); |
+ if (plugin_instance) |
+ plugin_instance->Graphics3DContextLost(); |
+} |
+ |
+} // namespace examples |
+} // namespace mojo |