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

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

Issue 11270042: Add non-member non-mutating methods for common gfx::Rect operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 1 month 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
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_aura.h" 5 #include "content/browser/renderer_host/backing_store_aura.h"
6 6
7 #include "content/browser/renderer_host/dip_util.h" 7 #include "content/browser/renderer_host/dip_util.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/public/browser/render_widget_host.h" 9 #include "content/public/browser/render_widget_host.h"
10 #include "skia/ext/platform_canvas.h" 10 #include "skia/ext/platform_canvas.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 TransportDIB::Id bitmap, 84 TransportDIB::Id bitmap,
85 const gfx::Rect& bitmap_rect, 85 const gfx::Rect& bitmap_rect,
86 const std::vector<gfx::Rect>& copy_rects, 86 const std::vector<gfx::Rect>& copy_rects,
87 float scale_factor, 87 float scale_factor,
88 const base::Closure& completion_callback, 88 const base::Closure& completion_callback,
89 bool* scheduled_completion_callback) { 89 bool* scheduled_completion_callback) {
90 *scheduled_completion_callback = false; 90 *scheduled_completion_callback = false;
91 if (bitmap_rect.IsEmpty()) 91 if (bitmap_rect.IsEmpty())
92 return; 92 return;
93 93
94 gfx::RectF scaled_bitmap_rect = bitmap_rect; 94 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosedRect(
95 scaled_bitmap_rect.Scale(scale_factor); 95 gfx::ScaleRect(bitmap_rect, scale_factor));
96 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosedRect(scaled_bitmap_rect);
97 96
98 const int width = pixel_bitmap_rect.width(); 97 const int width = pixel_bitmap_rect.width();
99 const int height = pixel_bitmap_rect.height(); 98 const int height = pixel_bitmap_rect.height();
100 99
101 if (width <= 0 || width > kMaxVideoLayerSize || 100 if (width <= 0 || width > kMaxVideoLayerSize ||
102 height <= 0 || height > kMaxVideoLayerSize) 101 height <= 0 || height > kMaxVideoLayerSize)
103 return; 102 return;
104 103
105 TransportDIB* dib = process->GetTransportDIB(bitmap); 104 TransportDIB* dib = process->GetTransportDIB(bitmap);
106 if (!dib) 105 if (!dib)
107 return; 106 return;
108 107
109 SkPaint copy_paint; 108 SkPaint copy_paint;
110 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); 109 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
111 110
112 SkBitmap sk_bitmap; 111 SkBitmap sk_bitmap;
113 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 112 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
114 sk_bitmap.setPixels(dib->memory()); 113 sk_bitmap.setPixels(dib->memory());
115 for (size_t i = 0; i < copy_rects.size(); i++) { 114 for (size_t i = 0; i < copy_rects.size(); i++) {
116 gfx::RectF scaled_copy_rect = copy_rects[i]; 115 const gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect(
117 scaled_copy_rect.Scale(scale_factor); 116 gfx::ScaleRect(copy_rects[i], scale_factor));
118 const gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect(scaled_copy_rect);
119 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); 117 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x();
120 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); 118 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y();
121 SkIRect srcrect = SkIRect::MakeXYWH(x, y, 119 SkIRect srcrect = SkIRect::MakeXYWH(x, y,
122 pixel_copy_rect.width(), 120 pixel_copy_rect.width(),
123 pixel_copy_rect.height()); 121 pixel_copy_rect.height());
124 122
125 gfx::RectF scaled_copy_dst_rect = copy_rects[i]; 123 const gfx::Rect pixel_copy_dst_rect = gfx::ToEnclosingRect(
126 scaled_copy_dst_rect.Scale(device_scale_factor_); 124 gfx::ScaleRect(copy_rects[i], device_scale_factor_));
127 const gfx::Rect pixel_copy_dst_rect =
128 gfx::ToEnclosingRect(scaled_copy_dst_rect);
129 SkRect dstrect = SkRect::MakeXYWH( 125 SkRect dstrect = SkRect::MakeXYWH(
130 SkIntToScalar(pixel_copy_dst_rect.x()), 126 SkIntToScalar(pixel_copy_dst_rect.x()),
131 SkIntToScalar(pixel_copy_dst_rect.y()), 127 SkIntToScalar(pixel_copy_dst_rect.y()),
132 SkIntToScalar(pixel_copy_dst_rect.width()), 128 SkIntToScalar(pixel_copy_dst_rect.width()),
133 SkIntToScalar(pixel_copy_dst_rect.height())); 129 SkIntToScalar(pixel_copy_dst_rect.height()));
134 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint); 130 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint);
135 } 131 }
136 } 132 }
137 133
138 void BackingStoreAura::ScrollBackingStore(int dx, int dy, 134 void BackingStoreAura::ScrollBackingStore(int dx, int dy,
139 const gfx::Rect& clip_rect, 135 const gfx::Rect& clip_rect,
140 const gfx::Size& view_size) { 136 const gfx::Size& view_size) {
141 gfx::RectF scaled_clip_rect = clip_rect; 137 gfx::Rect pixel_rect = gfx::ToEnclosingRect(
142 scaled_clip_rect.Scale(device_scale_factor_); 138 gfx::ScaleRect(clip_rect, device_scale_factor_));
143 gfx::Rect pixel_rect = gfx::ToEnclosingRect(scaled_clip_rect);
144 int pixel_dx = dx * device_scale_factor_; 139 int pixel_dx = dx * device_scale_factor_;
145 int pixel_dy = dy * device_scale_factor_; 140 int pixel_dy = dy * device_scale_factor_;
146 141
147 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); 142 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx);
148 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); 143 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy);
149 int w = pixel_rect.width() + abs(pixel_dx); 144 int w = pixel_rect.width() + abs(pixel_dx);
150 int h = pixel_rect.height() + abs(pixel_dy); 145 int h = pixel_rect.height() + abs(pixel_dy);
151 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); 146 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
152 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); 147 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy);
153 } 148 }
154 149
155 bool BackingStoreAura::CopyFromBackingStore(const gfx::Rect& rect, 150 bool BackingStoreAura::CopyFromBackingStore(const gfx::Rect& rect,
156 skia::PlatformBitmap* output) { 151 skia::PlatformBitmap* output) {
157 const int width = 152 const int width =
158 std::min(size().width(), rect.width()) * device_scale_factor_; 153 std::min(size().width(), rect.width()) * device_scale_factor_;
159 const int height = 154 const int height =
160 std::min(size().height(), rect.height()) * device_scale_factor_; 155 std::min(size().height(), rect.height()) * device_scale_factor_;
161 if (!output->Allocate(width, height, true)) 156 if (!output->Allocate(width, height, true))
162 return false; 157 return false;
163 158
164 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); 159 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height);
165 SkBitmap b; 160 SkBitmap b;
166 if (!canvas_->readPixels(skrect, &b)) 161 if (!canvas_->readPixels(skrect, &b))
167 return false; 162 return false;
168 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y()); 163 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y());
169 return true; 164 return true;
170 } 165 }
171 166
172 } // namespace content 167 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar_view.cc ('k') | content/browser/renderer_host/backing_store_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698