Home | History | Annotate | Download | only in pepper
      1 // Copyright (c) 2012 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 CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
      6 #define CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
      7 
      8 #include "base/memory/shared_memory.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "gpu/command_buffer/common/mailbox.h"
     11 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
     12 #include "ppapi/shared_impl/resource.h"
     13 
     14 namespace content {
     15 class CommandBufferProxyImpl;
     16 class GpuChannelHost;
     17 
     18 class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared {
     19  public:
     20   static PP_Resource Create(PP_Instance instance,
     21                             PP_Resource share_context,
     22                             const int32_t* attrib_list);
     23   static PP_Resource CreateRaw(
     24       PP_Instance instance,
     25       PP_Resource share_context,
     26       const int32_t* attrib_list,
     27       base::SharedMemoryHandle* shared_state_handle);
     28 
     29   // PPB_Graphics3D_API trusted implementation.
     30   virtual PP_Bool SetGetBuffer(int32_t transfer_buffer_id) OVERRIDE;
     31   virtual scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
     32                                                           int32* id) OVERRIDE;
     33   virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE;
     34   virtual PP_Bool Flush(int32_t put_offset) OVERRIDE;
     35   virtual gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
     36                                                         int32_t end) OVERRIDE;
     37   virtual gpu::CommandBuffer::State WaitForGetOffsetInRange(int32_t start,
     38                                                             int32_t end)
     39       OVERRIDE;
     40   virtual uint32_t InsertSyncPoint() OVERRIDE;
     41   virtual uint32_t InsertFutureSyncPoint() OVERRIDE;
     42   virtual void RetireSyncPoint(uint32_t) OVERRIDE;
     43 
     44   // Binds/unbinds the graphics of this context with the associated instance.
     45   // Returns true if binding/unbinding is successful.
     46   bool BindToInstance(bool bind);
     47 
     48   // Returns true if the backing texture is always opaque.
     49   bool IsOpaque();
     50 
     51   // Notifications about the view's progress painting.  See PluginInstance.
     52   // These messages are used to send Flush callbacks to the plugin.
     53   void ViewInitiatedPaint();
     54   void ViewFlushedPaint();
     55 
     56   void GetBackingMailbox(gpu::Mailbox* mailbox, uint32* sync_point) {
     57     *mailbox = mailbox_;
     58     *sync_point = sync_point_;
     59   }
     60 
     61   int GetCommandBufferRouteId();
     62 
     63   GpuChannelHost* channel() { return channel_.get(); }
     64 
     65  protected:
     66   virtual ~PPB_Graphics3D_Impl();
     67   // ppapi::PPB_Graphics3D_Shared overrides.
     68   virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE;
     69   virtual gpu::GpuControl* GetGpuControl() OVERRIDE;
     70   virtual int32 DoSwapBuffers() OVERRIDE;
     71 
     72  private:
     73   explicit PPB_Graphics3D_Impl(PP_Instance instance);
     74 
     75   bool Init(PPB_Graphics3D_API* share_context, const int32_t* attrib_list);
     76   bool InitRaw(PPB_Graphics3D_API* share_context,
     77                const int32_t* attrib_list,
     78                base::SharedMemoryHandle* shared_state_handle);
     79 
     80   // Notifications received from the GPU process.
     81   void OnSwapBuffers();
     82   void OnContextLost();
     83   void OnConsoleMessage(const std::string& msg, int id);
     84   // Notifications sent to plugin.
     85   void SendContextLost();
     86 
     87   // True if context is bound to instance.
     88   bool bound_to_instance_;
     89   // True when waiting for compositor to commit our backing texture.
     90   bool commit_pending_;
     91 
     92   gpu::Mailbox mailbox_;
     93   uint32 sync_point_;
     94   bool has_alpha_;
     95   scoped_refptr<GpuChannelHost> channel_;
     96   CommandBufferProxyImpl* command_buffer_;
     97 
     98   base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
     99 
    100   DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
    101 };
    102 
    103 }  // namespace content
    104 
    105 #endif  // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
    106