Home | History | Annotate | Download | only in renderer_host
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_RENDERER_HOST_ACCELERATED_PLUGIN_VIEW_MAC_H
      6 #define CHROME_BROWSER_RENDERER_HOST_ACCELERATED_PLUGIN_VIEW_MAC_H
      7 
      8 #import <Cocoa/Cocoa.h>
      9 #include <QuartzCore/QuartzCore.h>
     10 
     11 #include "base/memory/scoped_nsobject.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 
     14 class RenderWidgetHostViewMac;
     15 
     16 // Informal protocol implemented by windows that need to be informed explicitly
     17 // about underlay surfaces.
     18 @interface NSObject (UnderlayableSurface)
     19 - (void)underlaySurfaceAdded;
     20 - (void)underlaySurfaceRemoved;
     21 @end
     22 
     23 // This subclass of NSView hosts the output of accelerated plugins on
     24 // the page.
     25 
     26 // This class takes a couple of locks, some indirectly. The lock hiearchy is:
     27 // 1. The DisplayLink lock, implicit to the display link owned by this view.
     28 //    It is taken by the framework before |DrawOneAcceleratedPluginCallback()|
     29 //    is called, and during CVDisplayLink* function calls.
     30 // 2. The CGL lock, taken explicitly.
     31 // 3. The AcceleratedSurfaceContainerManagerMac's lock, which it takes when any
     32 //    of its methods are called.
     33 //
     34 // No code should ever try to acquire a lock further up in the hierarchy if it
     35 // already owns a lower lock. For example, while the CGL lock is taken, no
     36 // CVDisplayLink* functions must be called.
     37 @interface AcceleratedPluginView : NSView {
     38   scoped_nsobject<NSOpenGLPixelFormat> glPixelFormat_;
     39   CGLPixelFormatObj cglPixelFormat_;  // weak, backed by |glPixelFormat_|.
     40   scoped_nsobject<NSOpenGLContext> glContext_;
     41   CGLContextObj cglContext_;  // weak, backed by |glContext_|.
     42 
     43   CVDisplayLinkRef displayLink_;  // Owned by us.
     44 
     45   RenderWidgetHostViewMac* renderWidgetHostView_;  // weak
     46   gfx::PluginWindowHandle pluginHandle_;  // weak
     47 
     48   // The number of swap buffers calls that have been requested by the
     49   // GPU process, or a monotonically increasing number of calls to
     50   // updateSwapBuffersCount:fromRenderer:routeId: if the update came
     51   // from an accelerated plugin.
     52   uint64 swapBuffersCount_;
     53   // The number of swap buffers calls that have been processed by the
     54   // display link thread. This is only used with the GPU process
     55   // update path.
     56   volatile uint64 acknowledgedSwapBuffersCount_;
     57 
     58   // Auxiliary information needed to formulate an acknowledgment to
     59   // the GPU process. These are constant after the first message.
     60   // These are all zero for updates coming from a plugin process.
     61   volatile int rendererId_;
     62   volatile int32 routeId_;
     63   volatile int gpuHostId_;
     64 
     65   // Cocoa methods can only be called on the main thread, so have a copy of the
     66   // view's size, since it's required on the displaylink thread.
     67   NSSize cachedSize_;
     68 
     69   // Rects that should show web content rather than plugin content.
     70   scoped_nsobject<NSArray> cutoutRects_;
     71 
     72   // -globalFrameDidChange: can be called recursively, this counts how often it
     73   // holds the CGL lock.
     74   int globalFrameDidChangeCGLLockCount_;
     75 }
     76 
     77 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r
     78                          pluginHandle:(gfx::PluginWindowHandle)pluginHandle;
     79 - (void)drawView;
     80 
     81 // Sets the list of rectangles that should show the web page, rather than the
     82 // accelerated plugin. This is used to simulate the iframe-based trick that web
     83 // pages have long used to show web content above windowed plugins on Windows
     84 // and Linux.
     85 - (void)setCutoutRects:(NSArray*)cutout_rects;
     86 
     87 // Updates the number of swap buffers calls that have been requested.
     88 // This is currently called with non-zero values only in response to
     89 // updates from the GPU process. For accelerated plugins, all zeros
     90 // are passed, and the view takes this as a hint that no flow control
     91 // or acknowledgment of the swap buffers are desired.
     92 - (void)updateSwapBuffersCount:(uint64)count
     93                   fromRenderer:(int)rendererId
     94                        routeId:(int32)routeId
     95                      gpuHostId:(int)gpuHostId;
     96 
     97 // NSViews autorelease subviews when they die. The RWHVMac gets destroyed when
     98 // RHWVCocoa gets dealloc'd, which means the AcceleratedPluginView child views
     99 // can be around a little longer than the RWHVMac. This is called when the
    100 // RWHVMac is about to be deleted (but it's still valid while this method runs).
    101 - (void)onRenderWidgetHostViewGone;
    102 
    103 // This _must_ be atomic, since it's accessed from several threads.
    104 @property NSSize cachedSize;
    105 @end
    106 
    107 #endif  // CHROME_BROWSER_RENDERER_HOST_ACCELERATED_PLUGIN_VIEW_MAC_H
    108