| 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 11 matching lines...) Expand all Loading... |
| 22 // 2**29 and floor(sqrt(2**29)) = 23170. | 22 // 2**29 and floor(sqrt(2**29)) = 23170. |
| 23 | 23 |
| 24 // Max height and width for layers | 24 // Max height and width for layers |
| 25 static const int kMaxVideoLayerSize = 23170; | 25 static const int kMaxVideoLayerSize = 23170; |
| 26 | 26 |
| 27 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget, | 27 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget, |
| 28 const gfx::Size& size) | 28 const gfx::Size& size) |
| 29 : BackingStore(widget, size) { | 29 : BackingStore(widget, size) { |
| 30 device_scale_factor_ = | 30 device_scale_factor_ = |
| 31 ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView())); | 31 ui::GetScaleFactorScale(GetScaleFactorForView(widget->GetView())); |
| 32 gfx::Size pixel_size = gfx::ToFlooredSize(size.Scale(device_scale_factor_)); | 32 gfx::Size pixel_size = gfx::ToFlooredSize( |
| 33 gfx::ScaleSize(size, device_scale_factor_)); |
| 33 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 34 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, |
| 34 pixel_size.width(), pixel_size.height()); | 35 pixel_size.width(), pixel_size.height()); |
| 35 bitmap_.allocPixels(); | 36 bitmap_.allocPixels(); |
| 36 canvas_.reset(new SkCanvas(bitmap_)); | 37 canvas_.reset(new SkCanvas(bitmap_)); |
| 37 } | 38 } |
| 38 | 39 |
| 39 BackingStoreAura::~BackingStoreAura() { | 40 BackingStoreAura::~BackingStoreAura() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 void BackingStoreAura::SkiaShowRect(const gfx::Point& point, | 43 void BackingStoreAura::SkiaShowRect(const gfx::Point& point, |
| 43 gfx::Canvas* canvas) { | 44 gfx::Canvas* canvas) { |
| 44 gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_, | 45 gfx::ImageSkia image = gfx::ImageSkia(gfx::ImageSkiaRep(bitmap_, |
| 45 ui::GetScaleFactorFromScale(device_scale_factor_))); | 46 ui::GetScaleFactorFromScale(device_scale_factor_))); |
| 46 canvas->DrawImageInt(image, point.x(), point.y()); | 47 canvas->DrawImageInt(image, point.x(), point.y()); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void BackingStoreAura::ScaleFactorChanged(float device_scale_factor) { | 50 void BackingStoreAura::ScaleFactorChanged(float device_scale_factor) { |
| 50 if (device_scale_factor == device_scale_factor_) | 51 if (device_scale_factor == device_scale_factor_) |
| 51 return; | 52 return; |
| 52 | 53 |
| 53 gfx::Size old_pixel_size = gfx::ToFlooredSize( | 54 gfx::Size old_pixel_size = gfx::ToFlooredSize( |
| 54 size().Scale(device_scale_factor_)); | 55 gfx::ScaleSize(size(), device_scale_factor_)); |
| 55 device_scale_factor_ = device_scale_factor; | 56 device_scale_factor_ = device_scale_factor; |
| 56 | 57 |
| 57 gfx::Size pixel_size = gfx::ToFlooredSize(size().Scale(device_scale_factor_)); | 58 gfx::Size pixel_size = gfx::ToFlooredSize( |
| 59 gfx::ScaleSize(size(), device_scale_factor_)); |
| 58 SkBitmap new_bitmap; | 60 SkBitmap new_bitmap; |
| 59 new_bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 61 new_bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 60 pixel_size.width(), pixel_size.height()); | 62 pixel_size.width(), pixel_size.height()); |
| 61 new_bitmap.allocPixels(); | 63 new_bitmap.allocPixels(); |
| 62 scoped_ptr<SkCanvas> new_canvas(new SkCanvas(new_bitmap)); | 64 scoped_ptr<SkCanvas> new_canvas(new SkCanvas(new_bitmap)); |
| 63 | 65 |
| 64 // Copy old contents; a low-res flash is better than a black flash. | 66 // Copy old contents; a low-res flash is better than a black flash. |
| 65 SkPaint copy_paint; | 67 SkPaint copy_paint; |
| 66 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 68 copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 67 SkIRect src_rect = SkIRect::MakeWH(old_pixel_size.width(), | 69 SkIRect src_rect = SkIRect::MakeWH(old_pixel_size.width(), |
| 68 old_pixel_size.height()); | 70 old_pixel_size.height()); |
| 69 SkRect dst_rect = SkRect::MakeWH(pixel_size.width(), pixel_size.height()); | 71 SkRect dst_rect = SkRect::MakeWH(pixel_size.width(), pixel_size.height()); |
| 70 new_canvas.get()->drawBitmapRect(bitmap_, &src_rect, dst_rect, ©_paint); | 72 new_canvas.get()->drawBitmapRect(bitmap_, &src_rect, dst_rect, ©_paint); |
| 71 | 73 |
| 72 canvas_.swap(new_canvas); | 74 canvas_.swap(new_canvas); |
| 73 bitmap_ = new_bitmap; | 75 bitmap_ = new_bitmap; |
| 74 } | 76 } |
| 75 | 77 |
| 76 size_t BackingStoreAura::MemorySize() { | 78 size_t BackingStoreAura::MemorySize() { |
| 77 // NOTE: The computation may be different when the canvas is a subrectangle of | 79 // NOTE: The computation may be different when the canvas is a subrectangle of |
| 78 // a larger bitmap. | 80 // a larger bitmap. |
| 79 return gfx::ToFlooredSize(size().Scale(device_scale_factor_)).GetArea() * 4; | 81 return gfx::ToFlooredSize( |
| 82 gfx::ScaleSize(size(), device_scale_factor_)).GetArea() * 4; |
| 80 } | 83 } |
| 81 | 84 |
| 82 void BackingStoreAura::PaintToBackingStore( | 85 void BackingStoreAura::PaintToBackingStore( |
| 83 RenderProcessHost* process, | 86 RenderProcessHost* process, |
| 84 TransportDIB::Id bitmap, | 87 TransportDIB::Id bitmap, |
| 85 const gfx::Rect& bitmap_rect, | 88 const gfx::Rect& bitmap_rect, |
| 86 const std::vector<gfx::Rect>& copy_rects, | 89 const std::vector<gfx::Rect>& copy_rects, |
| 87 float scale_factor, | 90 float scale_factor, |
| 88 const base::Closure& completion_callback, | 91 const base::Closure& completion_callback, |
| 89 bool* scheduled_completion_callback) { | 92 bool* scheduled_completion_callback) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 161 |
| 159 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 162 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
| 160 SkBitmap b; | 163 SkBitmap b; |
| 161 if (!canvas_->readPixels(skrect, &b)) | 164 if (!canvas_->readPixels(skrect, &b)) |
| 162 return false; | 165 return false; |
| 163 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y()); | 166 SkCanvas(output->GetBitmap()).writePixels(b, rect.x(), rect.y()); |
| 164 return true; | 167 return true; |
| 165 } | 168 } |
| 166 | 169 |
| 167 } // namespace content | 170 } // namespace content |
| OLD | NEW |