[email protected] | 06b73aa | 2012-01-27 23:06:19 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 2 | // 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 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
dcheng | ced9224 | 2016-04-07 00:00:12 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 13 | #include "ppapi/c/pp_completion_callback.h" |
[email protected] | f0a04c4 | 2011-08-26 22:43:20 | [diff] [blame] | 14 | #include "ppapi/shared_impl/ppapi_shared_export.h" |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 15 | #include "ppapi/shared_impl/resource.h" |
| 16 | #include "ppapi/shared_impl/tracked_callback.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 17 | #include "ppapi/thunk/ppb_graphics_3d_api.h" |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 18 | #include "ui/gfx/geometry/size.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 19 | |
| 20 | namespace gpu { |
| 21 | class CommandBuffer; |
[email protected] | 744e079 | 2013-09-27 01:18:35 | [diff] [blame] | 22 | class GpuControl; |
[email protected] | 06b73aa | 2012-01-27 23:06:19 | [diff] [blame] | 23 | class TransferBuffer; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 24 | namespace gles2 { |
| 25 | class GLES2CmdHelper; |
| 26 | class GLES2Implementation; |
jbroman | 35f3e1eb | 2016-01-04 22:37:38 | [diff] [blame] | 27 | class GLES2Interface; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 28 | } // namespace gles2 |
| 29 | } // namespace gpu. |
| 30 | |
| 31 | namespace ppapi { |
| 32 | |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 33 | class PPAPI_SHARED_EXPORT PPB_Graphics3D_Shared |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 34 | : public Resource, |
| 35 | public thunk::PPB_Graphics3D_API { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 36 | public: |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 37 | // Resource overrides. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 38 | thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() override; |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 39 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 40 | // PPB_Graphics3D_API implementation. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 41 | int32_t GetAttribs(int32_t attrib_list[]) override; |
| 42 | int32_t SetAttribs(const int32_t attrib_list[]) override; |
| 43 | int32_t GetError() override; |
| 44 | int32_t ResizeBuffers(int32_t width, int32_t height) override; |
raymes | bc71ad0b | 2016-03-14 07:30:35 | [diff] [blame] | 45 | int32_t SwapBuffers(scoped_refptr<TrackedCallback> callback) override; |
| 46 | int32_t SwapBuffersWithSyncToken(scoped_refptr<TrackedCallback> callback, |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 47 | const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 48 | const gfx::Size& size) override; |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 49 | int32_t GetAttribMaxValue(int32_t attribute, int32_t* value) override; |
[email protected] | 252c4bd | 2013-03-30 03:00:03 | [diff] [blame] | 50 | |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 51 | void* MapTexSubImage2DCHROMIUM(GLenum target, |
| 52 | GLint level, |
| 53 | GLint xoffset, |
| 54 | GLint yoffset, |
| 55 | GLsizei width, |
| 56 | GLsizei height, |
| 57 | GLenum format, |
| 58 | GLenum type, |
| 59 | GLenum access) override; |
| 60 | void UnmapTexSubImage2DCHROMIUM(const void* mem) override; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 61 | |
[email protected] | 665b5c54 | 2014-02-22 08:06:26 | [diff] [blame] | 62 | gpu::gles2::GLES2Implementation* gles2_impl() { return gles2_impl_.get(); } |
jbroman | 35f3e1eb | 2016-01-04 22:37:38 | [diff] [blame] | 63 | gpu::gles2::GLES2Interface* gles2_interface(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 64 | |
| 65 | // Sends swap-buffers notification to the plugin. |
| 66 | void SwapBuffersACK(int32_t pp_error); |
| 67 | |
| 68 | protected: |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 69 | PPB_Graphics3D_Shared(PP_Instance instance); |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 70 | PPB_Graphics3D_Shared(const HostResource& host_resource, |
| 71 | const gfx::Size& size); |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 72 | ~PPB_Graphics3D_Shared() override; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 73 | |
| 74 | virtual gpu::CommandBuffer* GetCommandBuffer() = 0; |
[email protected] | 744e079 | 2013-09-27 01:18:35 | [diff] [blame] | 75 | virtual gpu::GpuControl* GetGpuControl() = 0; |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 76 | virtual int32_t DoSwapBuffers(const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 77 | const gfx::Size& size) = 0; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 78 | |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 79 | bool HasPendingSwap() const; |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 80 | bool CreateGLES2Impl(int32_t command_buffer_size, |
| 81 | int32_t transfer_buffer_size, |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 82 | gpu::gles2::GLES2Implementation* share_gles2); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 83 | void DestroyGLES2Impl(); |
| 84 | |
| 85 | private: |
dcheng | ced9224 | 2016-04-07 00:00:12 | [diff] [blame] | 86 | std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; |
| 87 | std::unique_ptr<gpu::TransferBuffer> transfer_buffer_; |
| 88 | std::unique_ptr<gpu::gles2::GLES2Implementation> gles2_impl_; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 89 | |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 90 | // A local cache of the size of the viewport. This is only valid in plugin |
| 91 | // resources. |
| 92 | gfx::Size size_; |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 93 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 94 | // Callback that needs to be executed when swap-buffers is completed. |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 95 | scoped_refptr<TrackedCallback> swap_callback_; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 96 | |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Shared); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace ppapi |
| 101 | |
| 102 | #endif // PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_ |