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_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" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/rect_conversions.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 // Assume that somewhere along the line, someone will do width * height * 4 | 19 // Assume that somewhere along the line, someone will do width * height * 4 |
19 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = | 20 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = |
20 // 2**29 and floor(sqrt(2**29)) = 23170. | 21 // 2**29 and floor(sqrt(2**29)) = 23170. |
21 | 22 |
22 // Max height and width for layers | 23 // Max height and width for layers |
23 static const int kMaxVideoLayerSize = 23170; | 24 static const int kMaxVideoLayerSize = 23170; |
24 | 25 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 TransportDIB::Id bitmap, | 81 TransportDIB::Id bitmap, |
81 const gfx::Rect& bitmap_rect, | 82 const gfx::Rect& bitmap_rect, |
82 const std::vector<gfx::Rect>& copy_rects, | 83 const std::vector<gfx::Rect>& copy_rects, |
83 float scale_factor, | 84 float scale_factor, |
84 const base::Closure& completion_callback, | 85 const base::Closure& completion_callback, |
85 bool* scheduled_completion_callback) { | 86 bool* scheduled_completion_callback) { |
86 *scheduled_completion_callback = false; | 87 *scheduled_completion_callback = false; |
87 if (bitmap_rect.IsEmpty()) | 88 if (bitmap_rect.IsEmpty()) |
88 return; | 89 return; |
89 | 90 |
90 gfx::Rect pixel_bitmap_rect = bitmap_rect.Scale(scale_factor); | 91 gfx::Rect pixel_bitmap_rect = |
| 92 gfx::ToEnclosingRect(bitmap_rect.Scale(scale_factor)); |
91 | 93 |
92 const int width = pixel_bitmap_rect.width(); | 94 const int width = pixel_bitmap_rect.width(); |
93 const int height = pixel_bitmap_rect.height(); | 95 const int height = pixel_bitmap_rect.height(); |
94 | 96 |
95 if (width <= 0 || width > kMaxVideoLayerSize || | 97 if (width <= 0 || width > kMaxVideoLayerSize || |
96 height <= 0 || height > kMaxVideoLayerSize) | 98 height <= 0 || height > kMaxVideoLayerSize) |
97 return; | 99 return; |
98 | 100 |
99 TransportDIB* dib = process->GetTransportDIB(bitmap); | 101 TransportDIB* dib = process->GetTransportDIB(bitmap); |
100 if (!dib) | 102 if (!dib) |
101 return; | 103 return; |
102 | 104 |
103 SkPaint copy_paint; | 105 SkPaint copy_paint; |
104 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 106 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
105 | 107 |
106 SkBitmap sk_bitmap; | 108 SkBitmap sk_bitmap; |
107 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 109 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
108 sk_bitmap.setPixels(dib->memory()); | 110 sk_bitmap.setPixels(dib->memory()); |
109 for (size_t i = 0; i < copy_rects.size(); i++) { | 111 for (size_t i = 0; i < copy_rects.size(); i++) { |
110 const gfx::Rect pixel_copy_rect = copy_rects[i].Scale(scale_factor); | 112 const gfx::Rect pixel_copy_rect = |
| 113 gfx::ToEnclosingRect(copy_rects[i].Scale(scale_factor)); |
111 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); | 114 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); |
112 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); | 115 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); |
113 SkIRect srcrect = SkIRect::MakeXYWH(x, y, | 116 SkIRect srcrect = SkIRect::MakeXYWH(x, y, |
114 pixel_copy_rect.width(), | 117 pixel_copy_rect.width(), |
115 pixel_copy_rect.height()); | 118 pixel_copy_rect.height()); |
116 | 119 |
117 const gfx::Rect pixel_copy_dst_rect = | 120 const gfx::Rect pixel_copy_dst_rect = |
118 copy_rects[i].Scale(device_scale_factor_); | 121 gfx::ToEnclosingRect(copy_rects[i].Scale(device_scale_factor_)); |
119 SkRect dstrect = SkRect::MakeXYWH( | 122 SkRect dstrect = SkRect::MakeXYWH( |
120 SkIntToScalar(pixel_copy_dst_rect.x()), | 123 SkIntToScalar(pixel_copy_dst_rect.x()), |
121 SkIntToScalar(pixel_copy_dst_rect.y()), | 124 SkIntToScalar(pixel_copy_dst_rect.y()), |
122 SkIntToScalar(pixel_copy_dst_rect.width()), | 125 SkIntToScalar(pixel_copy_dst_rect.width()), |
123 SkIntToScalar(pixel_copy_dst_rect.height())); | 126 SkIntToScalar(pixel_copy_dst_rect.height())); |
124 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); | 127 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); |
125 } | 128 } |
126 } | 129 } |
127 | 130 |
128 void BackingStoreAura::ScrollBackingStore(int dx, int dy, | 131 void BackingStoreAura::ScrollBackingStore(int dx, int dy, |
129 const gfx::Rect& clip_rect, | 132 const gfx::Rect& clip_rect, |
130 const gfx::Size& view_size) { | 133 const gfx::Size& view_size) { |
131 gfx::Rect pixel_rect = clip_rect.Scale(device_scale_factor_); | 134 gfx::Rect pixel_rect = |
| 135 gfx::ToEnclosingRect(clip_rect.Scale(device_scale_factor_)); |
132 int pixel_dx = dx * device_scale_factor_; | 136 int pixel_dx = dx * device_scale_factor_; |
133 int pixel_dy = dy * device_scale_factor_; | 137 int pixel_dy = dy * device_scale_factor_; |
134 | 138 |
135 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); | 139 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); |
136 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); | 140 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); |
137 int w = pixel_rect.width() + abs(pixel_dx); | 141 int w = pixel_rect.width() + abs(pixel_dx); |
138 int h = pixel_rect.height() + abs(pixel_dy); | 142 int h = pixel_rect.height() + abs(pixel_dy); |
139 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); | 143 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
140 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); | 144 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); |
141 } | 145 } |
(...skipping 10 matching lines...) Expand all Loading... |
152 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); | 156 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); |
153 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 157 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
154 SkBitmap b; | 158 SkBitmap b; |
155 if (!canvas_->readPixels(skrect, &b)) | 159 if (!canvas_->readPixels(skrect, &b)) |
156 return false; | 160 return false; |
157 output->writePixels(b, rect.x(), rect.y()); | 161 output->writePixels(b, rect.x(), rect.y()); |
158 return true; | 162 return true; |
159 } | 163 } |
160 | 164 |
161 } // namespace content | 165 } // namespace content |
OLD | NEW |