Home | History | Annotate | Download | only in renderer_host
      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 CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_
      7 
      8 #include <list>
      9 #include <set>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/ref_counted.h"
     13 #include "base/memory/shared_memory.h"
     14 #include "base/memory/weak_ptr.h"
     15 #include "cc/output/software_frame_data.h"
     16 #include "cc/resources/single_release_callback.h"
     17 #include "cc/resources/texture_mailbox.h"
     18 #include "content/browser/renderer_host/renderer_frame_manager.h"
     19 #include "content/common/content_export.h"
     20 #include "ui/gfx/size.h"
     21 
     22 namespace content {
     23 class SoftwareFrame;
     24 
     25 class CONTENT_EXPORT SoftwareFrameManagerClient {
     26  public:
     27   // Called when the memory for the current software frame was freed.
     28   virtual void SoftwareFrameWasFreed(
     29       uint32 output_surface_id, unsigned frame_id) = 0;
     30 
     31   // Called when the SoftwareFrameMemoryManager has requested that the frame
     32   // be evicted. Upon receiving this callback, the client should release any
     33   // references that it may hold to the current frame, to ensure that its memory
     34   // is freed expediently.
     35   virtual void ReleaseReferencesToSoftwareFrame() = 0;
     36 };
     37 
     38 class CONTENT_EXPORT SoftwareFrameManager : public RendererFrameManagerClient {
     39  public:
     40   explicit SoftwareFrameManager(
     41       base::WeakPtr<SoftwareFrameManagerClient> client);
     42   virtual ~SoftwareFrameManager();
     43 
     44   // Swaps to a new frame from shared memory. This frame is guaranteed to
     45   // not be evicted until SwapToNewFrameComplete is called.
     46   bool SwapToNewFrame(
     47       uint32 output_surface_id,
     48       const cc::SoftwareFrameData* frame_data,
     49       float frame_device_scale_factor,
     50       base::ProcessHandle process_handle);
     51   void SwapToNewFrameComplete(bool visible);
     52   void SetVisibility(bool visible);
     53   bool HasCurrentFrame() const;
     54   void DiscardCurrentFrame();
     55   uint32 GetCurrentFrameOutputSurfaceId() const;
     56   void GetCurrentFrameMailbox(
     57       cc::TextureMailbox* mailbox,
     58       scoped_ptr<cc::SingleReleaseCallback>* callback);
     59   void* GetCurrentFramePixels() const;
     60   float GetCurrentFrameDeviceScaleFactor() const;
     61   gfx::Size GetCurrentFrameSizeInPixels() const;
     62   gfx::Size GetCurrentFrameSizeInDIP() const;
     63 
     64  private:
     65   // Called by SoftwareFrameMemoryManager to demand that the current frame
     66   // be evicted.
     67   virtual void EvictCurrentFrame() OVERRIDE;
     68 
     69   base::WeakPtr<SoftwareFrameManagerClient> client_;
     70 
     71   // This holds the current software framebuffer.
     72   scoped_refptr<SoftwareFrame> current_frame_;
     73 
     74   DISALLOW_COPY_AND_ASSIGN(SoftwareFrameManager);
     75 };
     76 
     77 }  // namespace content
     78 
     79 #endif  // CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_
     80