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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MAC_H_
8 #include "base/basictypes.h"
9 #include "base/mac/scoped_cftyperef.h"
10 #include "content/browser/renderer_host/backing_store.h"
14 class BackingStoreMac
: public BackingStore
{
16 // |size| is in view units, |device_scale_factor| is the backingScaleFactor.
17 // The pixel size of the backing store is size.Scale(device_scale_factor).
18 BackingStoreMac(RenderWidgetHost
* widget
,
19 const gfx::Size
& size
,
20 float device_scale_factor
);
21 virtual ~BackingStoreMac();
23 // A CGLayer that stores the contents of the backing store, cached in GPU
24 // memory if possible.
25 CGLayerRef
cg_layer() { return cg_layer_
; }
27 // A CGBitmapContext that stores the contents of the backing store if the
28 // corresponding Cocoa view has not been inserted into an NSWindow yet.
29 CGContextRef
cg_bitmap() { return cg_bitmap_
; }
31 // Called when the view's backing scale factor changes.
32 void ScaleFactorChanged(float device_scale_factor
);
34 // BackingStore implementation.
35 virtual size_t MemorySize() OVERRIDE
;
36 virtual void PaintToBackingStore(
37 RenderProcessHost
* process
,
38 TransportDIB::Id bitmap
,
39 const gfx::Rect
& bitmap_rect
,
40 const std::vector
<gfx::Rect
>& copy_rects
,
42 const base::Closure
& completion_callback
,
43 bool* scheduled_completion_callback
) OVERRIDE
;
44 virtual bool CopyFromBackingStore(const gfx::Rect
& rect
,
45 skia::PlatformBitmap
* output
) OVERRIDE
;
46 virtual void ScrollBackingStore(const gfx::Vector2d
& delta
,
47 const gfx::Rect
& clip_rect
,
48 const gfx::Size
& view_size
) OVERRIDE
;
50 void CopyFromBackingStoreToCGContext(const CGRect
& dest_rect
,
51 CGContextRef context
);
54 // Creates a CGLayer associated with its owner view's window's graphics
55 // context, sized properly for the backing store. Returns NULL if the owner
56 // is not in a window with a CGContext. cg_layer_ is assigned this method's
58 CGLayerRef
CreateCGLayer();
60 // Creates a CGBitmapContext sized properly for the backing store. The
61 // owner view need not be in a window. cg_bitmap_ is assigned this method's
63 CGContextRef
CreateCGBitmapContext();
65 base::ScopedCFTypeRef
<CGContextRef
> cg_bitmap_
;
66 base::ScopedCFTypeRef
<CGLayerRef
> cg_layer_
;
68 // Number of physical pixels per view unit. This is 1 or 2 in practice.
69 float device_scale_factor_
;
71 DISALLOW_COPY_AND_ASSIGN(BackingStoreMac
);
74 } // namespace content
76 #endif // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MAC_H_