Currently, bionic only build a subset of the examples. This changes turns on all...
[chromium-blink-merge.git] / mojo / examples / pepper_container_app / graphics_3d_resource.cc
blob506e74737cf970c1f40a4f1bb588a588e3c4e76b
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"
13 namespace mojo {
14 namespace examples {
16 namespace {
18 gpu::CommandBuffer::State GetErrorState() {
19 gpu::CommandBuffer::State error_state;
20 error_state.error = gpu::error::kGenericError;
21 return error_state;
24 } // namespace
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);
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() {
46 return this;
49 int32_t Graphics3DResource::GetAttribs(int32_t attrib_list[]) {
50 NOTIMPLEMENTED();
51 return PP_ERROR_FAILED;
54 int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list[]) {
55 NOTIMPLEMENTED();
56 return PP_ERROR_FAILED;
59 int32_t Graphics3DResource::GetError() {
60 NOTIMPLEMENTED();
61 return PP_ERROR_FAILED;
64 int32_t Graphics3DResource::ResizeBuffers(int32_t width, int32_t height) {
65 NOTIMPLEMENTED();
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();
75 return PP_OK;
78 int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute,
79 int32_t* value) {
80 NOTIMPLEMENTED();
81 return PP_ERROR_FAILED;
84 PP_Bool Graphics3DResource::SetGetBuffer(int32_t shm_id) {
85 NOTIMPLEMENTED();
86 return PP_FALSE;
89 scoped_refptr<gpu::Buffer> Graphics3DResource::CreateTransferBuffer(
90 uint32_t size,
91 int32* id) {
92 NOTIMPLEMENTED();
93 return NULL;
96 PP_Bool Graphics3DResource::DestroyTransferBuffer(int32_t id) {
97 NOTIMPLEMENTED();
98 return PP_FALSE;
101 PP_Bool Graphics3DResource::Flush(int32_t put_offset) {
102 NOTIMPLEMENTED();
103 return PP_FALSE;
106 gpu::CommandBuffer::State Graphics3DResource::WaitForTokenInRange(int32_t start,
107 int32_t end) {
108 NOTIMPLEMENTED();
109 return GetErrorState();
112 gpu::CommandBuffer::State Graphics3DResource::WaitForGetOffsetInRange(
113 int32_t start, int32_t end) {
114 NOTIMPLEMENTED();
115 return GetErrorState();
118 void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target,
119 GLint level,
120 GLint xoffset,
121 GLint yoffset,
122 GLsizei width,
123 GLsizei height,
124 GLenum format,
125 GLenum type,
126 GLenum access) {
127 NOTIMPLEMENTED();
128 return NULL;
131 void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem) {
132 NOTIMPLEMENTED();
135 uint32_t Graphics3DResource::InsertSyncPoint() {
136 NOTIMPLEMENTED();
137 return 0;
140 uint32_t Graphics3DResource::InsertFutureSyncPoint() {
141 NOTIMPLEMENTED();
142 return 0;
145 void Graphics3DResource::RetireSyncPoint(uint32_t sync_point) {
146 NOTIMPLEMENTED();
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());
164 if (plugin_instance)
165 plugin_instance->Graphics3DContextLost();
168 } // namespace examples
169 } // namespace mojo