| 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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::Rect pixel_bitmap_rect = | 94 gfx::RectF scaled_bitmap_rect = bitmap_rect; |
| 95 gfx::ToEnclosedRect(bitmap_rect.Scale(scale_factor)); | 95 scaled_bitmap_rect.Scale(scale_factor); |
| 96 gfx::Rect pixel_bitmap_rect = gfx::ToEnclosedRect(scaled_bitmap_rect); |
| 96 | 97 |
| 97 const int width = pixel_bitmap_rect.width(); | 98 const int width = pixel_bitmap_rect.width(); |
| 98 const int height = pixel_bitmap_rect.height(); | 99 const int height = pixel_bitmap_rect.height(); |
| 99 | 100 |
| 100 if (width <= 0 || width > kMaxVideoLayerSize || | 101 if (width <= 0 || width > kMaxVideoLayerSize || |
| 101 height <= 0 || height > kMaxVideoLayerSize) | 102 height <= 0 || height > kMaxVideoLayerSize) |
| 102 return; | 103 return; |
| 103 | 104 |
| 104 TransportDIB* dib = process->GetTransportDIB(bitmap); | 105 TransportDIB* dib = process->GetTransportDIB(bitmap); |
| 105 if (!dib) | 106 if (!dib) |
| 106 return; | 107 return; |
| 107 | 108 |
| 108 SkPaint copy_paint; | 109 SkPaint copy_paint; |
| 109 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 110 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 110 | 111 |
| 111 SkBitmap sk_bitmap; | 112 SkBitmap sk_bitmap; |
| 112 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 113 sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 113 sk_bitmap.setPixels(dib->memory()); | 114 sk_bitmap.setPixels(dib->memory()); |
| 114 for (size_t i = 0; i < copy_rects.size(); i++) { | 115 for (size_t i = 0; i < copy_rects.size(); i++) { |
| 115 const gfx::Rect pixel_copy_rect = | 116 gfx::RectF scaled_copy_rect = copy_rects[i]; |
| 116 gfx::ToEnclosingRect(copy_rects[i].Scale(scale_factor)); | 117 scaled_copy_rect.Scale(scale_factor); |
| 118 const gfx::Rect pixel_copy_rect = gfx::ToEnclosingRect(scaled_copy_rect); |
| 117 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); | 119 int x = pixel_copy_rect.x() - pixel_bitmap_rect.x(); |
| 118 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); | 120 int y = pixel_copy_rect.y() - pixel_bitmap_rect.y(); |
| 119 SkIRect srcrect = SkIRect::MakeXYWH(x, y, | 121 SkIRect srcrect = SkIRect::MakeXYWH(x, y, |
| 120 pixel_copy_rect.width(), | 122 pixel_copy_rect.width(), |
| 121 pixel_copy_rect.height()); | 123 pixel_copy_rect.height()); |
| 122 | 124 |
| 125 gfx::RectF scaled_copy_dst_rect = copy_rects[i]; |
| 126 scaled_copy_dst_rect.Scale(device_scale_factor_); |
| 123 const gfx::Rect pixel_copy_dst_rect = | 127 const gfx::Rect pixel_copy_dst_rect = |
| 124 gfx::ToEnclosingRect(copy_rects[i].Scale(device_scale_factor_)); | 128 gfx::ToEnclosingRect(scaled_copy_dst_rect); |
| 125 SkRect dstrect = SkRect::MakeXYWH( | 129 SkRect dstrect = SkRect::MakeXYWH( |
| 126 SkIntToScalar(pixel_copy_dst_rect.x()), | 130 SkIntToScalar(pixel_copy_dst_rect.x()), |
| 127 SkIntToScalar(pixel_copy_dst_rect.y()), | 131 SkIntToScalar(pixel_copy_dst_rect.y()), |
| 128 SkIntToScalar(pixel_copy_dst_rect.width()), | 132 SkIntToScalar(pixel_copy_dst_rect.width()), |
| 129 SkIntToScalar(pixel_copy_dst_rect.height())); | 133 SkIntToScalar(pixel_copy_dst_rect.height())); |
| 130 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); | 134 canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, ©_paint); |
| 131 } | 135 } |
| 132 } | 136 } |
| 133 | 137 |
| 134 void BackingStoreAura::ScrollBackingStore(int dx, int dy, | 138 void BackingStoreAura::ScrollBackingStore(int dx, int dy, |
| 135 const gfx::Rect& clip_rect, | 139 const gfx::Rect& clip_rect, |
| 136 const gfx::Size& view_size) { | 140 const gfx::Size& view_size) { |
| 137 gfx::Rect pixel_rect = | 141 gfx::RectF scaled_clip_rect = clip_rect; |
| 138 gfx::ToEnclosingRect(clip_rect.Scale(device_scale_factor_)); | 142 scaled_clip_rect.Scale(device_scale_factor_); |
| 143 gfx::Rect pixel_rect = gfx::ToEnclosingRect(scaled_clip_rect); |
| 139 int pixel_dx = dx * device_scale_factor_; | 144 int pixel_dx = dx * device_scale_factor_; |
| 140 int pixel_dy = dy * device_scale_factor_; | 145 int pixel_dy = dy * device_scale_factor_; |
| 141 | 146 |
| 142 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); | 147 int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_dx); |
| 143 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); | 148 int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_dy); |
| 144 int w = pixel_rect.width() + abs(pixel_dx); | 149 int w = pixel_rect.width() + abs(pixel_dx); |
| 145 int h = pixel_rect.height() + abs(pixel_dy); | 150 int h = pixel_rect.height() + abs(pixel_dy); |
| 146 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); | 151 SkIRect rect = SkIRect::MakeXYWH(x, y, w, h); |
| 147 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); | 152 bitmap_.scrollRect(&rect, pixel_dx, pixel_dy); |
| 148 } | 153 } |
| 149 | 154 |
| 150 bool BackingStoreAura::CopyFromBackingStore(const gfx::Rect& rect, | 155 bool BackingStoreAura::CopyFromBackingStore(const gfx::Rect& rect, |
| 151 skia::PlatformBitmap* output) { | 156 skia::PlatformBitmap* output) { |
| 152 const int width = | 157 const int width = |
| 153 std::min(size().width(), rect.width()) * device_scale_factor_; | 158 std::min(size().width(), rect.width()) * device_scale_factor_; |
| 154 const int height = | 159 const int height = |
| 155 std::min(size().height(), rect.height()) * device_scale_factor_; | 160 std::min(size().height(), rect.height()) * device_scale_factor_; |
| 156 if (!output->Allocate(width, height, true)) | 161 if (!output->Allocate(width, height, true)) |
| 157 return false; | 162 return false; |
| 158 | 163 |
| 159 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 164 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
| 160 SkBitmap b; | 165 SkBitmap b; |
| 161 if (!canvas_->readPixels(skrect, &b)) | 166 if (!canvas_->readPixels(skrect, &b)) |
| 162 return false; | 167 return false; |
| 163 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y()); | 168 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y()); |
| 164 return true; | 169 return true; |
| 165 } | 170 } |
| 166 | 171 |
| 167 } // namespace content | 172 } // namespace content |
| OLD | NEW |