Introduce new SPDY Version UMA histogram.
[chromium-blink-merge.git] / mojo / examples / pepper_container_app / graphics_3d_resource.cc
blobef6bd76911b63c2697c794ba7f1f4c9f904ebde9
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 "mojo/public/cpp/environment/environment.h"
12 #include "ppapi/c/pp_errors.h"
14 namespace mojo {
15 namespace examples {
17 namespace {
19 gpu::CommandBuffer::State GetErrorState() {
20 gpu::CommandBuffer::State error_state;
21 error_state.error = gpu::error::kGenericError;
22 return error_state;
25 } // namespace
27 Graphics3DResource::Graphics3DResource(PP_Instance instance)
28 : Resource(ppapi::OBJECT_IS_IMPL, instance) {
29 ScopedMessagePipeHandle pipe = MojoPpapiGlobals::Get()->CreateGLES2Context();
30 context_ = MojoGLES2CreateContext(pipe.release().value(),
31 &ContextLostThunk,
32 this,
33 Environment::GetDefaultAsyncWaiter());
36 bool Graphics3DResource::IsBoundGraphics() const {
37 PluginInstance* plugin_instance =
38 MojoPpapiGlobals::Get()->GetInstance(pp_instance());
39 return plugin_instance && plugin_instance->IsBoundGraphics(pp_resource());
42 void Graphics3DResource::BindGraphics() {
43 MojoGLES2MakeCurrent(context_);
46 ppapi::thunk::PPB_Graphics3D_API* Graphics3DResource::AsPPB_Graphics3D_API() {
47 return this;
50 int32_t Graphics3DResource::GetAttribs(int32_t attrib_list[]) {
51 NOTIMPLEMENTED();
52 return PP_ERROR_FAILED;
55 int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list[]) {
56 NOTIMPLEMENTED();
57 return PP_ERROR_FAILED;
60 int32_t Graphics3DResource::GetError() {
61 NOTIMPLEMENTED();
62 return PP_ERROR_FAILED;
65 int32_t Graphics3DResource::ResizeBuffers(int32_t width, int32_t height) {
66 NOTIMPLEMENTED();
67 return PP_ERROR_FAILED;
70 int32_t Graphics3DResource::SwapBuffers(
71 scoped_refptr<ppapi::TrackedCallback> callback) {
72 if (!IsBoundGraphics())
73 return PP_ERROR_FAILED;
75 MojoGLES2SwapBuffers();
76 return PP_OK;
79 int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute,
80 int32_t* value) {
81 NOTIMPLEMENTED();
82 return PP_ERROR_FAILED;
85 PP_Bool Graphics3DResource::SetGetBuffer(int32_t shm_id) {
86 NOTIMPLEMENTED();
87 return PP_FALSE;
90 scoped_refptr<gpu::Buffer> Graphics3DResource::CreateTransferBuffer(
91 uint32_t size,
92 int32* id) {
93 NOTIMPLEMENTED();
94 return NULL;
97 PP_Bool Graphics3DResource::DestroyTransferBuffer(int32_t id) {
98 NOTIMPLEMENTED();
99 return PP_FALSE;
102 PP_Bool Graphics3DResource::Flush(int32_t put_offset) {
103 NOTIMPLEMENTED();
104 return PP_FALSE;
107 gpu::CommandBuffer::State Graphics3DResource::WaitForTokenInRange(int32_t start,
108 int32_t end) {
109 NOTIMPLEMENTED();
110 return GetErrorState();
113 gpu::CommandBuffer::State Graphics3DResource::WaitForGetOffsetInRange(
114 int32_t start, int32_t end) {
115 NOTIMPLEMENTED();
116 return GetErrorState();
119 void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target,
120 GLint level,
121 GLint xoffset,
122 GLint yoffset,
123 GLsizei width,
124 GLsizei height,
125 GLenum format,
126 GLenum type,
127 GLenum access) {
128 NOTIMPLEMENTED();
129 return NULL;
132 void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem) {
133 NOTIMPLEMENTED();
136 uint32_t Graphics3DResource::InsertSyncPoint() {
137 NOTIMPLEMENTED();
138 return 0;
141 uint32_t Graphics3DResource::InsertFutureSyncPoint() {
142 NOTIMPLEMENTED();
143 return 0;
146 void Graphics3DResource::RetireSyncPoint(uint32_t sync_point) {
147 NOTIMPLEMENTED();
150 Graphics3DResource::~Graphics3DResource() {
151 MojoGLES2DestroyContext(context_);
154 void Graphics3DResource::ContextLostThunk(void* closure) {
155 static_cast<Graphics3DResource*>(closure)->ContextLost();
158 void Graphics3DResource::ContextLost() {
159 PluginInstance* plugin_instance =
160 MojoPpapiGlobals::Get()->GetInstance(pp_instance());
161 if (plugin_instance)
162 plugin_instance->Graphics3DContextLost();
165 } // namespace examples
166 } // namespace mojo