OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/renderer_host/backing_store_win.h" | 5 #include "content/browser/renderer_host/backing_store_win.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 hdr.bV5Intent = LCS_GM_IMAGES; | 39 hdr.bV5Intent = LCS_GM_IMAGES; |
40 } | 40 } |
41 | 41 |
42 void* data = NULL; | 42 void* data = NULL; |
43 HANDLE dib = CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&hdr), | 43 HANDLE dib = CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&hdr), |
44 0, &data, NULL, 0); | 44 0, &data, NULL, 0); |
45 DCHECK(data); | 45 DCHECK(data); |
46 return dib; | 46 return dib; |
47 } | 47 } |
48 | 48 |
49 void CallStretchDIBits(HDC hdc, int dest_x, int dest_y, int dest_w, int dest_h, | |
50 int src_x, int src_y, int src_w, int src_h, void* pixels, | |
51 const BITMAPINFO* bitmap_info) { | |
52 // When blitting a rectangle that touches the bottom, left corner of the | |
53 // bitmap, StretchDIBits looks at it top-down! For more details, see | |
54 // http://wiki.allegro.cc/index.php?title=StretchDIBits. | |
55 int rv; | |
56 int bitmap_h = -bitmap_info->bmiHeader.biHeight; | |
57 int bottom_up_src_y = bitmap_h - src_y - src_h; | |
58 if (bottom_up_src_y == 0 && src_x == 0 && src_h != bitmap_h) { | |
59 rv = StretchDIBits(hdc, | |
60 dest_x, dest_h + dest_y - 1, dest_w, -dest_h, | |
61 src_x, bitmap_h - src_y + 1, src_w, -src_h, | |
62 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | |
63 } else { | |
64 rv = StretchDIBits(hdc, | |
65 dest_x, dest_y, dest_w, dest_h, | |
66 src_x, bottom_up_src_y, src_w, src_h, | |
67 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | |
68 } | |
69 DCHECK(rv != GDI_ERROR); | |
70 } | |
71 | |
72 } // namespace | 49 } // namespace |
73 | 50 |
74 BackingStoreWin::BackingStoreWin(RenderWidgetHost* widget, | 51 BackingStoreWin::BackingStoreWin(RenderWidgetHost* widget, |
75 const gfx::Size& size) | 52 const gfx::Size& size) |
76 : BackingStore(widget, size), | 53 : BackingStore(widget, size), |
77 backing_store_dib_(NULL), | 54 backing_store_dib_(NULL), |
78 original_bitmap_(NULL) { | 55 original_bitmap_(NULL) { |
79 HDC screen_dc = ::GetDC(NULL); | 56 HDC screen_dc = ::GetDC(NULL); |
80 color_depth_ = ::GetDeviceCaps(screen_dc, BITSPIXEL); | 57 color_depth_ = ::GetDeviceCaps(screen_dc, BITSPIXEL); |
81 // Color depths less than 16 bpp require a palette to be specified. Instead, | 58 // Color depths less than 16 bpp require a palette to be specified. Instead, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 BITMAPINFOHEADER hdr; | 121 BITMAPINFOHEADER hdr; |
145 gfx::CreateBitmapHeader(pixel_bitmap_rect.width(), | 122 gfx::CreateBitmapHeader(pixel_bitmap_rect.width(), |
146 pixel_bitmap_rect.height(), &hdr); | 123 pixel_bitmap_rect.height(), &hdr); |
147 // Account for a bitmap_rect that exceeds the bounds of our view | 124 // Account for a bitmap_rect that exceeds the bounds of our view |
148 gfx::Rect view_rect(size()); | 125 gfx::Rect view_rect(size()); |
149 | 126 |
150 for (size_t i = 0; i < copy_rects.size(); i++) { | 127 for (size_t i = 0; i < copy_rects.size(); i++) { |
151 gfx::Rect paint_rect = gfx::IntersectRects(view_rect, copy_rects[i]); | 128 gfx::Rect paint_rect = gfx::IntersectRects(view_rect, copy_rects[i]); |
152 gfx::Rect pixel_copy_rect = gfx::ToEnclosedRect( | 129 gfx::Rect pixel_copy_rect = gfx::ToEnclosedRect( |
153 gfx::ScaleRect(paint_rect, scale_factor)); | 130 gfx::ScaleRect(paint_rect, scale_factor)); |
154 CallStretchDIBits(hdc_, | 131 gfx::StretchDIBits(hdc_, |
155 paint_rect.x(), | 132 paint_rect.x(), |
156 paint_rect.y(), | 133 paint_rect.y(), |
157 paint_rect.width(), | 134 paint_rect.width(), |
158 paint_rect.height(), | 135 paint_rect.height(), |
159 pixel_copy_rect.x() - pixel_bitmap_rect.x(), | 136 pixel_copy_rect.x() - pixel_bitmap_rect.x(), |
160 pixel_copy_rect.y() - pixel_bitmap_rect.y(), | 137 pixel_copy_rect.y() - pixel_bitmap_rect.y(), |
161 pixel_copy_rect.width(), | 138 pixel_copy_rect.width(), |
162 pixel_copy_rect.height(), | 139 pixel_copy_rect.height(), |
163 dib->memory(), | 140 dib->memory(), |
164 reinterpret_cast<BITMAPINFO*>(&hdr)); | 141 reinterpret_cast<BITMAPINFO*>(&hdr)); |
165 } | 142 } |
166 } | 143 } |
167 | 144 |
168 bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect, | 145 bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect, |
169 skia::PlatformBitmap* output) { | 146 skia::PlatformBitmap* output) { |
170 if (!output->Allocate(rect.width(), rect.height(), true)) | 147 if (!output->Allocate(rect.width(), rect.height(), true)) |
171 return false; | 148 return false; |
172 | 149 |
173 HDC temp_dc = output->GetSurface(); | 150 HDC temp_dc = output->GetSurface(); |
174 BitBlt(temp_dc, 0, 0, rect.width(), rect.height(), | 151 BitBlt(temp_dc, 0, 0, rect.width(), rect.height(), |
175 hdc(), rect.x(), rect.y(), SRCCOPY); | 152 hdc(), rect.x(), rect.y(), SRCCOPY); |
176 return true; | 153 return true; |
177 } | 154 } |
178 | 155 |
179 void BackingStoreWin::ScrollBackingStore(const gfx::Vector2d& delta, | 156 void BackingStoreWin::ScrollBackingStore(const gfx::Vector2d& delta, |
180 const gfx::Rect& clip_rect, | 157 const gfx::Rect& clip_rect, |
181 const gfx::Size& view_size) { | 158 const gfx::Size& view_size) { |
182 // TODO(darin): this doesn't work if delta x() and y() are both non-zero! | 159 // TODO(darin): this doesn't work if delta x() and y() are both non-zero! |
183 DCHECK(delta.x() == 0 || delta.y() == 0); | 160 DCHECK(delta.x() == 0 || delta.y() == 0); |
184 | 161 |
185 RECT damaged_rect, r = clip_rect.ToRECT(); | 162 RECT damaged_rect, r = clip_rect.ToRECT(); |
186 ScrollDC(hdc_, delta.x(), delta.y(), NULL, &r, NULL, &damaged_rect); | 163 ScrollDC(hdc_, delta.x(), delta.y(), NULL, &r, NULL, &damaged_rect); |
187 } | 164 } |
188 | 165 |
189 } // namespace content | 166 } // namespace content |
OLD | NEW |