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"
19 gpu::CommandBuffer::State
GetErrorState() {
20 gpu::CommandBuffer::State error_state
;
21 error_state
.error
= gpu::error::kGenericError
;
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(),
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() {
50 int32_t Graphics3DResource::GetAttribs(int32_t attrib_list
[]) {
52 return PP_ERROR_FAILED
;
55 int32_t Graphics3DResource::SetAttribs(const int32_t attrib_list
[]) {
57 return PP_ERROR_FAILED
;
60 int32_t Graphics3DResource::GetError() {
62 return PP_ERROR_FAILED
;
65 int32_t Graphics3DResource::ResizeBuffers(int32_t width
, int32_t height
) {
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();
79 int32_t Graphics3DResource::GetAttribMaxValue(int32_t attribute
,
82 return PP_ERROR_FAILED
;
85 PP_Bool
Graphics3DResource::SetGetBuffer(int32_t shm_id
) {
90 scoped_refptr
<gpu::Buffer
> Graphics3DResource::CreateTransferBuffer(
97 PP_Bool
Graphics3DResource::DestroyTransferBuffer(int32_t id
) {
102 PP_Bool
Graphics3DResource::Flush(int32_t put_offset
) {
107 gpu::CommandBuffer::State
Graphics3DResource::WaitForTokenInRange(int32_t start
,
110 return GetErrorState();
113 gpu::CommandBuffer::State
Graphics3DResource::WaitForGetOffsetInRange(
114 int32_t start
, int32_t end
) {
116 return GetErrorState();
119 void* Graphics3DResource::MapTexSubImage2DCHROMIUM(GLenum target
,
132 void Graphics3DResource::UnmapTexSubImage2DCHROMIUM(const void* mem
) {
136 uint32_t Graphics3DResource::InsertSyncPoint() {
141 uint32_t Graphics3DResource::InsertFutureSyncPoint() {
146 void Graphics3DResource::RetireSyncPoint(uint32_t sync_point
) {
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());
162 plugin_instance
->Graphics3DContextLost();
165 } // namespace examples