OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #ifndef UI_GL_ASYNC_TASK_DELEGATE_H_ |
| 6 #define UI_GL_ASYNC_TASK_DELEGATE_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "build/build_config.h" |
| 13 #include "ui/gl/gl_bindings.h" |
| 14 #include "ui/gl/gl_export.h" |
| 15 |
| 16 namespace base { |
| 17 class SharedMemory; |
| 18 } |
| 19 |
| 20 namespace gfx { |
| 21 |
| 22 struct AsyncTexImage2DParams { |
| 23 GLenum target; |
| 24 GLint level; |
| 25 GLenum internal_format; |
| 26 GLsizei width; |
| 27 GLsizei height; |
| 28 GLint border; |
| 29 GLenum format; |
| 30 GLenum type; |
| 31 }; |
| 32 |
| 33 struct AsyncTexSubImage2DParams { |
| 34 GLenum target; |
| 35 GLint level; |
| 36 GLint xoffset; |
| 37 GLint yoffset; |
| 38 GLsizei width; |
| 39 GLsizei height; |
| 40 GLenum format; |
| 41 GLenum type; |
| 42 }; |
| 43 |
| 44 struct AsyncMemoryParams { |
| 45 base::SharedMemory* shared_memory; |
| 46 uint32 shm_size; |
| 47 uint32 shm_data_offset; |
| 48 uint32 shm_data_size; |
| 49 }; |
| 50 |
| 51 // AsyncPixelTransferState holds the resources required to do async |
| 52 // transfers on one texture. It should stay alive for the lifetime |
| 53 // of the texture to allow multiple transfers. |
| 54 class GL_EXPORT AsyncPixelTransferState : |
| 55 public base::SupportsWeakPtr<AsyncPixelTransferState> { |
| 56 public: |
| 57 virtual ~AsyncPixelTransferState() {} |
| 58 |
| 59 // Returns true if there is a transfer in progress. |
| 60 virtual bool TransferIsInProgress() = 0; |
| 61 |
| 62 // Perform any custom binding of the transfer (currently only |
| 63 // needed for AsyncTexImage2D). The params used to define the texture |
| 64 // are returned in level_params. |
| 65 // |
| 66 // The transfer must be complete to call this (!TransferIsInProgress). |
| 67 virtual void BindTransfer(AsyncTexImage2DParams* level_params) = 0; |
| 68 |
| 69 protected: |
| 70 friend class base::RefCounted<AsyncPixelTransferState>; |
| 71 AsyncPixelTransferState() {} |
| 72 |
| 73 |
| 74 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferState); |
| 76 }; |
| 77 |
| 78 class GL_EXPORT AsyncPixelTransferDelegate { |
| 79 public: |
| 80 static scoped_ptr<AsyncPixelTransferDelegate> |
| 81 Create(gfx::GLContext* context); |
| 82 virtual ~AsyncPixelTransferDelegate() {} |
| 83 |
| 84 // This wouldn't work with MOCK_METHOD, so it routes through |
| 85 // a virtual protected version which returns a raw pointer. |
| 86 scoped_ptr<AsyncPixelTransferState> |
| 87 CreatePixelTransferState(GLuint texture_id) { |
| 88 return make_scoped_ptr(CreateRawPixelTransferState(texture_id)); |
| 89 } |
| 90 |
| 91 virtual void AsyncNotifyCompletion( |
| 92 const base::Closure& notify_task) = 0; |
| 93 |
| 94 virtual void AsyncTexImage2D( |
| 95 AsyncPixelTransferState* state, |
| 96 const AsyncTexImage2DParams& tex_params, |
| 97 const AsyncMemoryParams& mem_params) = 0; |
| 98 |
| 99 virtual void AsyncTexSubImage2D( |
| 100 AsyncPixelTransferState* state, |
| 101 const AsyncTexSubImage2DParams& tex_params, |
| 102 const AsyncMemoryParams& mem_params) = 0; |
| 103 |
| 104 protected: |
| 105 AsyncPixelTransferDelegate() {} |
| 106 // For testing, as returning scoped_ptr wouldn't work with MOCK_METHOD. |
| 107 virtual AsyncPixelTransferState* |
| 108 CreateRawPixelTransferState(GLuint texture_id) = 0; |
| 109 |
| 110 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegate); |
| 112 }; |
| 113 |
| 114 } // namespace gfx |
| 115 |
| 116 #endif // UI_GL_ASYNC_TASK_DELEGATE_H_ |
| 117 |
OLD | NEW |