OLD | NEW |
(Empty) | |
| 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/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "cc/output/software_frame_data.h" |
| 17 #include "cc/resources/single_release_callback.h" |
| 18 #include "cc/resources/texture_mailbox.h" |
| 19 #include "content/common/content_export.h" |
| 20 #include "ui/gfx/size.h" |
| 21 |
| 22 namespace content { |
| 23 class SoftwareFrame; |
| 24 class SoftwareFrameMemoryManager; |
| 25 |
| 26 class CONTENT_EXPORT SoftwareFrameManagerClient { |
| 27 public: |
| 28 // Called when the memory for the current software frame was freed. |
| 29 virtual void SoftwareFrameWasFreed( |
| 30 uint32 output_surface_id, unsigned frame_id) = 0; |
| 31 |
| 32 // Called when the SoftwareFrameMemoryManager has requested that the frame |
| 33 // 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 |
| 35 // is freed expediently. |
| 36 virtual void ReleaseReferencesToSoftwareFrame() = 0; |
| 37 }; |
| 38 |
| 39 class CONTENT_EXPORT SoftwareFrameManager { |
| 40 public: |
| 41 explicit SoftwareFrameManager( |
| 42 base::WeakPtr<SoftwareFrameManagerClient> client); |
| 43 ~SoftwareFrameManager(); |
| 44 |
| 45 // Swaps to a new frame from shared memory. This frame is guaranteed to |
| 46 // not be evicted until SwapToNewFrameComplete is called. |
| 47 bool SwapToNewFrame( |
| 48 uint32 output_surface_id, |
| 49 const cc::SoftwareFrameData* frame_data, |
| 50 float frame_device_scale_factor, |
| 51 base::ProcessHandle process_handle); |
| 52 void SwapToNewFrameComplete(bool visible); |
| 53 void SetVisibility(bool visible); |
| 54 bool HasCurrentFrame() const; |
| 55 void DiscardCurrentFrame(); |
| 56 void GetCurrentFrameMailbox( |
| 57 cc::TextureMailbox* mailbox, |
| 58 scoped_ptr<cc::SingleReleaseCallback>* callback); |
| 59 const void* GetCurrentFramePixels() const; |
| 60 gfx::Size GetCurrentFrameSizeInPixels() const; |
| 61 gfx::Size GetCurrentFrameSizeInDIP() const; |
| 62 |
| 63 private: |
| 64 friend class SoftwareFrameMemoryManager; |
| 65 |
| 66 // Called by SoftwareFrameMemoryManager to demand that the current frame |
| 67 // be evicted. |
| 68 void EvictCurrentFrame(); |
| 69 |
| 70 base::WeakPtr<SoftwareFrameManagerClient> client_; |
| 71 |
| 72 // This holds the current software framebuffer. |
| 73 scoped_refptr<SoftwareFrame> current_frame_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(SoftwareFrameManager); |
| 76 }; |
| 77 |
| 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 |
| 104 |
| 105 #endif // CONTENT_BROWSER_RENDERER_HOST_SOFTWARE_FRAME_MANAGER_H_ |
OLD | NEW |