Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_mac.h

Issue 9958100: Unobfuscate RWHVMac accelerated compositing code path by separating it from plugin code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 coordinates (0,0). If |window_size| is larger than
31 // the IOSurface, the remaining left and bottom edges will be white.
32 void DrawIOSurface(uint64 io_surface_handle, NSView* view);
Ken Russell (switch to Gerrit) 2012/04/04 17:27:17 I think this should be made private, so that the p
jbates 2012/04/04 19:21:50 Done. (Just removed since there's no use-case for
33 void DrawLastIOSurface(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,
Ken Russell (switch to Gerrit) 2012/04/04 17:27:17 Indentation is off.
jbates 2012/04/04 19:21:50 Done.
84 CGLContextObj cglContext);
85
86 // Returns true if IOSurface is ready to render. False otherwise.
87 bool MapIOSurfaceToTexture(uint64 io_surface_handle);
88
89 // Cached pointer to IOSurfaceSupport Singleton.
90 IOSurfaceSupport* io_surface_support_;
91
92 // GL context
93 scoped_nsobject<NSOpenGLContext> glContext_;
94 CGLContextObj cglContext_; // weak, backed by |glContext_|.
95
96 // IOSurface data.
97 uint64 io_surface_handle_;
98 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_;
99
100 // The width and height of the io surface.
101 gfx::Size io_surface_size_;
102
103 // The "live" OpenGL texture referring to this IOSurfaceRef. Note
104 // that per the CGLTexImageIOSurface2D API we do not need to
105 // explicitly update this texture's contents once created. All we
106 // need to do is ensure it is re-bound before attempting to draw
107 // with it.
108 GLuint texture_;
109
110 SurfaceQuad quad_;
111 };
112
113 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698