| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_win.h" | 5 #include "chrome/browser/renderer_host/backing_store_win.h" |
| 6 | 6 |
| 7 #include "app/surface/transport_dib.h" | 7 #include "app/surface/transport_dib.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "chrome/browser/renderer_host/render_process_host.h" | 9 #include "chrome/browser/renderer_host/render_process_host.h" |
| 10 #include "chrome/browser/renderer_host/render_widget_host.h" | 10 #include "chrome/browser/renderer_host/render_widget_host.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 rv = StretchDIBits(hdc, | 62 rv = StretchDIBits(hdc, |
| 63 dest_x, dest_y, dest_w, dest_h, | 63 dest_x, dest_y, dest_w, dest_h, |
| 64 src_x, bottom_up_src_y, src_w, src_h, | 64 src_x, bottom_up_src_y, src_w, src_h, |
| 65 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); | 65 pixels, bitmap_info, DIB_RGB_COLORS, SRCCOPY); |
| 66 } | 66 } |
| 67 DCHECK(rv != GDI_ERROR); | 67 DCHECK(rv != GDI_ERROR); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 BackingStoreWin::BackingStoreWin(RenderWidgetHost* widget, const gfx::Size& size
) | 72 BackingStoreWin::BackingStoreWin(RenderWidgetHost* widget, |
| 73 const gfx::Size& size) |
| 73 : BackingStore(widget, size), | 74 : BackingStore(widget, size), |
| 74 backing_store_dib_(NULL), | 75 backing_store_dib_(NULL), |
| 75 original_bitmap_(NULL) { | 76 original_bitmap_(NULL) { |
| 76 HDC screen_dc = ::GetDC(NULL); | 77 HDC screen_dc = ::GetDC(NULL); |
| 77 color_depth_ = ::GetDeviceCaps(screen_dc, BITSPIXEL); | 78 color_depth_ = ::GetDeviceCaps(screen_dc, BITSPIXEL); |
| 78 // Color depths less than 16 bpp require a palette to be specified. Instead, | 79 // Color depths less than 16 bpp require a palette to be specified. Instead, |
| 79 // we specify the desired color depth as 16 which lets the OS to come up | 80 // we specify the desired color depth as 16 which lets the OS to come up |
| 80 // with an approximation. | 81 // with an approximation. |
| 81 if (color_depth_ < 16) | 82 if (color_depth_ < 16) |
| 82 color_depth_ = 16; | 83 color_depth_ = 16; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 } | 108 } |
| 108 return enabled; | 109 return enabled; |
| 109 } | 110 } |
| 110 | 111 |
| 111 size_t BackingStoreWin::MemorySize() { | 112 size_t BackingStoreWin::MemorySize() { |
| 112 return size().GetArea() * (color_depth_ / 8); | 113 return size().GetArea() * (color_depth_ / 8); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void BackingStoreWin::PaintToBackingStore( | 116 void BackingStoreWin::PaintToBackingStore( |
| 116 RenderProcessHost* process, | 117 RenderProcessHost* process, |
| 117 TransportDIB::Id bitmap, | 118 TransportDIB::Id dib_id, |
| 119 TransportDIB::Handle dib_handle, |
| 118 const gfx::Rect& bitmap_rect, | 120 const gfx::Rect& bitmap_rect, |
| 119 const std::vector<gfx::Rect>& copy_rects, | 121 const std::vector<gfx::Rect>& copy_rects, |
| 120 bool* painted_synchronously) { | 122 bool* painted_synchronously) { |
| 123 TransportDIB::ScopedHandle scoped_dib_handle(dib_handle); |
| 121 // Our paints are always synchronous and the TransportDIB can be freed when | 124 // Our paints are always synchronous and the TransportDIB can be freed when |
| 122 // we're done (even on error). | 125 // we're done (even on error). |
| 123 *painted_synchronously = true; | 126 *painted_synchronously = true; |
| 124 | 127 |
| 125 if (!backing_store_dib_) { | 128 if (!backing_store_dib_) { |
| 126 backing_store_dib_ = CreateDIB(hdc_, size().width(), | 129 backing_store_dib_ = CreateDIB(hdc_, size().width(), |
| 127 size().height(), color_depth_); | 130 size().height(), color_depth_); |
| 128 if (!backing_store_dib_) { | 131 if (!backing_store_dib_) { |
| 129 NOTREACHED(); | 132 NOTREACHED(); |
| 130 return; | 133 return; |
| 131 } | 134 } |
| 132 original_bitmap_ = SelectObject(hdc_, backing_store_dib_); | 135 original_bitmap_ = SelectObject(hdc_, backing_store_dib_); |
| 133 } | 136 } |
| 134 | 137 |
| 135 TransportDIB* dib = process->GetTransportDIB(bitmap); | 138 TransportDIB* dib = process->GetTransportDIB(dib_id, |
| 139 scoped_dib_handle.release()); |
| 136 if (!dib) | 140 if (!dib) |
| 137 return; | 141 return; |
| 138 | 142 |
| 139 BITMAPINFOHEADER hdr; | 143 BITMAPINFOHEADER hdr; |
| 140 gfx::CreateBitmapHeader(bitmap_rect.width(), bitmap_rect.height(), &hdr); | 144 gfx::CreateBitmapHeader(bitmap_rect.width(), bitmap_rect.height(), &hdr); |
| 141 // Account for a bitmap_rect that exceeds the bounds of our view | 145 // Account for a bitmap_rect that exceeds the bounds of our view |
| 142 gfx::Rect view_rect(size()); | 146 gfx::Rect view_rect(size()); |
| 143 | 147 |
| 144 for (size_t i = 0; i < copy_rects.size(); i++) { | 148 for (size_t i = 0; i < copy_rects.size(); i++) { |
| 145 gfx::Rect paint_rect = view_rect.Intersect(copy_rects[i]); | 149 gfx::Rect paint_rect = view_rect.Intersect(copy_rects[i]); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 | 175 |
| 172 void BackingStoreWin::ScrollBackingStore(int dx, int dy, | 176 void BackingStoreWin::ScrollBackingStore(int dx, int dy, |
| 173 const gfx::Rect& clip_rect, | 177 const gfx::Rect& clip_rect, |
| 174 const gfx::Size& view_size) { | 178 const gfx::Size& view_size) { |
| 175 RECT damaged_rect, r = clip_rect.ToRECT(); | 179 RECT damaged_rect, r = clip_rect.ToRECT(); |
| 176 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); | 180 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); |
| 177 | 181 |
| 178 // TODO(darin): this doesn't work if dx and dy are both non-zero! | 182 // TODO(darin): this doesn't work if dx and dy are both non-zero! |
| 179 DCHECK(dx == 0 || dy == 0); | 183 DCHECK(dx == 0 || dy == 0); |
| 180 } | 184 } |
| OLD | NEW |