| 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 | 15 |
| 16 namespace content { |
| 17 |
| 16 // Assume that somewhere along the line, someone will do width * height * 4 | 18 // Assume that somewhere along the line, someone will do width * height * 4 |
| 17 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = | 19 // with signed numbers. If the maximum value is 2**31, then 2**31 / 4 = |
| 18 // 2**29 and floor(sqrt(2**29)) = 23170. | 20 // 2**29 and floor(sqrt(2**29)) = 23170. |
| 19 | 21 |
| 20 // Max height and width for layers | 22 // Max height and width for layers |
| 21 static const int kMaxVideoLayerSize = 23170; | 23 static const int kMaxVideoLayerSize = 23170; |
| 22 | 24 |
| 23 BackingStoreAura::BackingStoreAura(content::RenderWidgetHost* widget, | 25 BackingStoreAura::BackingStoreAura(RenderWidgetHost* widget, |
| 24 const gfx::Size& size) | 26 const gfx::Size& size) |
| 25 : BackingStore(widget, size), | 27 : BackingStore(widget, size), |
| 26 device_scale_factor_(content::GetDIPScaleFactor(widget->GetView())) { | 28 device_scale_factor_(GetDIPScaleFactor(widget->GetView())) { |
| 27 gfx::Size pixel_size = size.Scale(device_scale_factor_); | 29 gfx::Size pixel_size = size.Scale(device_scale_factor_); |
| 28 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 30 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, |
| 29 pixel_size.width(), pixel_size.height()); | 31 pixel_size.width(), pixel_size.height()); |
| 30 bitmap_.allocPixels(); | 32 bitmap_.allocPixels(); |
| 31 canvas_.reset(new SkCanvas(bitmap_)); | 33 canvas_.reset(new SkCanvas(bitmap_)); |
| 32 } | 34 } |
| 33 | 35 |
| 34 BackingStoreAura::~BackingStoreAura() { | 36 BackingStoreAura::~BackingStoreAura() { |
| 35 } | 37 } |
| 36 | 38 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 67 bitmap_ = new_bitmap; | 69 bitmap_ = new_bitmap; |
| 68 } | 70 } |
| 69 | 71 |
| 70 size_t BackingStoreAura::MemorySize() { | 72 size_t BackingStoreAura::MemorySize() { |
| 71 // NOTE: The computation may be different when the canvas is a subrectangle of | 73 // NOTE: The computation may be different when the canvas is a subrectangle of |
| 72 // a larger bitmap. | 74 // a larger bitmap. |
| 73 return size().Scale(device_scale_factor_).GetArea() * 4; | 75 return size().Scale(device_scale_factor_).GetArea() * 4; |
| 74 } | 76 } |
| 75 | 77 |
| 76 void BackingStoreAura::PaintToBackingStore( | 78 void BackingStoreAura::PaintToBackingStore( |
| 77 content::RenderProcessHost* process, | 79 RenderProcessHost* process, |
| 78 TransportDIB::Id bitmap, | 80 TransportDIB::Id bitmap, |
| 79 const gfx::Rect& bitmap_rect, | 81 const gfx::Rect& bitmap_rect, |
| 80 const std::vector<gfx::Rect>& copy_rects, | 82 const std::vector<gfx::Rect>& copy_rects, |
| 81 float scale_factor, | 83 float scale_factor, |
| 82 const base::Closure& completion_callback, | 84 const base::Closure& completion_callback, |
| 83 bool* scheduled_completion_callback) { | 85 bool* scheduled_completion_callback) { |
| 84 *scheduled_completion_callback = false; | 86 *scheduled_completion_callback = false; |
| 85 if (bitmap_rect.IsEmpty()) | 87 if (bitmap_rect.IsEmpty()) |
| 86 return; | 88 return; |
| 87 | 89 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return false; | 150 return false; |
| 149 | 151 |
| 150 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); | 152 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); |
| 151 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); | 153 SkIRect skrect = SkIRect::MakeXYWH(rect.x(), rect.y(), width, height); |
| 152 SkBitmap b; | 154 SkBitmap b; |
| 153 if (!canvas_->readPixels(skrect, &b)) | 155 if (!canvas_->readPixels(skrect, &b)) |
| 154 return false; | 156 return false; |
| 155 output->writePixels(b, rect.x(), rect.y()); | 157 output->writePixels(b, rect.x(), rect.y()); |
| 156 return true; | 158 return true; |
| 157 } | 159 } |
| 160 |
| 161 } // namespace content |
| OLD | NEW |