blob: 482cb4cf03550cc603ff4ac4e88aa1ed91451df1 [file] [log] [blame]
[email protected]06b73aa2012-01-27 23:06:191// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]eeb4e4a2011-07-19 16:22:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_
6#define PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_
7
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "ppapi/c/pp_completion_callback.h"
[email protected]f0a04c42011-08-26 22:43:2011#include "ppapi/shared_impl/ppapi_shared_export.h"
[email protected]614888b2012-01-05 06:18:1212#include "ppapi/shared_impl/resource.h"
13#include "ppapi/shared_impl/tracked_callback.h"
[email protected]eeb4e4a2011-07-19 16:22:0614#include "ppapi/thunk/ppb_graphics_3d_api.h"
15
16namespace gpu {
17class CommandBuffer;
[email protected]06b73aa2012-01-27 23:06:1918class TransferBuffer;
[email protected]eeb4e4a2011-07-19 16:22:0619namespace gles2 {
20class GLES2CmdHelper;
21class GLES2Implementation;
22} // namespace gles2
23} // namespace gpu.
24
25namespace ppapi {
26
[email protected]9a578392011-12-07 18:59:2727class PPAPI_SHARED_EXPORT PPB_Graphics3D_Shared
[email protected]614888b2012-01-05 06:18:1228 : public Resource,
29 public thunk::PPB_Graphics3D_API {
[email protected]eeb4e4a2011-07-19 16:22:0630 public:
[email protected]614888b2012-01-05 06:18:1231 // Resource overrides.
32 virtual thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE;
33
[email protected]eeb4e4a2011-07-19 16:22:0634 // PPB_Graphics3D_API implementation.
[email protected]af9388e2012-02-10 09:39:5535 virtual int32_t GetAttribs(int32_t attrib_list[]) OVERRIDE;
36 virtual int32_t SetAttribs(const int32_t attrib_list[]) OVERRIDE;
[email protected]187a88c2011-09-03 03:19:3537 virtual int32_t GetError() OVERRIDE;
[email protected]23bd2af2011-08-01 17:48:0738 virtual int32_t ResizeBuffers(int32_t width, int32_t height) OVERRIDE;
[email protected]aed96532012-06-23 14:27:4239 virtual int32_t SwapBuffers(scoped_refptr<TrackedCallback> callback) OVERRIDE;
[email protected]252c4bd2013-03-30 03:00:0340 virtual int32_t GetAttribMaxValue(int32_t attribute, int32_t* value) OVERRIDE;
41
[email protected]94653572012-02-26 19:05:2042 virtual void* MapTexSubImage2DCHROMIUM(GLenum target,
43 GLint level,
44 GLint xoffset,
45 GLint yoffset,
46 GLsizei width,
47 GLsizei height,
48 GLenum format,
49 GLenum type,
50 GLenum access) OVERRIDE;
51 virtual void UnmapTexSubImage2DCHROMIUM(const void* mem) OVERRIDE;
[email protected]eeb4e4a2011-07-19 16:22:0652
53 gpu::gles2::GLES2Implementation* gles2_impl() {
54 return gles2_impl_.get();
55 }
56
57 // Sends swap-buffers notification to the plugin.
58 void SwapBuffersACK(int32_t pp_error);
59
60 protected:
[email protected]84b44c552012-10-15 20:58:1761 // ScopedNoLocking makes sure we don't try to lock again when we already have
62 // the proxy lock. This is used when we need to use the CommandBuffer
63 // (possibly via gles2_impl) but we already have the proxy lock. The
64 // CommandBuffer in the plugin side of the proxy will otherwise try to acquire
65 // the ProxyLock, causing a crash because we already own the lock. (Locks in
66 // Chromium are never recursive).
67 class ScopedNoLocking {
68 public:
69 explicit ScopedNoLocking(PPB_Graphics3D_Shared* graphics3d_shared)
70 : graphics3d_shared_(graphics3d_shared) {
71 graphics3d_shared_->PushAlreadyLocked();
72 }
73 ~ScopedNoLocking() {
74 graphics3d_shared_->PopAlreadyLocked();
75 }
76 private:
77 PPB_Graphics3D_Shared* graphics3d_shared_; // Weak
78
79 DISALLOW_COPY_AND_ASSIGN(ScopedNoLocking);
80 };
81
82
[email protected]614888b2012-01-05 06:18:1283 PPB_Graphics3D_Shared(PP_Instance instance);
84 PPB_Graphics3D_Shared(const HostResource& host_resource);
[email protected]9a578392011-12-07 18:59:2785 virtual ~PPB_Graphics3D_Shared();
[email protected]eeb4e4a2011-07-19 16:22:0686
87 virtual gpu::CommandBuffer* GetCommandBuffer() = 0;
88 virtual int32 DoSwapBuffers() = 0;
89
[email protected]614888b2012-01-05 06:18:1290 bool HasPendingSwap() const;
[email protected]eeb4e4a2011-07-19 16:22:0691 bool CreateGLES2Impl(int32 command_buffer_size,
[email protected]9ed07f82012-05-29 21:54:5592 int32 transfer_buffer_size,
93 gpu::gles2::GLES2Implementation* share_gles2);
[email protected]eeb4e4a2011-07-19 16:22:0694 void DestroyGLES2Impl();
95
96 private:
[email protected]84b44c552012-10-15 20:58:1797 // On the plugin side, we need to know that we already have the lock, so that
98 // we don't try to acquire it again. The default implementation does nothing;
99 // the Plugin side of the proxy must implement these.
100 friend class ScopedNoLocking;
101 virtual void PushAlreadyLocked();
102 virtual void PopAlreadyLocked();
103
[email protected]c902ec22013-01-10 05:59:42104 // The VideoDecoder needs to be able to call Graphics3D Flush() after taking
105 // the proxy lock. Hence it needs access to ScopedNoLocking.
106 friend class PPB_VideoDecoder_Shared;
107
[email protected]eeb4e4a2011-07-19 16:22:06108 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_;
[email protected]06b73aa2012-01-27 23:06:19109 scoped_ptr<gpu::TransferBuffer> transfer_buffer_;
[email protected]eeb4e4a2011-07-19 16:22:06110 scoped_ptr<gpu::gles2::GLES2Implementation> gles2_impl_;
111
112 // Callback that needs to be executed when swap-buffers is completed.
[email protected]614888b2012-01-05 06:18:12113 scoped_refptr<TrackedCallback> swap_callback_;
[email protected]eeb4e4a2011-07-19 16:22:06114
[email protected]9a578392011-12-07 18:59:27115 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Shared);
[email protected]eeb4e4a2011-07-19 16:22:06116};
117
118} // namespace ppapi
119
120#endif // PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_
121