| OLD | NEW |
| (Empty) | |
| 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_ACCELERATED_COMPOSITING_VIEW_MAC_H |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H |
| 7 |
| 8 #import <Cocoa/Cocoa.h> |
| 9 #include <QuartzCore/QuartzCore.h> |
| 10 |
| 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/memory/scoped_nsobject.h" |
| 13 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/gfx/size.h" |
| 15 |
| 16 class IOSurfaceSupport; |
| 17 |
| 18 // This class manages an OpenGL context and IOSurface for the accelerated |
| 19 // compositing code path. The GL context is attached to |
| 20 // RenderWidgetHostViewCocoa for blitting the IOSurface. |
| 21 class CompositingIOSurfaceMac { |
| 22 public: |
| 23 // Returns NULL if IOSurface support is missing or GL APIs fail. |
| 24 static CompositingIOSurfaceMac* Create(); |
| 25 ~CompositingIOSurfaceMac(); |
| 26 |
| 27 // Set IOSurface that will be drawn on the next NSView drawRect. |
| 28 void SetIOSurface(uint64 io_surface_handle); |
| 29 |
| 30 // Blit the IOSurface at the upper-left corner of the |view|. If |view| window |
| 31 // size is larger than the IOSurface, the remaining left and bottom edges will |
| 32 // be white. |
| 33 void DrawIOSurface(NSView* view); |
| 34 |
| 35 // Unref the IOSurface and delete the associated GL texture. If the GPU |
| 36 // process is no longer referencing it, this will delete the IOSurface. |
| 37 void UnrefIOSurface(); |
| 38 |
| 39 // Call when globalFrameDidChange is received on the NSView. |
| 40 void GlobalFrameDidChange(); |
| 41 |
| 42 // Disassociate the GL context with the NSView and unref the IOSurface. Do |
| 43 // this to switch to software drawing mode. |
| 44 void ClearDrawable(); |
| 45 |
| 46 bool HasIOSurface() { return !!io_surface_.get(); } |
| 47 |
| 48 const gfx::Size& io_surface_size() const { return io_surface_size_; } |
| 49 |
| 50 private: |
| 51 // Vertex structure for use in glDraw calls. |
| 52 struct SurfaceVertex { |
| 53 SurfaceVertex() : x_(0.0f), y_(0.0f), tx_(0.0f), ty_(0.0f) { } |
| 54 // Currently the texture coords are always the same as vertex coords. |
| 55 void set(float x, float y, float tx, float ty) { |
| 56 x_ = x; |
| 57 y_ = y; |
| 58 tx_ = tx; |
| 59 ty_ = ty; |
| 60 } |
| 61 float x_; |
| 62 float y_; |
| 63 float tx_; |
| 64 float ty_; |
| 65 }; |
| 66 |
| 67 // Counter-clockwise verts starting from upper-left corner (0, 0). |
| 68 struct SurfaceQuad { |
| 69 void set_size(gfx::Size size) { |
| 70 // Texture coordinates are flipped vertically so they can be drawn on |
| 71 // a projection with a flipped y-axis (origin is top left). |
| 72 float w = static_cast<float>(size.width()); |
| 73 float h = static_cast<float>(size.height()); |
| 74 verts_[0].set(0.0f, 0.0f, 0.0f, h); |
| 75 verts_[1].set(0.0f, h, 0.0f, 0.0f); |
| 76 verts_[2].set(w, h, w, 0.0f); |
| 77 verts_[3].set(w, 0.0f, w, h); |
| 78 } |
| 79 SurfaceVertex verts_[4]; |
| 80 }; |
| 81 |
| 82 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support, |
| 83 NSOpenGLContext* glContext, |
| 84 CGLContextObj cglContext); |
| 85 |
| 86 // Returns true if IOSurface is ready to render. False otherwise. |
| 87 bool MapIOSurfaceToTexture(uint64 io_surface_handle); |
| 88 |
| 89 void UnrefIOSurfaceWithContextCurrent(); |
| 90 |
| 91 // Cached pointer to IOSurfaceSupport Singleton. |
| 92 IOSurfaceSupport* io_surface_support_; |
| 93 |
| 94 // GL context |
| 95 scoped_nsobject<NSOpenGLContext> glContext_; |
| 96 CGLContextObj cglContext_; // weak, backed by |glContext_|. |
| 97 |
| 98 // IOSurface data. |
| 99 uint64 io_surface_handle_; |
| 100 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; |
| 101 |
| 102 // The width and height of the io surface. |
| 103 gfx::Size io_surface_size_; |
| 104 |
| 105 // The "live" OpenGL texture referring to this IOSurfaceRef. Note |
| 106 // that per the CGLTexImageIOSurface2D API we do not need to |
| 107 // explicitly update this texture's contents once created. All we |
| 108 // need to do is ensure it is re-bound before attempting to draw |
| 109 // with it. |
| 110 GLuint texture_; |
| 111 |
| 112 SurfaceQuad quad_; |
| 113 }; |
| 114 |
| 115 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H |
| OLD | NEW |