OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/examples/pepper_container_app/graphics_3d_resource.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" | |
9 #include "mojo/examples/pepper_container_app/plugin_instance.h" | |
10 #include "mojo/public/gles2/gles2.h" | |
11 #include "ppapi/c/pp_errors.h" | |
12 | |
13 namespace mojo { | |
14 namespace examples { | |
15 | |
16 namespace { | |
17 | |
18 gpu::CommandBuffer::State GetErrorState() { | |
19 gpu::CommandBuffer::State error_state; | |
20 error_state.error = gpu::error::kGenericError; | |
21 return error_state; | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 Graphics3DResource::Graphics3DResource(PP_Instance instance) | |
27 : Resource(ppapi::OBJECT_IS_IMPL, instance) { | |
28 ScopedMessagePipeHandle pipe = MojoPpapiGlobals::Get()->CreateGLES2Context(); | |
29 context_ = MojoGLES2CreateContext(pipe.release().value(), | |
30 &ContextLostThunk, | |
31 &DrawAnimationFrameThunk, | |
32 this); | |
33 } | |
34 | |
35 Graphics3DResource::~Graphics3DResource() { | |
36 MojoGLES2DestroyContext(context_); | |
37 } | |
38 | |
39 bool Graphics3DResource::IsBoundGraphics() const { | |
40 PluginInstance* plugin_instance = | |
41 MojoPpapiGlobals::Get()->GetInstance(pp_instance()); | |
42 return plugin_instance && plugin_instance->IsBoundGraphics(pp_resource()); | |
43 } | |
44 | |
45 void Graphics3DResource::BindGraphics() { | |
46 MojoGLES2MakeCurrent(context_); | |
47 } | |
48 | |
49 ppapi::thunk::PPB_Graphics3D_API* Graphics3DResource::AsPPB_Graphics3D_API() { | |
50 return this; | |
51 } | |
52 | |
53 int32_t Graphics3DResource::GetAttribs(int32_t attrib_list[]) { | |
54 NOTIMPLEMENTED(); | |
55 return PP_ERROR_FAILED; | |
56 } | |
57 | |
58 int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list[]) { | |
59 NOTIMPLEMENTED(); | |
60 return PP_ERROR_FAILED; | |
61 } | |
62 | |
63 int32_t Graphics3DResource::GetError() { | |
64 NOTIMPLEMENTED(); | |
65 return PP_ERROR_FAILED; | |
66 } | |
67 | |
68 int32_t Graphics3DResource::ResizeBuffers(int32_t width, int32_t height) { | |
69 NOTIMPLEMENTED(); | |
70 return PP_ERROR_FAILED; | |
71 } | |
72 | |
73 int32_t Graphics3DResource::SwapBuffers( | |
74 scoped_refptr<ppapi::TrackedCallback> callback) { | |
75 if (!IsBoundGraphics()) | |
76 return PP_ERROR_FAILED; | |
77 | |
78 MojoGLES2SwapBuffers(); | |
79 return PP_OK; | |
80 } | |
81 | |
82 int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute, | |
83 int32_t* value) { | |
84 NOTIMPLEMENTED(); | |
85 return PP_ERROR_FAILED; | |
86 } | |
87 | |
88 PP_Bool Graphics3DResource::SetGetBuffer(int32_t shm_id) { | |
89 NOTIMPLEMENTED(); | |
90 return PP_FALSE; | |
91 } | |
92 | |
93 gpu::CommandBuffer::State Graphics3DResource::GetState() { | |
94 NOTIMPLEMENTED(); | |
95 return GetErrorState(); | |
96 } | |
97 | |
98 int32_t Graphics3DResource::CreateTransferBuffer(uint32_t size) { | |
99 NOTIMPLEMENTED(); | |
100 return PP_FALSE; | |
101 } | |
102 | |
103 PP_Bool Graphics3DResource::DestroyTransferBuffer(int32_t id) { | |
104 NOTIMPLEMENTED(); | |
105 return PP_FALSE; | |
106 } | |
107 | |
108 PP_Bool Graphics3DResource::GetTransferBuffer(int32_t id, | |
109 int* shm_handle, | |
110 uint32_t* shm_size) { | |
111 NOTIMPLEMENTED(); | |
112 return PP_FALSE; | |
113 } | |
114 | |
115 PP_Bool Graphics3DResource::Flush(int32_t put_offset) { | |
116 NOTIMPLEMENTED(); | |
117 return PP_FALSE; | |
118 } | |
119 | |
120 gpu::CommandBuffer::State Graphics3DResource::FlushSync(int32_t put_offset) { | |
121 NOTIMPLEMENTED(); | |
122 return GetErrorState(); | |
123 } | |
124 | |
125 gpu::CommandBuffer::State Graphics3DResource::FlushSyncFast( | |
126 int32_t put_offset, | |
127 int32_t last_known_get) { | |
128 NOTIMPLEMENTED(); | |
129 return GetErrorState(); | |
130 } | |
131 | |
132 void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target, | |
133 GLint level, | |
134 GLint xoffset, | |
135 GLint yoffset, | |
136 GLsizei width, | |
137 GLsizei height, | |
138 GLenum format, | |
139 GLenum type, | |
140 GLenum access) { | |
141 NOTIMPLEMENTED(); | |
142 return NULL; | |
143 } | |
144 | |
145 void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem) { | |
146 NOTIMPLEMENTED(); | |
147 } | |
148 | |
149 uint32_t Graphics3DResource::InsertSyncPoint() { | |
150 NOTIMPLEMENTED(); | |
151 return 0; | |
152 } | |
153 | |
154 void Graphics3DResource::ContextLostThunk(void* closure) { | |
155 static_cast<Graphics3DResource*>(closure)->ContextLost(); | |
156 } | |
157 | |
158 void Graphics3DResource::DrawAnimationFrameThunk(void* closure) { | |
159 // 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!
| |
160 } | |
161 | |
162 void Graphics3DResource::ContextLost() { | |
163 PluginInstance* plugin_instance = | |
164 MojoPpapiGlobals::Get()->GetInstance(pp_instance()); | |
165 if (plugin_instance) | |
166 plugin_instance->Graphics3DContextLost(); | |
167 } | |
168 | |
169 } // namespace examples | |
170 } // namespace mojo | |
OLD | NEW |