Home | History | Annotate | Download | only in filters
      1 // Copyright 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 MEDIA_FILTERS_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
      6 #define MEDIA_FILTERS_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "gpu/command_buffer/common/mailbox.h"
     13 #include "media/base/media_export.h"
     14 
     15 class SkBitmap;
     16 
     17 namespace base {
     18 class SingleThreadTaskRunner;
     19 class SharedMemory;
     20 }
     21 
     22 namespace gfx {
     23 class Rect;
     24 class Size;
     25 }
     26 
     27 namespace media {
     28 
     29 class VideoDecodeAccelerator;
     30 class VideoEncodeAccelerator;
     31 
     32 // Helper interface for specifying factories needed to instantiate a hardware
     33 // video accelerator.
     34 // Threading model:
     35 // * The GpuVideoAcceleratorFactories may be constructed on any thread.
     36 // * The GpuVideoAcceleratorFactories has an associated message loop, which may
     37 //   be retrieved as |GetMessageLoop()|.
     38 // * All calls to the Factories after construction must be made on its message
     39 //   loop.
     40 class MEDIA_EXPORT GpuVideoAcceleratorFactories
     41     : public base::RefCountedThreadSafe<GpuVideoAcceleratorFactories> {
     42  public:
     43   // Caller owns returned pointer, but should call Destroy() on it (instead of
     44   // directly deleting) for proper destruction, as per the
     45   // VideoDecodeAccelerator interface.
     46   virtual scoped_ptr<VideoDecodeAccelerator> CreateVideoDecodeAccelerator() = 0;
     47 
     48   // Caller owns returned pointer, but should call Destroy() on it (instead of
     49   // directly deleting) for proper destruction, as per the
     50   // VideoEncodeAccelerator interface.
     51   virtual scoped_ptr<VideoEncodeAccelerator> CreateVideoEncodeAccelerator() = 0;
     52 
     53   // Allocate & delete native textures.
     54   virtual bool CreateTextures(int32 count,
     55                               const gfx::Size& size,
     56                               std::vector<uint32>* texture_ids,
     57                               std::vector<gpu::Mailbox>* texture_mailboxes,
     58                               uint32 texture_target) = 0;
     59   virtual void DeleteTexture(uint32 texture_id) = 0;
     60 
     61   virtual void WaitSyncPoint(uint32 sync_point) = 0;
     62 
     63   // Read pixels within |visible_rect| boundaries from a native texture and
     64   // store into |pixels| as RGBA.
     65   virtual void ReadPixels(uint32 texture_id,
     66                           const gfx::Rect& visible_rect,
     67                           const SkBitmap& pixels) = 0;
     68 
     69   // Allocate & return a shared memory segment.  Caller is responsible for
     70   // Close()ing the returned pointer.
     71   virtual base::SharedMemory* CreateSharedMemory(size_t size) = 0;
     72 
     73   // Returns the task runner the video accelerator runs on.
     74   virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0;
     75 
     76  protected:
     77   friend class base::RefCountedThreadSafe<GpuVideoAcceleratorFactories>;
     78   virtual ~GpuVideoAcceleratorFactories();
     79 };
     80 
     81 }  // namespace media
     82 
     83 #endif  // MEDIA_FILTERS_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
     84