| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
| 14 #include "base/memory/singleton.h" | |
| 15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 16 #include "cc/output/software_frame_data.h" | 15 #include "cc/output/software_frame_data.h" |
| 17 #include "cc/resources/single_release_callback.h" | 16 #include "cc/resources/single_release_callback.h" |
| 18 #include "cc/resources/texture_mailbox.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" | 19 #include "content/common/content_export.h" |
| 20 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class SoftwareFrame; | 23 class SoftwareFrame; |
| 24 class SoftwareFrameMemoryManager; | |
| 25 | 24 |
| 26 class CONTENT_EXPORT SoftwareFrameManagerClient { | 25 class CONTENT_EXPORT SoftwareFrameManagerClient { |
| 27 public: | 26 public: |
| 28 // Called when the memory for the current software frame was freed. | 27 // Called when the memory for the current software frame was freed. |
| 29 virtual void SoftwareFrameWasFreed( | 28 virtual void SoftwareFrameWasFreed( |
| 30 uint32 output_surface_id, unsigned frame_id) = 0; | 29 uint32 output_surface_id, unsigned frame_id) = 0; |
| 31 | 30 |
| 32 // Called when the SoftwareFrameMemoryManager has requested that the frame | 31 // Called when the SoftwareFrameMemoryManager has requested that the frame |
| 33 // be evicted. Upon receiving this callback, the client should release any | 32 // be evicted. Upon receiving this callback, the client should release any |
| 34 // references that it may hold to the current frame, to ensure that its memory | 33 // references that it may hold to the current frame, to ensure that its memory |
| 35 // is freed expediently. | 34 // is freed expediently. |
| 36 virtual void ReleaseReferencesToSoftwareFrame() = 0; | 35 virtual void ReleaseReferencesToSoftwareFrame() = 0; |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 class CONTENT_EXPORT SoftwareFrameManager { | 38 class CONTENT_EXPORT SoftwareFrameManager : public RendererFrameManagerClient { |
| 40 public: | 39 public: |
| 41 explicit SoftwareFrameManager( | 40 explicit SoftwareFrameManager( |
| 42 base::WeakPtr<SoftwareFrameManagerClient> client); | 41 base::WeakPtr<SoftwareFrameManagerClient> client); |
| 43 ~SoftwareFrameManager(); | 42 virtual ~SoftwareFrameManager(); |
| 44 | 43 |
| 45 // Swaps to a new frame from shared memory. This frame is guaranteed to | 44 // Swaps to a new frame from shared memory. This frame is guaranteed to |
| 46 // not be evicted until SwapToNewFrameComplete is called. | 45 // not be evicted until SwapToNewFrameComplete is called. |
| 47 bool SwapToNewFrame( | 46 bool SwapToNewFrame( |
| 48 uint32 output_surface_id, | 47 uint32 output_surface_id, |
| 49 const cc::SoftwareFrameData* frame_data, | 48 const cc::SoftwareFrameData* frame_data, |
| 50 float frame_device_scale_factor, | 49 float frame_device_scale_factor, |
| 51 base::ProcessHandle process_handle); | 50 base::ProcessHandle process_handle); |
| 52 void SwapToNewFrameComplete(bool visible); | 51 void SwapToNewFrameComplete(bool visible); |
| 53 void SetVisibility(bool visible); | 52 void SetVisibility(bool visible); |
| 54 bool HasCurrentFrame() const; | 53 bool HasCurrentFrame() const; |
| 55 void DiscardCurrentFrame(); | 54 void DiscardCurrentFrame(); |
| 56 void GetCurrentFrameMailbox( | 55 void GetCurrentFrameMailbox( |
| 57 cc::TextureMailbox* mailbox, | 56 cc::TextureMailbox* mailbox, |
| 58 scoped_ptr<cc::SingleReleaseCallback>* callback); | 57 scoped_ptr<cc::SingleReleaseCallback>* callback); |
| 59 const void* GetCurrentFramePixels() const; | 58 const void* GetCurrentFramePixels() const; |
| 60 gfx::Size GetCurrentFrameSizeInPixels() const; | 59 gfx::Size GetCurrentFrameSizeInPixels() const; |
| 61 gfx::Size GetCurrentFrameSizeInDIP() const; | 60 gfx::Size GetCurrentFrameSizeInDIP() const; |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 friend class SoftwareFrameMemoryManager; | |
| 65 | |
| 66 // Called by SoftwareFrameMemoryManager to demand that the current frame | 63 // Called by SoftwareFrameMemoryManager to demand that the current frame |
| 67 // be evicted. | 64 // be evicted. |
| 68 void EvictCurrentFrame(); | 65 virtual void EvictCurrentFrame() OVERRIDE; |
| 69 | 66 |
| 70 base::WeakPtr<SoftwareFrameManagerClient> client_; | 67 base::WeakPtr<SoftwareFrameManagerClient> client_; |
| 71 | 68 |
| 72 // This holds the current software framebuffer. | 69 // This holds the current software framebuffer. |
| 73 scoped_refptr<SoftwareFrame> current_frame_; | 70 scoped_refptr<SoftwareFrame> current_frame_; |
| 74 | 71 |
| 75 DISALLOW_COPY_AND_ASSIGN(SoftwareFrameManager); | 72 DISALLOW_COPY_AND_ASSIGN(SoftwareFrameManager); |
| 76 }; | 73 }; |
| 77 | 74 |
| 78 class CONTENT_EXPORT SoftwareFrameMemoryManager { | |
| 79 public: | |
| 80 static SoftwareFrameMemoryManager* GetInstance(); | |
| 81 | |
| 82 void AddFrame(SoftwareFrameManager*, bool visible); | |
| 83 void RemoveFrame(SoftwareFrameManager*); | |
| 84 void SetFrameVisibility(SoftwareFrameManager*, bool visible); | |
| 85 | |
| 86 size_t max_number_of_saved_frames() const { | |
| 87 return max_number_of_saved_frames_; | |
| 88 } | |
| 89 | |
| 90 private: | |
| 91 SoftwareFrameMemoryManager(); | |
| 92 ~SoftwareFrameMemoryManager(); | |
| 93 void CullHiddenFrames(); | |
| 94 friend struct DefaultSingletonTraits<SoftwareFrameMemoryManager>; | |
| 95 | |
| 96 std::set<SoftwareFrameManager*> visible_frames_; | |
| 97 std::list<SoftwareFrameManager*> hidden_frames_; | |
| 98 size_t max_number_of_saved_frames_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(SoftwareFrameMemoryManager); | |
| 101 }; | |
| 102 | |
| 103 } // namespace content | 75 } // namespace content |
| 104 | 76 |
| 105 #endif // CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ | 77 #endif // CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ |
| OLD | NEW |