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 #include "chrome/browser/renderer_host/backing_store.h" | 5 #include "chrome/browser/renderer_host/backing_store.h" |
6 | 6 |
7 #include "base/gfx/gdi_util.h" | 7 #include "base/gfx/gdi_util.h" |
8 #include "chrome/browser/renderer_host/render_widget_host.h" | 8 #include "chrome/browser/renderer_host/render_widget_host.h" |
9 #include "chrome/common/win_util.h" | 9 #include "chrome/common/transport_dib.h" |
10 | 10 |
11 // BackingStore (Windows) ------------------------------------------------------ | 11 // BackingStore (Windows) ------------------------------------------------------ |
12 | 12 |
13 BackingStore::BackingStore(const gfx::Size& size) | 13 BackingStore::BackingStore(const gfx::Size& size) |
14 : size_(size), | 14 : size_(size), |
15 backing_store_dib_(NULL), | 15 backing_store_dib_(NULL), |
16 original_bitmap_(NULL) { | 16 original_bitmap_(NULL) { |
17 HDC screen_dc = ::GetDC(NULL); | 17 HDC screen_dc = ::GetDC(NULL); |
18 hdc_ = CreateCompatibleDC(screen_dc); | 18 hdc_ = CreateCompatibleDC(screen_dc); |
19 ReleaseDC(NULL, screen_dc); | 19 ReleaseDC(NULL, screen_dc); |
20 } | 20 } |
21 | 21 |
22 BackingStore::~BackingStore() { | 22 BackingStore::~BackingStore() { |
23 DCHECK(hdc_); | 23 DCHECK(hdc_); |
24 | 24 |
25 DeleteDC(hdc_); | 25 DeleteDC(hdc_); |
26 | 26 |
27 if (backing_store_dib_) { | 27 if (backing_store_dib_) { |
28 DeleteObject(backing_store_dib_); | 28 DeleteObject(backing_store_dib_); |
29 backing_store_dib_ = NULL; | 29 backing_store_dib_ = NULL; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 bool BackingStore::PaintRect(base::ProcessHandle process, | 33 bool BackingStore::PaintRect(base::ProcessHandle process, |
34 BitmapWireData bitmap_section, | 34 TransportDIB* bitmap, |
cpu_(ooo_6.6-7.5)
2009/02/20 00:28:07
When merging my change and your change, we should
| |
35 const gfx::Rect& bitmap_rect) { | 35 const gfx::Rect& bitmap_rect) { |
36 // The bitmap received is valid only in the renderer process. | |
37 HANDLE valid_bitmap = | |
38 win_util::GetSectionFromProcess(bitmap_section, process, false); | |
39 if (!valid_bitmap) | |
40 return false; | |
41 | |
42 if (!backing_store_dib_) { | 36 if (!backing_store_dib_) { |
43 backing_store_dib_ = CreateDIB(hdc_, size_.width(), size_.height(), true, | 37 backing_store_dib_ = CreateDIB(hdc_, size_.width(), size_.height(), true, |
44 NULL); | 38 NULL); |
45 DCHECK(backing_store_dib_ != NULL); | 39 DCHECK(backing_store_dib_ != NULL); |
46 original_bitmap_ = SelectObject(hdc_, backing_store_dib_); | 40 original_bitmap_ = SelectObject(hdc_, backing_store_dib_); |
47 } | 41 } |
48 | 42 |
49 // TODO(darin): protect against integer overflow | 43 // TODO(darin): protect against integer overflow |
50 DWORD size = 4 * bitmap_rect.width() * bitmap_rect.height(); | 44 DWORD size = 4 * bitmap_rect.width() * bitmap_rect.height(); |
51 void* backing_store_data = MapViewOfFile(valid_bitmap, FILE_MAP_READ, 0, 0, | 45 |
52 size); | |
53 // These values are shared with gfx::PlatformDevice | 46 // These values are shared with gfx::PlatformDevice |
54 BITMAPINFOHEADER hdr; | 47 BITMAPINFOHEADER hdr; |
55 gfx::CreateBitmapHeader(bitmap_rect.width(), bitmap_rect.height(), &hdr); | 48 gfx::CreateBitmapHeader(bitmap_rect.width(), bitmap_rect.height(), &hdr); |
56 // Account for a bitmap_rect that exceeds the bounds of our view | 49 // Account for a bitmap_rect that exceeds the bounds of our view |
57 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); | 50 gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
58 gfx::Rect paint_rect = view_rect.Intersect(bitmap_rect); | 51 gfx::Rect paint_rect = view_rect.Intersect(bitmap_rect); |
59 | 52 |
60 StretchDIBits(hdc_, | 53 StretchDIBits(hdc_, |
61 paint_rect.x(), | 54 paint_rect.x(), |
62 paint_rect.y(), | 55 paint_rect.y(), |
63 paint_rect.width(), | 56 paint_rect.width(), |
64 paint_rect.height(), | 57 paint_rect.height(), |
65 0, 0, // source x,y | 58 0, 0, // source x,y |
66 paint_rect.width(), | 59 paint_rect.width(), |
67 paint_rect.height(), | 60 paint_rect.height(), |
68 backing_store_data, | 61 bitmap->memory(), |
69 reinterpret_cast<BITMAPINFO*>(&hdr), | 62 reinterpret_cast<BITMAPINFO*>(&hdr), |
70 DIB_RGB_COLORS, | 63 DIB_RGB_COLORS, |
71 SRCCOPY); | 64 SRCCOPY); |
72 | 65 |
73 UnmapViewOfFile(backing_store_data); | |
74 CloseHandle(valid_bitmap); | |
75 return true; | 66 return true; |
76 } | 67 } |
77 | 68 |
78 void BackingStore::ScrollRect(base::ProcessHandle process, | 69 void BackingStore::ScrollRect(base::ProcessHandle process, |
79 BitmapWireData bitmap, | 70 TransportDIB* bitmap, |
80 const gfx::Rect& bitmap_rect, | 71 const gfx::Rect& bitmap_rect, |
81 int dx, int dy, | 72 int dx, int dy, |
82 const gfx::Rect& clip_rect, | 73 const gfx::Rect& clip_rect, |
83 const gfx::Size& view_size) { | 74 const gfx::Size& view_size) { |
84 RECT damaged_rect, r = clip_rect.ToRECT(); | 75 RECT damaged_rect, r = clip_rect.ToRECT(); |
85 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); | 76 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); |
86 | 77 |
87 // TODO(darin): this doesn't work if dx and dy are both non-zero! | 78 // TODO(darin): this doesn't work if dx and dy are both non-zero! |
88 DCHECK(dx == 0 || dy == 0); | 79 DCHECK(dx == 0 || dy == 0); |
89 | 80 |
(...skipping 24 matching lines...) Expand all Loading... | |
114 gfx::CreateBitmapHeaderWithColorDepth(width, height, color_depth, &hdr); | 105 gfx::CreateBitmapHeaderWithColorDepth(width, height, color_depth, &hdr); |
115 } else { | 106 } else { |
116 gfx::CreateBitmapHeader(width, height, &hdr); | 107 gfx::CreateBitmapHeader(width, height, &hdr); |
117 } | 108 } |
118 void* data = NULL; | 109 void* data = NULL; |
119 HANDLE dib = | 110 HANDLE dib = |
120 CreateDIBSection(hdc_, reinterpret_cast<BITMAPINFO*>(&hdr), | 111 CreateDIBSection(hdc_, reinterpret_cast<BITMAPINFO*>(&hdr), |
121 0, &data, section, 0); | 112 0, &data, section, 0); |
122 return dib; | 113 return dib; |
123 } | 114 } |
OLD | NEW |