| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
| 10 #include "base/gfx/size.h" | 10 #include "base/gfx/size.h" |
| 11 #include "base/process.h" | 11 #include "base/process.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/common/mru_cache.h" | 13 #include "chrome/common/mru_cache.h" |
| 14 | 14 |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 #elif defined(OS_POSIX) | 17 #elif defined(OS_MACOSX) |
| 18 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
| 19 #elif defined(OS_LINUX) |
| 20 #include "chrome/common/x11_util.h" |
| 19 #endif | 21 #endif |
| 20 | 22 |
| 21 class RenderWidgetHost; | 23 class RenderWidgetHost; |
| 22 class TransportDIB; | 24 class TransportDIB; |
| 23 | 25 |
| 24 // BackingStore ---------------------------------------------------------------- | 26 // BackingStore ---------------------------------------------------------------- |
| 25 | 27 |
| 26 // Represents a backing store for the pixels in a RenderWidgetHost. | 28 // Represents a backing store for the pixels in a RenderWidgetHost. |
| 27 class BackingStore { | 29 class BackingStore { |
| 28 public: | 30 public: |
| 31 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 29 explicit BackingStore(const gfx::Size& size); | 32 explicit BackingStore(const gfx::Size& size); |
| 33 #elif defined(OS_LINUX) |
| 34 // Create a backing store on the X server. |
| 35 // size: the size of the server-side pixmap |
| 36 // x_connection: the display to target |
| 37 // depth: the depth of the X window which will be drawn into |
| 38 // visual: An Xlib Visual describing the format of the target window |
| 39 // parent_window: The X id of the target window |
| 40 // use_shared_memory: if true, the X server is local |
| 41 BackingStore(const gfx::Size& size, Display* x_connection, int depth, |
| 42 void* visual, XID parent_window, bool use_shared_memory); |
| 43 // This is for unittesting only. An object constructed using this constructor |
| 44 // will silently ignore all paints |
| 45 explicit BackingStore(const gfx::Size& size); |
| 46 #endif |
| 30 ~BackingStore(); | 47 ~BackingStore(); |
| 31 | 48 |
| 32 const gfx::Size& size() { return size_; } | 49 const gfx::Size& size() { return size_; } |
| 33 | 50 |
| 34 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 35 HDC hdc() { return hdc_; } | 52 HDC hdc() { return hdc_; } |
| 36 #elif defined(OS_POSIX) | 53 #elif defined(OS_MACOSX) |
| 37 skia::PlatformCanvas* canvas() { return &canvas_; } | 54 skia::PlatformCanvas* canvas() { return &canvas_; } |
| 55 #elif defined(OS_LINUX) |
| 56 // Copy from the server-side backing store to the target window |
| 57 // display: the display of the backing store and target window |
| 58 // damage: the area to copy |
| 59 // target: the X id of the target window |
| 60 void ShowRect(const gfx::Rect& damage); |
| 38 #endif | 61 #endif |
| 39 | 62 |
| 40 // Paints the bitmap from the renderer onto the backing store. | 63 // Paints the bitmap from the renderer onto the backing store. |
| 41 bool PaintRect(base::ProcessHandle process, | 64 void PaintRect(base::ProcessHandle process, |
| 42 TransportDIB* bitmap, | 65 TransportDIB* bitmap, |
| 43 const gfx::Rect& bitmap_rect); | 66 const gfx::Rect& bitmap_rect); |
| 44 | 67 |
| 45 // Scrolls the given rect in the backing store, replacing the given region | 68 // Scrolls the given rect in the backing store, replacing the given region |
| 46 // identified by |bitmap_rect| by the bitmap in the file identified by the | 69 // identified by |bitmap_rect| by the bitmap in the file identified by the |
| 47 // given file handle. | 70 // given file handle. |
| 48 void ScrollRect(base::ProcessHandle process, | 71 void ScrollRect(base::ProcessHandle process, |
| 49 TransportDIB* bitmap, const gfx::Rect& bitmap_rect, | 72 TransportDIB* bitmap, const gfx::Rect& bitmap_rect, |
| 50 int dx, int dy, | 73 int dx, int dy, |
| 51 const gfx::Rect& clip_rect, | 74 const gfx::Rect& clip_rect, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 65 HANDLE section); | 88 HANDLE section); |
| 66 | 89 |
| 67 // The backing store dc. | 90 // The backing store dc. |
| 68 HDC hdc_; | 91 HDC hdc_; |
| 69 | 92 |
| 70 // Handle to the backing store dib. | 93 // Handle to the backing store dib. |
| 71 HANDLE backing_store_dib_; | 94 HANDLE backing_store_dib_; |
| 72 | 95 |
| 73 // Handle to the original bitmap in the dc. | 96 // Handle to the original bitmap in the dc. |
| 74 HANDLE original_bitmap_; | 97 HANDLE original_bitmap_; |
| 75 #elif defined(OS_POSIX) | 98 #elif defined(OS_MACOSX) |
| 76 skia::PlatformCanvas canvas_; | 99 skia::PlatformCanvas canvas_; |
| 77 #endif // defined(OS_WIN) | 100 #elif defined(OS_LINUX) |
| 101 // This is the connection to the X server where this backing store will be |
| 102 // displayed. |
| 103 Display *const display_; |
| 104 // If this is true, then |connection_| is good for MIT-SHM (X shared memory). |
| 105 const bool use_shared_memory_; |
| 106 // The parent window (probably a GtkDrawingArea) for this backing store. |
| 107 const XID parent_window_; |
| 108 // This is a handle to the server side pixmap which is our backing store. |
| 109 XID pixmap_; |
| 110 // This is the RENDER picture pointing at |pixmap_|. |
| 111 XID picture_; |
| 112 // This is a default graphic context, used in XCopyArea |
| 113 void* pixmap_gc_; |
| 114 #endif |
| 78 | 115 |
| 79 DISALLOW_COPY_AND_ASSIGN(BackingStore); | 116 DISALLOW_COPY_AND_ASSIGN(BackingStore); |
| 80 }; | 117 }; |
| 81 | 118 |
| 82 // BackingStoreManager --------------------------------------------------------- | 119 // BackingStoreManager --------------------------------------------------------- |
| 83 | 120 |
| 84 // This class manages backing stores in the browsr. Every RenderWidgetHost is | 121 // This class manages backing stores in the browsr. Every RenderWidgetHost is |
| 85 // associated with a backing store which it requests from this class. The | 122 // associated with a backing store which it requests from this class. The |
| 86 // hosts don't maintain any references to the backing stores. These backing | 123 // hosts don't maintain any references to the backing stores. These backing |
| 87 // stores are maintained in a cache which can be trimmed as needed. | 124 // stores are maintained in a cache which can be trimmed as needed. |
| 88 class BackingStoreManager { | 125 class BackingStoreManager { |
| 89 public: | 126 public: |
| 90 // Returns a backing store which matches the desired dimensions. | 127 // Returns a backing store which matches the desired dimensions. |
| 91 // | 128 // |
| 92 // backing_store_rect | 129 // backing_store_rect |
| 93 // The desired backing store dimensions. | 130 // The desired backing store dimensions. |
| 94 // Returns a pointer to the backing store on success, NULL on failure. | 131 // Returns a pointer to the backing store on success, NULL on failure. |
| 95 static BackingStore* GetBackingStore(RenderWidgetHost* host, | 132 static BackingStore* GetBackingStore(RenderWidgetHost* host, |
| 96 const gfx::Size& desired_size); | 133 const gfx::Size& desired_size); |
| 97 | 134 |
| 98 // Returns a backing store which is fully ready for consumption, i.e. the | 135 // Returns a backing store which is fully ready for consumption, i.e. the |
| 99 // bitmap from the renderer has been copied into the backing store dc, or the | 136 // bitmap from the renderer has been copied into the backing store dc, or the |
| 100 // bitmap in the backing store dc references the renderer bitmap. | 137 // bitmap in the backing store dc references the renderer bitmap. |
| 101 // | 138 // |
| 102 // backing_store_rect | 139 // backing_store_size |
| 103 // The desired backing store dimensions. | 140 // The desired backing store dimensions. |
| 104 // process_handle | 141 // process_handle |
| 105 // The renderer process handle. | 142 // The renderer process handle. |
| 106 // bitmap_section | 143 // bitmap_section |
| 107 // The bitmap section from the renderer. | 144 // The bitmap section from the renderer. |
| 108 // bitmap_rect | 145 // bitmap_rect |
| 109 // The rect to be painted into the backing store | 146 // The rect to be painted into the backing store |
| 110 // needs_full_paint | 147 // needs_full_paint |
| 111 // Set if we need to send out a request to paint the view | 148 // Set if we need to send out a request to paint the view |
| 112 // to the renderer. | 149 // to the renderer. |
| 113 static BackingStore* PrepareBackingStore(RenderWidgetHost* host, | 150 static BackingStore* PrepareBackingStore(RenderWidgetHost* host, |
| 114 const gfx::Rect& backing_store_rect, | 151 const gfx::Size& backing_store_size, |
| 115 base::ProcessHandle process_handle, | 152 base::ProcessHandle process_handle, |
| 116 TransportDIB* bitmap, | 153 TransportDIB* bitmap, |
| 117 const gfx::Rect& bitmap_rect, | 154 const gfx::Rect& bitmap_rect, |
| 118 bool* needs_full_paint); | 155 bool* needs_full_paint); |
| 119 | 156 |
| 120 // Returns a matching backing store for the host. | 157 // Returns a matching backing store for the host. |
| 121 // Returns NULL if we fail to find one. | 158 // Returns NULL if we fail to find one. |
| 122 static BackingStore* Lookup(RenderWidgetHost* host); | 159 static BackingStore* Lookup(RenderWidgetHost* host); |
| 123 | 160 |
| 124 // Removes the backing store for the host. | 161 // Removes the backing store for the host. |
| 125 static void RemoveBackingStore(RenderWidgetHost* host); | 162 static void RemoveBackingStore(RenderWidgetHost* host); |
| 126 | 163 |
| 127 private: | 164 private: |
| 128 // Not intended for instantiation. | 165 // Not intended for instantiation. |
| 129 BackingStoreManager() {} | 166 BackingStoreManager() {} |
| 130 | 167 |
| 131 DISALLOW_COPY_AND_ASSIGN(BackingStoreManager); | 168 DISALLOW_COPY_AND_ASSIGN(BackingStoreManager); |
| 132 }; | 169 }; |
| 133 | 170 |
| 134 #endif // CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ | 171 #endif // CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ |
| OLD | NEW |