Home | History | Annotate | Download | only in resources
      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 CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
      6 #define CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/memory/ref_counted.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/memory/weak_ptr.h"
     14 #include "cc/base/cc_export.h"
     15 #include "cc/resources/texture_mailbox.h"
     16 #include "ui/gfx/size.h"
     17 
     18 namespace media {
     19 class SkCanvasVideoRenderer;
     20 class VideoFrame;
     21 }
     22 
     23 namespace cc {
     24 class ResourceProvider;
     25 
     26 class CC_EXPORT VideoFrameExternalResources {
     27  public:
     28   // Specifies what type of data is contained in the mailboxes, as well as how
     29   // many mailboxes will be present.
     30   enum ResourceType {
     31     NONE,
     32     YUV_RESOURCE,
     33     RGB_RESOURCE,
     34     STREAM_TEXTURE_RESOURCE,
     35     IO_SURFACE,
     36 
     37 #if defined(GOOGLE_TV)
     38     // TODO(danakj): Implement this with a solid color layer instead of a video
     39     // frame and video layer.
     40     HOLE,
     41 #endif
     42 
     43     // TODO(danakj): Remove this and abstract TextureMailbox into
     44     // "ExternalResource" that can hold a hardware or software backing.
     45     SOFTWARE_RESOURCE
     46   };
     47 
     48   ResourceType type;
     49   std::vector<TextureMailbox> mailboxes;
     50 
     51   // TODO(danakj): Remove these too.
     52   std::vector<unsigned> software_resources;
     53   TextureMailbox::ReleaseCallback software_release_callback;
     54 
     55   VideoFrameExternalResources();
     56   ~VideoFrameExternalResources();
     57 };
     58 
     59 // VideoResourceUpdater is by the video system to produce frame content as
     60 // resources consumable by the compositor.
     61 class CC_EXPORT VideoResourceUpdater
     62     : public base::SupportsWeakPtr<VideoResourceUpdater> {
     63  public:
     64   explicit VideoResourceUpdater(ResourceProvider* resource_provider);
     65   ~VideoResourceUpdater();
     66 
     67   VideoFrameExternalResources CreateExternalResourcesFromVideoFrame(
     68       const scoped_refptr<media::VideoFrame>& video_frame);
     69 
     70  private:
     71   struct PlaneResource {
     72     unsigned resource_id;
     73     gfx::Size resource_size;
     74     unsigned resource_format;
     75     gpu::Mailbox mailbox;
     76 
     77     PlaneResource(unsigned resource_id,
     78                   gfx::Size resource_size,
     79                   unsigned resource_format,
     80                   gpu::Mailbox mailbox)
     81         : resource_id(resource_id),
     82           resource_size(resource_size),
     83           resource_format(resource_format),
     84           mailbox(mailbox) {}
     85   };
     86 
     87   void DeleteResource(unsigned resource_id);
     88   bool VerifyFrame(const scoped_refptr<media::VideoFrame>& video_frame);
     89   VideoFrameExternalResources CreateForHardwarePlanes(
     90       const scoped_refptr<media::VideoFrame>& video_frame);
     91   VideoFrameExternalResources CreateForSoftwarePlanes(
     92       const scoped_refptr<media::VideoFrame>& video_frame);
     93 
     94   struct RecycleResourceData {
     95     unsigned resource_id;
     96     gfx::Size resource_size;
     97     unsigned resource_format;
     98     gpu::Mailbox mailbox;
     99   };
    100   static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater,
    101                               RecycleResourceData data,
    102                               unsigned sync_point,
    103                               bool lost_resource);
    104 
    105   ResourceProvider* resource_provider_;
    106   scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_;
    107 
    108   std::vector<unsigned> all_resources_;
    109   std::vector<PlaneResource> recycled_resources_;
    110 
    111   DISALLOW_COPY_AND_ASSIGN(VideoResourceUpdater);
    112 };
    113 
    114 }  // namespace cc
    115 
    116 #endif  // CC_RESOURCES_VIDEO_RESOURCE_UPDATER_H_
    117