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

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

Issue 10835014: Support copying a partial rectangle region from the compositing surface on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 4 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
« no previous file with comments | « no previous file | content/browser/renderer_host/compositing_iosurface_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
6 #define CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 6 #define CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/scoped_nsobject.h" 12 #include "base/memory/scoped_nsobject.h"
13 #include "ui/gfx/native_widget_types.h" 13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/gfx/size.h" 14 #include "ui/gfx/size.h"
15 15
16 class IOSurfaceSupport; 16 class IOSurfaceSupport;
17 17
18 namespace gfx {
19 class Rect;
20 }
21
18 namespace content { 22 namespace content {
19 23
20 // This class manages an OpenGL context and IOSurface for the accelerated 24 // This class manages an OpenGL context and IOSurface for the accelerated
21 // compositing code path. The GL context is attached to 25 // compositing code path. The GL context is attached to
22 // RenderWidgetHostViewCocoa for blitting the IOSurface. 26 // RenderWidgetHostViewCocoa for blitting the IOSurface.
23 class CompositingIOSurfaceMac { 27 class CompositingIOSurfaceMac {
24 public: 28 public:
25 // Returns NULL if IOSurface support is missing or GL APIs fail. 29 // Returns NULL if IOSurface support is missing or GL APIs fail.
26 static CompositingIOSurfaceMac* Create(); 30 static CompositingIOSurfaceMac* Create();
27 ~CompositingIOSurfaceMac(); 31 ~CompositingIOSurfaceMac();
28 32
29 // Set IOSurface that will be drawn on the next NSView drawRect. 33 // Set IOSurface that will be drawn on the next NSView drawRect.
30 void SetIOSurface(uint64 io_surface_handle); 34 void SetIOSurface(uint64 io_surface_handle);
31 35
32 // Blit the IOSurface at the upper-left corner of the |view|. If |view| window 36 // Blit the IOSurface at the upper-left corner of the |view|. If |view| window
33 // size is larger than the IOSurface, the remaining right and bottom edges 37 // size is larger than the IOSurface, the remaining right and bottom edges
34 // will be white. |scaleFactor| is 1 in normal views, 2 in HiDPI views. 38 // will be white. |scaleFactor| is 1 in normal views, 2 in HiDPI views.
35 void DrawIOSurface(NSView* view, float scale_factor); 39 void DrawIOSurface(NSView* view, float scale_factor);
36 40
37 // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef 41 // Copy the data of the "live" OpenGL texture referring to this IOSurfaceRef
38 // into |out|. The image data is transformed so that it fits in |dst_size|. 42 // into |out|. The copied region is specified with |src_pixel_subrect| and
43 // the data is transformed so that it fits in |dst_pixel_size|.
44 // |src_pixel_subrect| and |dst_pixel_size| are not in DIP but in pixel.
39 // Caller must ensure that |out| is allocated with the size no less than 45 // Caller must ensure that |out| is allocated with the size no less than
40 // |4 * dst_size.width() * dst_size.height()| bytes. 46 // |4 * dst_pixel_size.width() * dst_pixel_size.height()| bytes.
41 bool CopyTo(const gfx::Size& dst_size, void* out); 47 bool CopyTo(const gfx::Rect& src_pixel_subrect,
48 const gfx::Size& dst_pixel_size,
49 void* out);
42 50
43 // Unref the IOSurface and delete the associated GL texture. If the GPU 51 // Unref the IOSurface and delete the associated GL texture. If the GPU
44 // process is no longer referencing it, this will delete the IOSurface. 52 // process is no longer referencing it, this will delete the IOSurface.
45 void UnrefIOSurface(); 53 void UnrefIOSurface();
46 54
47 // Call when globalFrameDidChange is received on the NSView. 55 // Call when globalFrameDidChange is received on the NSView.
48 void GlobalFrameDidChange(); 56 void GlobalFrameDidChange();
49 57
50 // Disassociate the GL context with the NSView and unref the IOSurface. Do 58 // Disassociate the GL context with the NSView and unref the IOSurface. Do
51 // this to switch to software drawing mode. 59 // this to switch to software drawing mode.
52 void ClearDrawable(); 60 void ClearDrawable();
53 61
54 bool HasIOSurface() { return !!io_surface_.get(); } 62 bool HasIOSurface() { return !!io_surface_.get(); }
55 63
56 const gfx::Size& pixel_io_surface_size() const { 64 const gfx::Size& pixel_io_surface_size() const {
57 return pixel_io_surface_size_; 65 return pixel_io_surface_size_;
58 } 66 }
59 // In cocoa view units / DIPs. 67 // In cocoa view units / DIPs.
60 const gfx::Size& io_surface_size() const { return io_surface_size_; } 68 const gfx::Size& io_surface_size() const { return io_surface_size_; }
61 69
62 bool is_vsync_disabled() const { return is_vsync_disabled_; } 70 bool is_vsync_disabled() const { return is_vsync_disabled_; }
63 71
64 private: 72 private:
65 // Vertex structure for use in glDraw calls. 73 // Vertex structure for use in glDraw calls.
66 struct SurfaceVertex { 74 struct SurfaceVertex {
67 SurfaceVertex() : x_(0.0f), y_(0.0f), tx_(0.0f), ty_(0.0f) { } 75 SurfaceVertex() : x_(0.0f), y_(0.0f), tx_(0.0f), ty_(0.0f) { }
68 // Currently the texture coords are always the same as vertex coords.
69 void set(float x, float y, float tx, float ty) { 76 void set(float x, float y, float tx, float ty) {
70 x_ = x; 77 x_ = x;
71 y_ = y; 78 y_ = y;
72 tx_ = tx; 79 tx_ = tx;
73 ty_ = ty; 80 ty_ = ty;
74 } 81 }
75 void set_position(float x, float y) { 82 void set_position(float x, float y) {
76 x_ = x; 83 x_ = x;
77 y_ = y; 84 y_ = y;
78 } 85 }
86 void set_texcoord(float tx, float ty) {
87 tx_ = tx;
88 ty_ = ty;
89 }
79 float x_; 90 float x_;
80 float y_; 91 float y_;
81 float tx_; 92 float tx_;
82 float ty_; 93 float ty_;
83 }; 94 };
84 95
85 // Counter-clockwise verts starting from upper-left corner (0, 0). 96 // Counter-clockwise verts starting from upper-left corner (0, 0).
86 struct SurfaceQuad { 97 struct SurfaceQuad {
87 void set_size(gfx::Size vertex_size, gfx::Size texcoord_size) { 98 void set_size(gfx::Size vertex_size, gfx::Size texcoord_size) {
88 // Texture coordinates are flipped vertically so they can be drawn on 99 // Texture coordinates are flipped vertically so they can be drawn on
89 // a projection with a flipped y-axis (origin is top left). 100 // a projection with a flipped y-axis (origin is top left).
90 float vw = static_cast<float>(vertex_size.width()); 101 float vw = static_cast<float>(vertex_size.width());
91 float vh = static_cast<float>(vertex_size.height()); 102 float vh = static_cast<float>(vertex_size.height());
92 float tw = static_cast<float>(texcoord_size.width()); 103 float tw = static_cast<float>(texcoord_size.width());
93 float th = static_cast<float>(texcoord_size.height()); 104 float th = static_cast<float>(texcoord_size.height());
94 verts_[0].set(0.0f, 0.0f, 0.0f, th); 105 verts_[0].set(0.0f, 0.0f, 0.0f, th);
95 verts_[1].set(0.0f, vh, 0.0f, 0.0f); 106 verts_[1].set(0.0f, vh, 0.0f, 0.0f);
96 verts_[2].set(vw, vh, tw, 0.0f); 107 verts_[2].set(vw, vh, tw, 0.0f);
97 verts_[3].set(vw, 0.0f, tw, th); 108 verts_[3].set(vw, 0.0f, tw, th);
98 } 109 }
99 void set_rect(float x1, float y1, float x2, float y2) { 110 void set_rect(float x1, float y1, float x2, float y2) {
100 verts_[0].set_position(x1, y1); 111 verts_[0].set_position(x1, y1);
101 verts_[1].set_position(x1, y2); 112 verts_[1].set_position(x1, y2);
102 verts_[2].set_position(x2, y2); 113 verts_[2].set_position(x2, y2);
103 verts_[3].set_position(x2, y1); 114 verts_[3].set_position(x2, y1);
104 } 115 }
116 void set_texcoord_rect(float tx1, float ty1, float tx2, float ty2) {
117 // Texture coordinates are flipped vertically so they can be drawn on
118 // a projection with a flipped y-axis (origin is top left).
119 verts_[0].set_texcoord(tx1, ty2);
120 verts_[1].set_texcoord(tx1, ty1);
121 verts_[2].set_texcoord(tx2, ty1);
122 verts_[3].set_texcoord(tx2, ty2);
123 }
105 SurfaceVertex verts_[4]; 124 SurfaceVertex verts_[4];
106 }; 125 };
107 126
108 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support, 127 CompositingIOSurfaceMac(IOSurfaceSupport* io_surface_support,
109 NSOpenGLContext* glContext, 128 NSOpenGLContext* glContext,
110 CGLContextObj cglContext, 129 CGLContextObj cglContext,
111 GLuint shader_program_blit_rgb, 130 GLuint shader_program_blit_rgb,
112 GLint blit_rgb_sampler_location, 131 GLint blit_rgb_sampler_location,
113 GLuint shader_program_white, 132 GLuint shader_program_white,
114 bool is_vsync_disabled); 133 bool is_vsync_disabled);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 GLuint shader_program_white_; 167 GLuint shader_program_white_;
149 168
150 SurfaceQuad quad_; 169 SurfaceQuad quad_;
151 170
152 bool is_vsync_disabled_; 171 bool is_vsync_disabled_;
153 }; 172 };
154 173
155 } // namespace content 174 } // namespace content
156 175
157 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H 176 #endif // CONTENT_BROWSER_RENDERER_HOST_ACCELERATED_COMPOSITING_VIEW_MAC_H
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/compositing_iosurface_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698