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.
5 #include "mojo/examples/pepper_container_app/graphics_3d_resource.h"
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/c/gles2/gles2.h"
11 #include "ppapi/c/pp_errors.h"
18 gpu::CommandBuffer::State
GetErrorState() {
19 gpu::CommandBuffer::State error_state
;
20 error_state
.error
= gpu::error::kGenericError
;
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(),
31 &DrawAnimationFrameThunk
,
35 bool Graphics3DResource::IsBoundGraphics() const {
36 PluginInstance
* plugin_instance
=
37 MojoPpapiGlobals::Get()->GetInstance(pp_instance());
38 return plugin_instance
&& plugin_instance
->IsBoundGraphics(pp_resource());
41 void Graphics3DResource::BindGraphics() {
42 MojoGLES2MakeCurrent(context_
);
45 ppapi::thunk::PPB_Graphics3D_API
* Graphics3DResource::AsPPB_Graphics3D_API() {
49 int32_t Graphics3DResource::GetAttribs(int32_t attrib_list
[]) {
51 return PP_ERROR_FAILED
;
54 int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list
[]) {
56 return PP_ERROR_FAILED
;
59 int32_t Graphics3DResource::GetError() {
61 return PP_ERROR_FAILED
;
64 int32_t Graphics3DResource::ResizeBuffers(int32_t width
, int32_t height
) {
66 return PP_ERROR_FAILED
;
69 int32_t Graphics3DResource::SwapBuffers(
70 scoped_refptr
<ppapi::TrackedCallback
> callback
) {
71 if (!IsBoundGraphics())
72 return PP_ERROR_FAILED
;
74 MojoGLES2SwapBuffers();
78 int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute
,
81 return PP_ERROR_FAILED
;
84 PP_Bool
Graphics3DResource::SetGetBuffer(int32_t shm_id
) {
89 scoped_refptr
<gpu::Buffer
> Graphics3DResource::CreateTransferBuffer(
96 PP_Bool
Graphics3DResource::DestroyTransferBuffer(int32_t id
) {
101 PP_Bool
Graphics3DResource::Flush(int32_t put_offset
) {
106 gpu::CommandBuffer::State
Graphics3DResource::WaitForTokenInRange(int32_t start
,
109 return GetErrorState();
112 gpu::CommandBuffer::State
Graphics3DResource::WaitForGetOffsetInRange(
113 int32_t start
, int32_t end
) {
115 return GetErrorState();
118 void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target
,
131 void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem
) {
135 uint32_t Graphics3DResource::InsertSyncPoint() {
140 uint32_t Graphics3DResource::InsertFutureSyncPoint() {
145 void Graphics3DResource::RetireSyncPoint(uint32_t sync_point
) {
149 Graphics3DResource::~Graphics3DResource() {
150 MojoGLES2DestroyContext(context_
);
153 void Graphics3DResource::ContextLostThunk(void* closure
) {
154 static_cast<Graphics3DResource
*>(closure
)->ContextLost();
157 void Graphics3DResource::DrawAnimationFrameThunk(void* closure
) {
158 // TODO(yzshen): Use this notification to drive the SwapBuffers() callback.
161 void Graphics3DResource::ContextLost() {
162 PluginInstance
* plugin_instance
=
163 MojoPpapiGlobals::Get()->GetInstance(pp_instance());
165 plugin_instance
->Graphics3DContextLost();
168 } // namespace examples