Home | History | Annotate | Download | only in service
      1 // Copyright (c) 2013 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 GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_
      6 #define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/callback.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/synchronization/lock.h"
     13 #include "base/time/time.h"
     14 #include "gpu/gpu_export.h"
     15 #include "ui/gl/gl_bindings.h"
     16 
     17 namespace base {
     18 class SharedMemory;
     19 }
     20 
     21 namespace gpu {
     22 
     23 class ScopedSafeSharedMemory;
     24 
     25 struct AsyncTexImage2DParams {
     26   GLenum target;
     27   GLint level;
     28   GLenum internal_format;
     29   GLsizei width;
     30   GLsizei height;
     31   GLint border;
     32   GLenum format;
     33   GLenum type;
     34 };
     35 
     36 struct AsyncTexSubImage2DParams {
     37   GLenum target;
     38   GLint level;
     39   GLint xoffset;
     40   GLint yoffset;
     41   GLsizei width;
     42   GLsizei height;
     43   GLenum format;
     44   GLenum type;
     45 };
     46 
     47 struct AsyncMemoryParams {
     48   base::SharedMemory* shared_memory;
     49   uint32 shm_size;
     50   uint32 shm_data_offset;
     51   uint32 shm_data_size;
     52 };
     53 
     54 class AsyncPixelTransferUploadStats
     55     : public base::RefCountedThreadSafe<AsyncPixelTransferUploadStats> {
     56  public:
     57   AsyncPixelTransferUploadStats();
     58 
     59   void AddUpload(base::TimeDelta transfer_time);
     60   int GetStats(base::TimeDelta* total_texture_upload_time);
     61 
     62  private:
     63   friend class base::RefCountedThreadSafe<AsyncPixelTransferUploadStats>;
     64 
     65   ~AsyncPixelTransferUploadStats();
     66 
     67   int texture_upload_count_;
     68   base::TimeDelta total_texture_upload_time_;
     69   base::Lock lock_;
     70 
     71   DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferUploadStats);
     72 };
     73 
     74 class GPU_EXPORT AsyncPixelTransferDelegate {
     75  public:
     76   virtual ~AsyncPixelTransferDelegate();
     77 
     78   // The callback occurs on the caller thread, once the texture is
     79   // safe/ready to be used.
     80   virtual void AsyncTexImage2D(
     81       const AsyncTexImage2DParams& tex_params,
     82       const AsyncMemoryParams& mem_params,
     83       const base::Closure& bind_callback) = 0;
     84 
     85   virtual void AsyncTexSubImage2D(
     86       const AsyncTexSubImage2DParams& tex_params,
     87       const AsyncMemoryParams& mem_params) = 0;
     88 
     89   // Returns true if there is a transfer in progress.
     90   virtual bool TransferIsInProgress() = 0;
     91 
     92   // Block until the specified transfer completes.
     93   virtual void WaitForTransferCompletion() = 0;
     94 
     95   // Gets the address of the data from shared memory.
     96   static void* GetAddress(const AsyncMemoryParams& mem_params);
     97 
     98   // Sometimes the |safe_shared_memory| is duplicate to prevent use after free.
     99   static void* GetAddress(ScopedSafeSharedMemory* safe_shared_memory,
    100                           const AsyncMemoryParams& mem_params);
    101 
    102  protected:
    103   AsyncPixelTransferDelegate();
    104 
    105  private:
    106   DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegate);
    107 };
    108 
    109 }  // namespace gpu
    110 
    111 #endif  // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_
    112 
    113