| 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 30 matching lines...) Expand all Loading... |
| 41 hdr.bV5Intent = LCS_GM_IMAGES; | 41 hdr.bV5Intent = LCS_GM_IMAGES; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void* data = NULL; | 44 void* data = NULL; |
| 45 HANDLE dib = CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&hdr), | 45 HANDLE dib = CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&hdr), |
| 46 0, &data, NULL, 0); | 46 0, &data, NULL, 0); |
| 47 DCHECK(data); | 47 DCHECK(data); |
| 48 return dib; | 48 return dib; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void CallStretchDIBits(HDC hdc, int dest_x, int dest_y, int dest_w, int dest_h, | |
| 52 int src_x, int src_y, int src_w, int src_h, void* pixels, | |
| 53 const BITMAPINFO* bitmap_info) { | |
| 54 // When blitting a rectangle that touches the bottom, left corner of the | |
| 55 // bitmap, StretchDIBits looks at it top-down! For more details, see | |
| 56 // http://wiki.allegro.cc/index.php?title=StretchDIBits. | |
| 57 int rv; | |
| 58 int bitmap_h = -bitmap_info->bmiHeader.biHeight; | |
| 59 int bottom_up_src_y = bitmap_h - src_y - src_h; | |
| 60 if (bottom_up_src_y == 0 && src_x == 0 && src_h != bitmap_h) { | |
| 61 rv = StretchDIBits(hdc, | |
| 62 dest_x, dest_h + dest_y - 1, dest_w, -dest_h, | |
| 63 src_x, bitmap_h - src_y + 1, src_w, -src_h, | |
| 64 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | |
| 65 } else { | |
| 66 rv = StretchDIBits(hdc, | |
| 67 dest_x, dest_y, dest_w, dest_h, | |
| 68 src_x, bottom_up_src_y, src_w, src_h, | |
| 69 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | |
| 70 } | |
| 71 DCHECK(rv != GDI_ERROR); | |
| 72 } | |
| 73 | |
| 74 } // namespace | 51 } // namespace |
| 75 | 52 |
| 76 BackingStoreWin::BackingStoreWin(RenderWidgetHost* widget, | 53 BackingStoreWin::BackingStoreWin(RenderWidgetHost* widget, |
| 77 const gfx::Size& size) | 54 const gfx::Size& size) |
| 78 : BackingStore(widget, size), | 55 : BackingStore(widget, size), |
| 79 backing_store_dib_(NULL), | 56 backing_store_dib_(NULL), |
| 80 original_bitmap_(NULL) { | 57 original_bitmap_(NULL) { |
| 81 HDC screen_dc = ::GetDC(NULL); | 58 HDC screen_dc = ::GetDC(NULL); |
| 82 color_depth_ = ::GetDeviceCaps(screen_dc, BITSPIXEL); | 59 color_depth_ = ::GetDeviceCaps(screen_dc, BITSPIXEL); |
| 83 // Color depths less than 16 bpp require a palette to be specified. Instead, | 60 // Color depths less than 16 bpp require a palette to be specified. Instead, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 gfx::CreateBitmapHeader(pixel_bitmap_rect.width(), | 130 gfx::CreateBitmapHeader(pixel_bitmap_rect.width(), |
| 154 pixel_bitmap_rect.height(), &hdr); | 131 pixel_bitmap_rect.height(), &hdr); |
| 155 // Account for a bitmap_rect that exceeds the bounds of our view. | 132 // Account for a bitmap_rect that exceeds the bounds of our view. |
| 156 gfx::Rect view_rect(size()); | 133 gfx::Rect view_rect(size()); |
| 157 | 134 |
| 158 for (size_t i = 0; i < copy_rects.size(); i++) { | 135 for (size_t i = 0; i < copy_rects.size(); i++) { |
| 159 gfx::Rect paint_rect = gfx::IntersectRects(view_rect, copy_rects[i]); | 136 gfx::Rect paint_rect = gfx::IntersectRects(view_rect, copy_rects[i]); |
| 160 gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect( | 137 gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect( |
| 161 gfx::ScaleRect(paint_rect, scale_factor)); | 138 gfx::ScaleRect(paint_rect, scale_factor)); |
| 162 gfx::Rect target_rect = pixel_copy_rect; | 139 gfx::Rect target_rect = pixel_copy_rect; |
| 163 CallStretchDIBits(hdc_, | 140 gfx::StretchDIBits(hdc_, |
| 164 target_rect.x(), | 141 target_rect.x(), |
| 165 target_rect.y(), | 142 target_rect.y(), |
| 166 target_rect.width(), | 143 target_rect.width(), |
| 167 target_rect.height(), | 144 target_rect.height(), |
| 168 pixel_copy_rect.x() - pixel_bitmap_rect.x(), | 145 pixel_copy_rect.x() - pixel_bitmap_rect.x(), |
| 169 pixel_copy_rect.y() - pixel_bitmap_rect.y(), | 146 pixel_copy_rect.y() - pixel_bitmap_rect.y(), |
| 170 pixel_copy_rect.width(), | 147 pixel_copy_rect.width(), |
| 171 pixel_copy_rect.height(), | 148 pixel_copy_rect.height(), |
| 172 dib->memory(), | 149 dib->memory(), |
| 173 reinterpret_cast<BITMAPINFO*>(&hdr)); | 150 reinterpret_cast<BITMAPINFO*>(&hdr)); |
| 174 } | 151 } |
| 175 } | 152 } |
| 176 | 153 |
| 177 bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect, | 154 bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect, |
| 178 skia::PlatformBitmap* output) { | 155 skia::PlatformBitmap* output) { |
| 179 // TODO(kevers): Make sure this works with HiDPI backing stores. | 156 // TODO(kevers): Make sure this works with HiDPI backing stores. |
| 180 if (!output->Allocate(rect.width(), rect.height(), true)) | 157 if (!output->Allocate(rect.width(), rect.height(), true)) |
| 181 return false; | 158 return false; |
| 182 | 159 |
| 183 HDC temp_dc = output->GetSurface(); | 160 HDC temp_dc = output->GetSurface(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 195 float scale = ui::win::GetDeviceScaleFactor(); | 172 float scale = ui::win::GetDeviceScaleFactor(); |
| 196 gfx::Rect screen_rect = gfx::ToEnclosingRect( | 173 gfx::Rect screen_rect = gfx::ToEnclosingRect( |
| 197 gfx::ScaleRect(clip_rect, scale)); | 174 gfx::ScaleRect(clip_rect, scale)); |
| 198 int dx = static_cast<int>(delta.x() * scale); | 175 int dx = static_cast<int>(delta.x() * scale); |
| 199 int dy = static_cast<int>(delta.y() * scale); | 176 int dy = static_cast<int>(delta.y() * scale); |
| 200 RECT damaged_rect, r = screen_rect.ToRECT(); | 177 RECT damaged_rect, r = screen_rect.ToRECT(); |
| 201 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); | 178 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); |
| 202 } | 179 } |
| 203 | 180 |
| 204 } // namespace content | 181 } // namespace content |
| OLD | NEW |