Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: content/browser/renderer_host/backing_store_win.cc

Issue 12542006: Implemented browser side software compositing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed reninterpret_casts Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/renderer_host/image_transport_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 original_bitmap_ = SelectObject(hdc_, backing_store_dib_); 119 original_bitmap_ = SelectObject(hdc_, backing_store_dib_);
143 } 120 }
144 121
145 TransportDIB* dib = process->GetTransportDIB(bitmap); 122 TransportDIB* dib = process->GetTransportDIB(bitmap);
146 if (!dib) 123 if (!dib)
147 return; 124 return;
148 125
149 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosingRect( 126 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosingRect(
150 gfx::ScaleRect(bitmap_rect, scale_factor)); 127 gfx::ScaleRect(bitmap_rect, scale_factor));
151 128
152 BITMAPINFOHEADER hdr; 129 BITMAPINFO bitmap_info;
130 memset(&bitmap_info, 0, sizeof(bitmap_info));
153 gfx::CreateBitmapHeader(pixel_bitmap_rect.width(), 131 gfx::CreateBitmapHeader(pixel_bitmap_rect.width(),
154 pixel_bitmap_rect.height(), &hdr); 132 pixel_bitmap_rect.height(),
133 &bitmap_info.bmiHeader);
155 // Account for a bitmap_rect that exceeds the bounds of our view. 134 // Account for a bitmap_rect that exceeds the bounds of our view.
156 gfx::Rect view_rect(size()); 135 gfx::Rect view_rect(size());
157 136
158 for (size_t i = 0; i < copy_rects.size(); i++) { 137 for (size_t i = 0; i < copy_rects.size(); i++) {
159 gfx::Rect paint_rect = gfx::IntersectRects(view_rect, copy_rects[i]); 138 gfx::Rect paint_rect = gfx::IntersectRects(view_rect, copy_rects[i]);
160 gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect( 139 gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect(
161 gfx::ScaleRect(paint_rect, scale_factor)); 140 gfx::ScaleRect(paint_rect, scale_factor));
162 gfx::Rect target_rect = pixel_copy_rect; 141 gfx::Rect target_rect = pixel_copy_rect;
163 CallStretchDIBits(hdc_, 142 gfx::StretchDIBits(hdc_,
164 target_rect.x(), 143 target_rect.x(),
165 target_rect.y(), 144 target_rect.y(),
166 target_rect.width(), 145 target_rect.width(),
167 target_rect.height(), 146 target_rect.height(),
168 pixel_copy_rect.x() - pixel_bitmap_rect.x(), 147 pixel_copy_rect.x() - pixel_bitmap_rect.x(),
169 pixel_copy_rect.y() - pixel_bitmap_rect.y(), 148 pixel_copy_rect.y() - pixel_bitmap_rect.y(),
170 pixel_copy_rect.width(), 149 pixel_copy_rect.width(),
171 pixel_copy_rect.height(), 150 pixel_copy_rect.height(),
172 dib->memory(), 151 dib->memory(),
173 reinterpret_cast<BITMAPINFO*>(&hdr)); 152 &bitmap_info);
174 } 153 }
175 } 154 }
176 155
177 bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect, 156 bool BackingStoreWin::CopyFromBackingStore(const gfx::Rect& rect,
178 skia::PlatformBitmap* output) { 157 skia::PlatformBitmap* output) {
179 // TODO(kevers): Make sure this works with HiDPI backing stores. 158 // TODO(kevers): Make sure this works with HiDPI backing stores.
180 if (!output->Allocate(rect.width(), rect.height(), true)) 159 if (!output->Allocate(rect.width(), rect.height(), true))
181 return false; 160 return false;
182 161
183 HDC temp_dc = output->GetSurface(); 162 HDC temp_dc = output->GetSurface();
(...skipping 11 matching lines...) Expand all
195 float scale = ui::win::GetDeviceScaleFactor(); 174 float scale = ui::win::GetDeviceScaleFactor();
196 gfx::Rect screen_rect = gfx::ToEnclosingRect( 175 gfx::Rect screen_rect = gfx::ToEnclosingRect(
197 gfx::ScaleRect(clip_rect, scale)); 176 gfx::ScaleRect(clip_rect, scale));
198 int dx = static_cast<int>(delta.x() * scale); 177 int dx = static_cast<int>(delta.x() * scale);
199 int dy = static_cast<int>(delta.y() * scale); 178 int dy = static_cast<int>(delta.y() * scale);
200 RECT damaged_rect, r = screen_rect.ToRECT(); 179 RECT damaged_rect, r = screen_rect.ToRECT();
201 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect); 180 ScrollDC(hdc_, dx, dy, NULL, &r, NULL, &damaged_rect);
202 } 181 }
203 182
204 } // namespace content 183 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/image_transport_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698