1 // Copyright (c) 2012 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_BACKING_STORE_MANAGER_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MANAGER_H_ 7 8 #include <vector> 9 10 #include "base/basictypes.h" 11 #include "base/callback_forward.h" 12 #include "base/process/process.h" 13 #include "ui/gfx/rect.h" 14 #include "ui/gfx/size.h" 15 #include "ui/surface/transport_dib.h" 16 17 namespace content { 18 class BackingStore; 19 class RenderWidgetHost; 20 21 // This class manages backing stores in the browsr. Every RenderWidgetHost is 22 // associated with a backing store which it requests from this class. The 23 // hosts don't maintain any references to the backing stores. These backing 24 // stores are maintained in a cache which can be trimmed as needed. 25 class BackingStoreManager { 26 public: 27 // Returns a backing store which matches the desired dimensions. 28 // 29 // backing_store_rect 30 // The desired backing store dimensions. 31 // Returns a pointer to the backing store on success, NULL on failure. 32 static BackingStore* GetBackingStore(RenderWidgetHost* host, 33 const gfx::Size& desired_size); 34 35 // Makes a backing store which is fully ready for consumption, i.e. the 36 // bitmap from the renderer has been copied into the backing store. 37 // 38 // backing_store_size 39 // The desired backing store dimensions, in DIPs. 40 // bitmap_section 41 // The bitmap section from the renderer. 42 // bitmap_rect 43 // The rect to be painted into the backing store, in DIPs. 44 // scale_factor 45 // The device scale factor the backing store is expected to be at. 46 // If the backing store's device scale factor doesn't match, it will need 47 // to scale |bitmap| at paint time. This will only be out of sync with the 48 // backing store scale factor for a few frames, right after device scale 49 // changes. 50 // needs_full_paint 51 // Set if we need to send out a request to paint the view 52 // to the renderer. 53 static void PrepareBackingStore( 54 RenderWidgetHost* host, 55 const gfx::Size& backing_store_size, 56 TransportDIB::Id bitmap, 57 const gfx::Rect& bitmap_rect, 58 const std::vector<gfx::Rect>& copy_rects, 59 float scale_factor, 60 const base::Closure& completion_callback, 61 bool* needs_full_paint, 62 bool* scheduled_completion_callback); 63 64 // Returns a matching backing store for the host. 65 // Returns NULL if we fail to find one. 66 static BackingStore* Lookup(RenderWidgetHost* host); 67 68 // Removes the backing store for the host. 69 static void RemoveBackingStore(RenderWidgetHost* host); 70 71 // Removes all backing stores. 72 static void RemoveAllBackingStores(); 73 74 // Current size in bytes of the backing store cache. 75 static size_t MemorySize(); 76 77 private: 78 // Not intended for instantiation. BackingStoreManager()79 BackingStoreManager() {} 80 81 DISALLOW_COPY_AND_ASSIGN(BackingStoreManager); 82 }; 83 84 } // namespace content 85 86 #endif // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MANAGER_H_ 87