| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/backing_store_mac.h" | 7 #include "content/browser/renderer_host/backing_store_mac.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 13 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 14 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
| 15 #include "skia/ext/platform_canvas.h" | 15 #include "skia/ext/platform_canvas.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" | 19 #include "ui/gfx/scoped_cg_context_save_gstate_mac.h" |
| 20 #include "ui/surface/transport_dib.h" | 20 #include "ui/surface/transport_dib.h" |
| 21 | 21 |
| 22 namespace content { |
| 23 |
| 22 // Mac Backing Stores: | 24 // Mac Backing Stores: |
| 23 // | 25 // |
| 24 // Since backing stores are only ever written to or drawn into windows, we keep | 26 // Since backing stores are only ever written to or drawn into windows, we keep |
| 25 // our backing store in a CGLayer that can get cached in GPU memory. This | 27 // our backing store in a CGLayer that can get cached in GPU memory. This |
| 26 // allows acclerated drawing into the layer and lets scrolling and such happen | 28 // allows acclerated drawing into the layer and lets scrolling and such happen |
| 27 // all or mostly on the GPU, which is good for performance. | 29 // all or mostly on the GPU, which is good for performance. |
| 28 | 30 |
| 29 BackingStoreMac::BackingStoreMac(content::RenderWidgetHost* widget, | 31 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, |
| 30 const gfx::Size& size, | 32 const gfx::Size& size, |
| 31 float device_scale_factor) | 33 float device_scale_factor) |
| 32 : BackingStore(widget, size), device_scale_factor_(device_scale_factor) { | 34 : BackingStore(widget, size), device_scale_factor_(device_scale_factor) { |
| 33 cg_layer_.reset(CreateCGLayer()); | 35 cg_layer_.reset(CreateCGLayer()); |
| 34 if (!cg_layer_) { | 36 if (!cg_layer_) { |
| 35 // The view isn't in a window yet. Use a CGBitmapContext for now. | 37 // The view isn't in a window yet. Use a CGBitmapContext for now. |
| 36 cg_bitmap_.reset(CreateCGBitmapContext()); | 38 cg_bitmap_.reset(CreateCGBitmapContext()); |
| 37 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); | 39 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); |
| 38 } | 40 } |
| 39 } | 41 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 cg_bitmap_.reset(CreateCGBitmapContext()); | 63 cg_bitmap_.reset(CreateCGBitmapContext()); |
| 62 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); | 64 CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); |
| 63 } | 65 } |
| 64 } | 66 } |
| 65 | 67 |
| 66 size_t BackingStoreMac::MemorySize() { | 68 size_t BackingStoreMac::MemorySize() { |
| 67 return size().Scale(device_scale_factor_).GetArea() * 4; | 69 return size().Scale(device_scale_factor_).GetArea() * 4; |
| 68 } | 70 } |
| 69 | 71 |
| 70 void BackingStoreMac::PaintToBackingStore( | 72 void BackingStoreMac::PaintToBackingStore( |
| 71 content::RenderProcessHost* process, | 73 RenderProcessHost* process, |
| 72 TransportDIB::Id bitmap, | 74 TransportDIB::Id bitmap, |
| 73 const gfx::Rect& bitmap_rect, | 75 const gfx::Rect& bitmap_rect, |
| 74 const std::vector<gfx::Rect>& copy_rects, | 76 const std::vector<gfx::Rect>& copy_rects, |
| 75 float scale_factor, | 77 float scale_factor, |
| 76 const base::Closure& completion_callback, | 78 const base::Closure& completion_callback, |
| 77 bool* scheduled_completion_callback) { | 79 bool* scheduled_completion_callback) { |
| 78 *scheduled_completion_callback = false; | 80 *scheduled_completion_callback = false; |
| 79 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); | 81 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); |
| 80 | 82 |
| 81 TransportDIB* dib = process->GetTransportDIB(bitmap); | 83 TransportDIB* dib = process->GetTransportDIB(bitmap); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 pixel_size.width(), | 278 pixel_size.width(), |
| 277 pixel_size.height(), | 279 pixel_size.height(), |
| 278 8, pixel_size.width() * 4, | 280 8, pixel_size.width() * 4, |
| 279 base::mac::GetSystemColorSpace(), | 281 base::mac::GetSystemColorSpace(), |
| 280 kCGImageAlphaPremultipliedFirst | | 282 kCGImageAlphaPremultipliedFirst | |
| 281 kCGBitmapByteOrder32Host); | 283 kCGBitmapByteOrder32Host); |
| 282 DCHECK(context); | 284 DCHECK(context); |
| 283 | 285 |
| 284 return context; | 286 return context; |
| 285 } | 287 } |
| 288 |
| 289 } // namespace content |
| OLD | NEW |