1 // Copyright 2014 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_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ 7 8 #include <vector> 9 10 #include "cc/output/software_frame_data.h" 11 #include "skia/ext/platform_canvas.h" 12 #include "ui/compositor/compositor.h" 13 #include "ui/events/latency_info.h" 14 #include "ui/gfx/geometry/size.h" 15 16 namespace content { 17 18 class BrowserCompositorViewMacInternal; 19 20 // The interface through which BrowserCompositorViewMac calls back into 21 // RenderWidgetHostViewMac (or any other structure that wishes to draw a 22 // NSView backed by a ui::Compositor). 23 class BrowserCompositorViewMacClient { 24 public: 25 // Drawing is usually throttled by the rate at which CoreAnimation draws 26 // frames to the screen. This can be used to disable throttling. 27 virtual bool BrowserCompositorViewShouldAckImmediately() const = 0; 28 29 // Called when a frame is drawn, and used to pass latency info back to the 30 // renderer (if any). 31 virtual void BrowserCompositorViewFrameSwapped( 32 const std::vector<ui::LatencyInfo>& latency_info) = 0; 33 34 // Used to install the ui::Compositor-backed NSView as a child of its parent 35 // view. 36 virtual NSView* BrowserCompositorSuperview() = 0; 37 38 // Used to install the root ui::Layer into the ui::Compositor. 39 virtual ui::Layer* BrowserCompositorRootLayer() = 0; 40 }; 41 42 // The class to hold a ui::Compositor-backed NSView. Because a ui::Compositor 43 // is expensive in terms of resources and re-allocating a ui::Compositor is 44 // expensive in terms of work, this class is largely used to manage recycled 45 // instances of BrowserCompositorViewCocoa, which actually is a NSView and 46 // has a ui::Compositor instance. 47 class BrowserCompositorViewMac { 48 public: 49 // This will install the NSView which is drawn by the ui::Compositor into 50 // the NSView provided by the client. 51 explicit BrowserCompositorViewMac(BrowserCompositorViewMacClient* client); 52 ~BrowserCompositorViewMac(); 53 54 // The ui::Compositor being used to render the NSView. 55 ui::Compositor* GetCompositor() const; 56 57 // The client (used by the BrowserCompositorViewCocoa to access the client). 58 BrowserCompositorViewMacClient* GetClient() const { return client_; } 59 60 // Return true if the last frame swapped has a size in DIP of |dip_size|. 61 bool HasFrameOfSize(const gfx::Size& dip_size) const; 62 63 // Mark a bracket in which new frames are pumped in a restricted nested run 64 // loop because the the target window is resizing or because the view is being 65 // shown after previously being hidden. 66 void BeginPumpingFrames(); 67 void EndPumpingFrames(); 68 69 static void GotAcceleratedFrame( 70 gfx::AcceleratedWidget widget, 71 uint64 surface_handle, int surface_id, 72 const std::vector<ui::LatencyInfo>& latency_info, 73 gfx::Size pixel_size, float scale_factor, 74 int gpu_host_id, int gpu_route_id); 75 76 static void GotSoftwareFrame( 77 gfx::AcceleratedWidget widget, 78 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas); 79 80 private: 81 BrowserCompositorViewMacClient* client_; 82 scoped_ptr<BrowserCompositorViewMacInternal> internal_view_; 83 }; 84 85 // A class to keep around whenever a BrowserCompositorViewMac may be created. 86 // While at least one instance of this class exists, a spare 87 // BrowserCompositorViewCocoa will be kept around to be recycled so that the 88 // next BrowserCompositorViewMac to be created will be be created quickly. 89 class BrowserCompositorViewPlaceholderMac { 90 public: 91 BrowserCompositorViewPlaceholderMac(); 92 ~BrowserCompositorViewPlaceholderMac(); 93 }; 94 95 } // namespace content 96 97 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ 98