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

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

Issue 13749002: Cache OpenGL textures and other objects in CompositingIOSurfaceMac copy/transform code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_COMPOSITING_IOSURFACE_TRANSFORMER_MAC_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_TRANSFORMER_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_TRANSFORMER_MAC_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_TRANSFORMER_MAC_H_
7 7
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma c.h" 11 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma c.h"
12 #include "ui/gfx/size.h"
12 13
13 namespace gfx { 14 namespace gfx {
14 class Rect; 15 class Rect;
15 class Size;
16 } // namespace gfx 16 } // namespace gfx
17 17
18 namespace content { 18 namespace content {
19 19
20 // Provides useful image filtering operations that are implemented efficiently 20 // Provides useful image filtering operations that are implemented efficiently
21 // using OpenGL shader programs. 21 // using OpenGL shader programs.
22 // 22 //
23 // Note: All methods assume to be called within an active OpenGL context. 23 // Note: All methods assume to be called within an active OpenGL context.
24 class CompositingIOSurfaceTransformer { 24 class CompositingIOSurfaceTransformer {
25 public: 25 public:
26 // Construct a transformer that always uses the given parameters for texture 26 // Construct a transformer that always uses the given parameters for texture
27 // bindings. |texture_target| is one of the valid enums to use with 27 // bindings. |texture_target| is one of the valid enums to use with
28 // glBindTexture(). 28 // glBindTexture().
29 // |src_texture_needs_y_flip| is true when the |src_texture| argument to any 29 // |src_texture_needs_y_flip| is true when the |src_texture| argument to any
30 // of the methods below uses upside-down Y coordinates. 30 // of the methods below uses upside-down Y coordinates.
31 // |shader_program_cache| is not owned by this instance. 31 // |shader_program_cache| is not owned by this instance.
32 CompositingIOSurfaceTransformer( 32 CompositingIOSurfaceTransformer(
33 GLenum texture_target, bool src_texture_needs_y_flip, 33 GLenum texture_target, bool src_texture_needs_y_flip,
34 CompositingIOSurfaceShaderPrograms* shader_program_cache); 34 CompositingIOSurfaceShaderPrograms* shader_program_cache);
35 35
36 ~CompositingIOSurfaceTransformer(); 36 ~CompositingIOSurfaceTransformer();
37 37
38 // Delete any references to currently-cached OpenGL objects. This must be
39 // called within the OpenGL context just before destruction.
40 void ReleaseCachedGLObjects();
41
38 // Resize using bilinear interpolation. Returns false on error. Otherwise, 42 // Resize using bilinear interpolation. Returns false on error. Otherwise,
39 // the |texture| argument will point to the result and the caller is 43 // the |texture| argument will point to the result. Ownership of the returned
40 // responsible for calling glDeleteTexture(*texture). 44 // |texture| remains with CompositingIOSurfaceTransformer (i.e., the caller
45 // must not delete this texture). The |texture| remains valid until the next
46 // call to ResizeBilinear() or ReleaseCachedGLObjects().
41 // 47 //
42 // If the src and dst sizes are identical, this becomes a simple copy into a 48 // If the src and dst sizes are identical, this becomes a simple copy into a
43 // new texture. 49 // new texture.
44 // 50 //
45 // Note: This implementation is faulty in that minifications by more than 2X 51 // Note: This implementation is faulty in that minifications by more than 2X
46 // will undergo aliasing. 52 // will undergo aliasing.
47 bool ResizeBilinear(GLuint src_texture, const gfx::Rect& src_subrect, 53 bool ResizeBilinear(GLuint src_texture, const gfx::Rect& src_subrect,
48 const gfx::Size& dst_size, GLuint* texture); 54 const gfx::Size& dst_size, GLuint* texture);
49 55
50 // Color format conversion from RGB to planar YV12 (also known as YUV420). 56 // Color format conversion from RGB to planar YV12 (also known as YUV420).
51 // 57 //
52 // YV12 is effectively a twelve bit per pixel format consisting of a full- 58 // YV12 is effectively a twelve bit per pixel format consisting of a full-
53 // size y (luminance) plane and half-width, half-height u and v (blue and 59 // size y (luminance) plane and half-width, half-height u and v (blue and
54 // red chrominance) planes. This method will allocate three off-screen 60 // red chrominance) planes. This method will return three off-screen
55 // textures, one for each plane, and return them via the output arguments 61 // textures, one for each plane, via the output arguments |texture_y|,
56 // |texture_y|, |texture_u|, and |texture_v|. While the textures are in 62 // |texture_u|, and |texture_v|. While the textures are in GL_RGBA format,
57 // GL_RGBA format, they should be interpreted as the appropriate single-byte, 63 // they should be interpreted as the appropriate single-byte, planar format
58 // planar format after reading the pixel data. The output arguments 64 // after reading the pixel data. The output arguments |packed_y_size| and
59 // |packed_y_size| and |packed_uv_size| follow from these special semantics: 65 // |packed_uv_size| follow from these special semantics: They represent the
60 // They represent the size of their corresponding texture, if it was to be 66 // size of their corresponding texture, if it was to be treated like RGBA
61 // treated like RGBA pixel data. That means their widths are in terms of 67 // pixel data. That means their widths are in terms of "quads," where one
62 // "quads," where one quad contains 4 Y (or U or V) pixels. 68 // quad contains 4 Y (or U or V) pixels.
69 //
70 // Ownership of the returned textures remains with
71 // CompositingIOSurfaceTransformer (i.e., the caller must not delete the
72 // textures). The textures remain valid until the next call to
73 // TransformRGBToYV12() or ReleaseCachedGLObjects().
63 // 74 //
64 // If |src_subrect|'s size does not match |dst_size|, the source will be 75 // If |src_subrect|'s size does not match |dst_size|, the source will be
65 // bilinearly interpolated during conversion. 76 // bilinearly interpolated during conversion.
66 // 77 //
67 // Returns true if successful, and the caller is responsible for deleting the 78 // Returns true if successful, and the caller is responsible for deleting the
68 // output textures. 79 // output textures.
69 bool TransformRGBToYV12( 80 bool TransformRGBToYV12(
70 GLuint src_texture, const gfx::Rect& src_subrect, 81 GLuint src_texture, const gfx::Rect& src_subrect,
71 const gfx::Size& dst_size, 82 const gfx::Size& dst_size,
72 GLuint* texture_y, GLuint* texture_u, GLuint* texture_v, 83 GLuint* texture_y, GLuint* texture_u, GLuint* texture_v,
73 gfx::Size* packed_y_size, gfx::Size* packed_uv_size); 84 gfx::Size* packed_y_size, gfx::Size* packed_uv_size);
74 85
75 private: 86 private:
87 enum CachedTexture {
88 RGBA_OUTPUT = 0,
89 Y_PLANE_OUTPUT,
90 UUVV_INTERMEDIATE,
91 U_PLANE_OUTPUT,
92 V_PLANE_OUTPUT,
93 NUM_CACHED_TEXTURES
94 };
95
96 // If necessary, generate the texture and/or resize it to the given |size|.
97 void PrepareTexture(CachedTexture which, const gfx::Size& size);
ncarter (slow) 2013/04/15 23:38:19 Should this return the texture name?
miu 2013/04/16 03:51:22 If the method was public, I'd probably do that and
98
99 // If necessary, generate a framebuffer object to be used as an intermediate
100 // destination for drawing.
101 void PrepareFramebuffer();
102
76 // Target to bind all input and output textures to (which defines the type of 103 // Target to bind all input and output textures to (which defines the type of
77 // textures being created and read). Generally, this is 104 // textures being created and read). Generally, this is
78 // GL_TEXTURE_RECTANGLE_ARB. 105 // GL_TEXTURE_RECTANGLE_ARB.
79 const GLenum texture_target_; 106 const GLenum texture_target_;
80 const bool src_texture_needs_y_flip_; 107 const bool src_texture_needs_y_flip_;
81 CompositingIOSurfaceShaderPrograms* const shader_program_cache_; 108 CompositingIOSurfaceShaderPrograms* const shader_program_cache_;
82 109
110 // Cached OpenGL objects.
111 GLuint textures_[NUM_CACHED_TEXTURES];
112 gfx::Size texture_sizes_[NUM_CACHED_TEXTURES];
113 GLuint frame_buffer_;
114
83 // Auto-detected and set once in the constructor. 115 // Auto-detected and set once in the constructor.
84 bool system_supports_multiple_draw_buffers_; 116 bool system_supports_multiple_draw_buffers_;
85 117
86 DISALLOW_COPY_AND_ASSIGN(CompositingIOSurfaceTransformer); 118 DISALLOW_COPY_AND_ASSIGN(CompositingIOSurfaceTransformer);
87 }; 119 };
88 120
89 } // namespace content 121 } // namespace content
90 122
91 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_TRANSFORMER_MAC_H _ 123 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_TRANSFORMER_MAC_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698