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

Side by Side Diff: content/common/gpu/image_transport_surface_fbo_mac.h

Issue 334173006: Clean up GLSurfaceCGL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ 5 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_FBO_MAC_H_
6 #define CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ 6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_FBO_MAC_H_
7 7
8 #include <string> 8 #include "base/mac/scoped_cftyperef.h"
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
12 #include "content/common/gpu/gpu_command_buffer_stub.h" 10 #include "content/common/gpu/gpu_command_buffer_stub.h"
13 #include "content/common/gpu/image_transport_surface.h" 11 #include "content/common/gpu/image_transport_surface.h"
14 #include "gpu/command_buffer/common/mailbox.h" 12 #include "ui/gl/gl_bindings.h"
15 #include "gpu/command_buffer/service/texture_manager.h"
16 #include "ui/gl/gl_context.h"
17 #include "ui/gl/gl_surface.h"
18 13
19 namespace content { 14 namespace content {
20 class GpuChannelManager;
21 15
22 class TextureImageTransportSurface 16 // We are backed by an offscreen surface for the purposes of creating
23 : public ImageTransportSurface, 17 // a context, but use FBOs to render to texture. The texture may be backed by
24 public GpuCommandBufferStub::DestructionObserver, 18 // an IOSurface, or it may be presented to the screen via a CALayer, depending
25 public gfx::GLSurface { 19 // on the StorageProvider class specified.
20 class ImageTransportSurfaceFBO
21 : public gfx::GLSurface,
22 public ImageTransportSurface,
23 public GpuCommandBufferStub::DestructionObserver {
26 public: 24 public:
27 TextureImageTransportSurface(GpuChannelManager* manager, 25 // The interface through which storage for the color buffer of the FBO is
28 GpuCommandBufferStub* stub, 26 // allocated.
29 const gfx::GLSurfaceHandle& handle); 27 class StorageProvider {
28 public:
29 virtual ~StorageProvider() {}
30 // IOSurfaces cause too much address space fragmentation if they are
31 // allocated on every resize. This gets a rounded size for allocation.
32 virtual gfx::Size GetRoundedSize(gfx::Size size) = 0;
30 33
31 // gfx::GLSurface implementation. 34 // Allocate the storage for the color buffer. The specified context is
35 // current, and there is a texture bound to GL_TEXTURE_RECTANGLE_ARB.
36 virtual bool AllocateColorBufferStorage(
37 CGLContextObj context, gfx::Size size) = 0;
38
39 // Free the storage allocated in the AllocateColorBufferStorage call. The
40 // GL texture that was bound has already been deleted by the caller.
41 virtual void FreeColorBufferStorage() = 0;
42
43 // Retrieve the handle for the surface to send to the browser process to
44 // display.
45 virtual uint64 GetSurfaceHandle() const = 0;
46 };
47
48 ImageTransportSurfaceFBO(StorageProvider* storage_provider,
49 GpuChannelManager* manager,
50 GpuCommandBufferStub* stub,
51 gfx::PluginWindowHandle handle);
52
53 // GLSurface implementation
32 virtual bool Initialize() OVERRIDE; 54 virtual bool Initialize() OVERRIDE;
33 virtual void Destroy() OVERRIDE; 55 virtual void Destroy() OVERRIDE;
34 virtual bool DeferDraws() OVERRIDE; 56 virtual bool DeferDraws() OVERRIDE;
35 virtual bool IsOffscreen() OVERRIDE; 57 virtual bool IsOffscreen() OVERRIDE;
36 virtual bool SwapBuffers() OVERRIDE; 58 virtual bool SwapBuffers() OVERRIDE;
59 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
60 virtual bool SupportsPostSubBuffer() OVERRIDE;
37 virtual gfx::Size GetSize() OVERRIDE; 61 virtual gfx::Size GetSize() OVERRIDE;
38 virtual void* GetHandle() OVERRIDE; 62 virtual void* GetHandle() OVERRIDE;
39 virtual unsigned GetFormat() OVERRIDE; 63 virtual void* GetDisplay() OVERRIDE;
40 virtual bool SupportsPostSubBuffer() OVERRIDE; 64 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE;
41 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; 65 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE;
42 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
43 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE; 66 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE;
44 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; 67 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE;
45 virtual void* GetShareHandle() OVERRIDE;
46 virtual void* GetDisplay() OVERRIDE;
47 virtual void* GetConfig() OVERRIDE;
48 68
49 protected: 69 protected:
50 // ImageTransportSurface implementation. 70 // ImageTransportSurface implementation
51 virtual void OnBufferPresented( 71 virtual void OnBufferPresented(
52 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE; 72 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE;
53 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE; 73 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE;
54 virtual void SetLatencyInfo( 74 virtual void SetLatencyInfo(
55 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE; 75 const std::vector<ui::LatencyInfo>&) OVERRIDE;
56 virtual void WakeUpGpu() OVERRIDE; 76 virtual void WakeUpGpu() OVERRIDE;
57 77
58 // GpuCommandBufferStub::DestructionObserver implementation. 78 // GpuCommandBufferStub::DestructionObserver implementation.
59 virtual void OnWillDestroyStub() OVERRIDE; 79 virtual void OnWillDestroyStub() OVERRIDE;
60 80
61 private: 81 private:
82 virtual ~ImageTransportSurfaceFBO() OVERRIDE;
62 83
63 gfx::Size backbuffer_size() const { 84 void AdjustBufferAllocation();
64 DCHECK(backbuffer_.get()); 85 void DestroyFramebuffer();
65 GLsizei width = 0; 86 void CreateFramebuffer();
66 GLsizei height = 0;
67 backbuffer_->texture()->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height);
68 return gfx::Size(width, height);
69 }
70 87
71 virtual ~TextureImageTransportSurface(); 88 scoped_ptr<StorageProvider> storage_provider_;
72 void CreateBackTexture();
73 void AttachBackTextureToFBO();
74 void ReleaseBackTexture();
75 void ReleaseFrontTexture();
76 void BufferPresentedImpl(const gpu::Mailbox& mailbox_name);
77 89
78 // The framebuffer that represents this surface (service id). Allocated lazily 90 // Tracks the current buffer allocation state.
79 // in OnMakeCurrent.
80 uint32 fbo_id_;
81
82 // The current backbuffer.
83 scoped_refptr<gpu::gles2::TextureRef> backbuffer_;
84 scoped_refptr<gpu::gles2::TextureRef> frontbuffer_;
85
86 // The mailbox name for the current backbuffer texture. Needs to be unique per
87 // GL texture and is invalid while service_id is zero.
88 gpu::Mailbox back_mailbox_;
89 gpu::Mailbox front_mailbox_;
90
91 // The current size of the GLSurface. Used to disambiguate from the current
92 // texture size which might be outdated (since we use two buffers).
93 gfx::Size current_size_;
94 float scale_factor_;
95
96 // Whether or not the command buffer stub has been destroyed.
97 bool stub_destroyed_;
98
99 bool backbuffer_suggested_allocation_; 91 bool backbuffer_suggested_allocation_;
100 bool frontbuffer_suggested_allocation_; 92 bool frontbuffer_suggested_allocation_;
101 93
102 scoped_ptr<ImageTransportHelper> helper_; 94 uint32 fbo_id_;
103 gfx::GLSurfaceHandle handle_; 95 GLuint texture_id_;
96 GLuint depth_stencil_renderbuffer_id_;
97 bool has_complete_framebuffer_;
104 98
105 // The offscreen surface used to make the context current. However note that 99 // Weak pointer to the context that this was last made current to.
106 // the actual rendering is always redirected to an FBO. 100 gfx::GLContext* context_;
107 scoped_refptr<gfx::GLSurface> surface_; 101
102 gfx::Size size_;
103 gfx::Size rounded_size_;
104 float scale_factor_;
105
106 // Whether or not we've successfully made the surface current once.
107 bool made_current_;
108 108
109 // Whether a SwapBuffers is pending. 109 // Whether a SwapBuffers is pending.
110 bool is_swap_buffers_pending_; 110 bool is_swap_buffers_pending_;
111 111
112 // Whether we unscheduled command buffer because of pending SwapBuffers. 112 // Whether we unscheduled command buffer because of pending SwapBuffers.
113 bool did_unschedule_; 113 bool did_unschedule_;
114 114
115 // Holds a reference to the mailbox manager for cleanup. 115 std::vector<ui::LatencyInfo> latency_info_;
116 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
117 116
118 std::vector<ui::LatencyInfo> latency_info_; 117 scoped_ptr<ImageTransportHelper> helper_;
119 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); 118
119 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurfaceFBO);
120 }; 120 };
121 121
122 } // namespace content 122 } // namespace content
123 123
124 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ 124 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_MAC_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.mm ('k') | content/common/gpu/image_transport_surface_fbo_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698