graphics_3d_resource.cc revision effb81e5f8246d0db0270817048dc992db66e9fb
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
13namespace mojo {
14namespace examples {
15
16namespace {
17
18gpu::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
26Graphics3DResource::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
35bool Graphics3DResource::IsBoundGraphics() const {
36  PluginInstance* plugin_instance =
37      MojoPpapiGlobals::Get()->GetInstance(pp_instance());
38  return plugin_instance && plugin_instance->IsBoundGraphics(pp_resource());
39}
40
41void Graphics3DResource::BindGraphics() {
42  MojoGLES2MakeCurrent(context_);
43}
44
45ppapi::thunk::PPB_Graphics3D_API* Graphics3DResource::AsPPB_Graphics3D_API() {
46  return this;
47}
48
49int32_t Graphics3DResource::GetAttribs(int32_t attrib_list[]) {
50  NOTIMPLEMENTED();
51  return PP_ERROR_FAILED;
52}
53
54int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list[]) {
55  NOTIMPLEMENTED();
56  return PP_ERROR_FAILED;
57}
58
59int32_t Graphics3DResource::GetError() {
60  NOTIMPLEMENTED();
61  return PP_ERROR_FAILED;
62}
63
64int32_t Graphics3DResource::ResizeBuffers(int32_t width, int32_t height) {
65  NOTIMPLEMENTED();
66  return PP_ERROR_FAILED;
67}
68
69int32_t Graphics3DResource::SwapBuffers(
70    scoped_refptr<ppapi::TrackedCallback> callback) {
71  if (!IsBoundGraphics())
72    return PP_ERROR_FAILED;
73
74  MojoGLES2SwapBuffers();
75  return PP_OK;
76}
77
78int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute,
79                                              int32_t* value) {
80  NOTIMPLEMENTED();
81  return PP_ERROR_FAILED;
82}
83
84PP_Bool Graphics3DResource::SetGetBuffer(int32_t shm_id) {
85  NOTIMPLEMENTED();
86  return PP_FALSE;
87}
88
89gpu::CommandBuffer::State Graphics3DResource::GetState() {
90  NOTIMPLEMENTED();
91  return GetErrorState();
92}
93
94int32_t Graphics3DResource::CreateTransferBuffer(uint32_t size) {
95  NOTIMPLEMENTED();
96  return PP_FALSE;
97}
98
99PP_Bool Graphics3DResource::DestroyTransferBuffer(int32_t id) {
100  NOTIMPLEMENTED();
101  return PP_FALSE;
102}
103
104PP_Bool Graphics3DResource::GetTransferBuffer(int32_t id,
105                                              int* shm_handle,
106                                              uint32_t* shm_size) {
107  NOTIMPLEMENTED();
108  return PP_FALSE;
109}
110
111PP_Bool Graphics3DResource::Flush(int32_t put_offset) {
112  NOTIMPLEMENTED();
113  return PP_FALSE;
114}
115
116gpu::CommandBuffer::State Graphics3DResource::WaitForTokenInRange(int32_t start,
117                                                                  int32_t end) {
118  NOTIMPLEMENTED();
119  return GetErrorState();
120}
121
122gpu::CommandBuffer::State Graphics3DResource::WaitForGetOffsetInRange(
123    int32_t start, int32_t end) {
124  NOTIMPLEMENTED();
125  return GetErrorState();
126}
127
128void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target,
129                                                   GLint level,
130                                                   GLint xoffset,
131                                                   GLint yoffset,
132                                                   GLsizei width,
133                                                   GLsizei height,
134                                                   GLenum format,
135                                                   GLenum type,
136                                                   GLenum access) {
137  NOTIMPLEMENTED();
138  return NULL;
139}
140
141void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem) {
142  NOTIMPLEMENTED();
143}
144
145uint32_t Graphics3DResource::InsertSyncPoint() {
146  NOTIMPLEMENTED();
147  return 0;
148}
149
150Graphics3DResource::~Graphics3DResource() {
151  MojoGLES2DestroyContext(context_);
152}
153
154void Graphics3DResource::ContextLostThunk(void* closure) {
155  static_cast<Graphics3DResource*>(closure)->ContextLost();
156}
157
158void Graphics3DResource::DrawAnimationFrameThunk(void* closure) {
159  // TODO(yzshen): Use this notification to drive the SwapBuffers() callback.
160}
161
162void 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
171