OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
13 #include "content/browser/renderer_host/render_widget_host.h" | 13 #include "content/browser/renderer_host/render_widget_host.h" |
14 #include "content/browser/renderer_host/render_widget_host_view.h" | 14 #include "content/browser/renderer_host/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/surface/transport_dib.h" | 19 #include "ui/gfx/surface/transport_dib.h" |
20 | 20 |
21 // Mac Backing Stores: | 21 // Mac Backing Stores: |
22 // | 22 // |
23 // Since backing stores are only ever written to or drawn into windows, we keep | 23 // Since backing stores are only ever written to or drawn into windows, we keep |
24 // our backing store in a CGLayer that can get cached in GPU memory. This | 24 // our backing store in a CGLayer that can get cached in GPU memory. This |
25 // allows acclerated drawing into the layer and lets scrolling and such happen | 25 // allows acclerated drawing into the layer and lets scrolling and such happen |
26 // all or mostly on the GPU, which is good for performance. | 26 // all or mostly on the GPU, which is good for performance. |
27 | 27 |
28 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, | 28 BackingStoreMac::BackingStoreMac(RenderWidgetHost* widget, |
29 const gfx::Size& size) | 29 const gfx::Size& size) |
30 : BackingStore(widget, size) { | 30 : BackingStore(widget, size) { |
31 cg_layer_.reset(CreateCGLayer()); | 31 cg_layer_.reset(CreateCGLayer()); |
32 if (!cg_layer_) { | 32 if (!cg_layer_) { |
33 // The view isn't in a window yet. Use a CGBitmapContext for now. | 33 // The view isn't in a window yet. Use a CGBitmapContext for now. |
34 cg_bitmap_.reset(CreateCGBitmapContext()); | 34 cg_bitmap_.reset(CreateCGBitmapContext()); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 BackingStoreMac::~BackingStoreMac() { | 38 BackingStoreMac::~BackingStoreMac() { |
39 } | 39 } |
40 | 40 |
41 void BackingStoreMac::PaintToBackingStore( | 41 void BackingStoreMac::PaintToBackingStore( |
42 RenderProcessHost* process, | 42 content::RenderProcessHost* process, |
43 TransportDIB::Id bitmap, | 43 TransportDIB::Id bitmap, |
44 const gfx::Rect& bitmap_rect, | 44 const gfx::Rect& bitmap_rect, |
45 const std::vector<gfx::Rect>& copy_rects, | 45 const std::vector<gfx::Rect>& copy_rects, |
46 const base::Closure& completion_callback, | 46 const base::Closure& completion_callback, |
47 bool* scheduled_completion_callback) { | 47 bool* scheduled_completion_callback) { |
48 *scheduled_completion_callback = false; | 48 *scheduled_completion_callback = false; |
49 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); | 49 DCHECK_NE(static_cast<bool>(cg_layer()), static_cast<bool>(cg_bitmap())); |
50 | 50 |
51 TransportDIB* dib = process->GetTransportDIB(bitmap); | 51 TransportDIB* dib = process->GetTransportDIB(bitmap); |
52 if (!dib) | 52 if (!dib) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 CGContextRef context = CGBitmapContextCreate(NULL, | 223 CGContextRef context = CGBitmapContextCreate(NULL, |
224 size().width(), size().height(), | 224 size().width(), size().height(), |
225 8, size().width() * 4, | 225 8, size().width() * 4, |
226 base::mac::GetSystemColorSpace(), | 226 base::mac::GetSystemColorSpace(), |
227 kCGImageAlphaPremultipliedFirst | | 227 kCGImageAlphaPremultipliedFirst | |
228 kCGBitmapByteOrder32Host); | 228 kCGBitmapByteOrder32Host); |
229 DCHECK(context); | 229 DCHECK(context); |
230 | 230 |
231 return context; | 231 return context; |
232 } | 232 } |
OLD | NEW |