Home | History | Annotate | Download | only in renderer_host
      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.
      4 
      5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MAC_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MAC_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/mac/scoped_cftyperef.h"
     10 #include "content/browser/renderer_host/backing_store.h"
     11 
     12 namespace content {
     13 
     14 class BackingStoreMac : public BackingStore {
     15  public:
     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();
     22 
     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_; }
     26 
     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_; }
     30 
     31   // Called when the view's backing scale factor changes.
     32   void ScaleFactorChanged(float device_scale_factor);
     33 
     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,
     41       float scale_factor,
     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;
     49 
     50   void CopyFromBackingStoreToCGContext(const CGRect& dest_rect,
     51                                        CGContextRef context);
     52 
     53  private:
     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
     57   // result.
     58   CGLayerRef CreateCGLayer();
     59 
     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
     62   // result.
     63   CGContextRef CreateCGBitmapContext();
     64 
     65   base::ScopedCFTypeRef<CGContextRef> cg_bitmap_;
     66   base::ScopedCFTypeRef<CGLayerRef> cg_layer_;
     67 
     68   // Number of physical pixels per view unit. This is 1 or 2 in practice.
     69   float device_scale_factor_;
     70 
     71   DISALLOW_COPY_AND_ASSIGN(BackingStoreMac);
     72 };
     73 
     74 }  // namespace content
     75 
     76 #endif  // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_MAC_H_
     77