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

Side by Side Diff: content/common/gpu/image_transport_surface_mac.cc

Issue 15925007: Virtual context MakeCurrent tweaks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 #include "content/common/gpu/image_transport_surface.h" 5 #include "content/common/gpu/image_transport_surface.h"
6 6
7 #include "base/mac/scoped_cftyperef.h" 7 #include "base/mac/scoped_cftyperef.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "content/common/gpu/gpu_command_buffer_stub.h"
9 #include "content/common/gpu/gpu_messages.h" 10 #include "content/common/gpu/gpu_messages.h"
10 #include "ui/gfx/native_widget_types.h" 11 #include "ui/gfx/native_widget_types.h"
11 #include "ui/gl/gl_bindings.h" 12 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_context.h" 13 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_surface_cgl.h" 15 #include "ui/gl/gl_surface_cgl.h"
15 #include "ui/gl/gl_surface_osmesa.h" 16 #include "ui/gl/gl_surface_osmesa.h"
16 #include "ui/surface/io_surface_support_mac.h" 17 #include "ui/surface/io_surface_support_mac.h"
17 18
18 namespace content { 19 namespace content {
19 namespace { 20 namespace {
20 21
21 // IOSurface dimensions will be rounded up to a multiple of this value in order 22 // IOSurface dimensions will be rounded up to a multiple of this value in order
22 // to reduce memory thrashing during resize. This must be a power of 2. 23 // to reduce memory thrashing during resize. This must be a power of 2.
23 const uint32 kIOSurfaceDimensionRoundup = 64; 24 const uint32 kIOSurfaceDimensionRoundup = 64;
24 25
25 int RoundUpSurfaceDimension(int number) { 26 int RoundUpSurfaceDimension(int number) {
26 DCHECK(number >= 0); 27 DCHECK(number >= 0);
27 // Cast into unsigned space for portable bitwise ops. 28 // Cast into unsigned space for portable bitwise ops.
28 uint32 unsigned_number = static_cast<uint32>(number); 29 uint32 unsigned_number = static_cast<uint32>(number);
29 uint32 roundup_sub_1 = kIOSurfaceDimensionRoundup - 1; 30 uint32 roundup_sub_1 = kIOSurfaceDimensionRoundup - 1;
30 unsigned_number = (unsigned_number + roundup_sub_1) & ~roundup_sub_1; 31 unsigned_number = (unsigned_number + roundup_sub_1) & ~roundup_sub_1;
31 return static_cast<int>(unsigned_number); 32 return static_cast<int>(unsigned_number);
32 } 33 }
33 34
34 // We are backed by an offscreen surface for the purposes of creating 35 // We are backed by an offscreen surface for the purposes of creating
35 // a context, but use FBOs to render to texture backed IOSurface 36 // a context, but use FBOs to render to texture backed IOSurface
36 class IOSurfaceImageTransportSurface : public gfx::NoOpGLSurfaceCGL, 37 class IOSurfaceImageTransportSurface
37 public ImageTransportSurface { 38 : public gfx::NoOpGLSurfaceCGL,
39 public ImageTransportSurface,
40 public GpuCommandBufferStub::DestructionObserver {
38 public: 41 public:
39 IOSurfaceImageTransportSurface(GpuChannelManager* manager, 42 IOSurfaceImageTransportSurface(GpuChannelManager* manager,
40 GpuCommandBufferStub* stub, 43 GpuCommandBufferStub* stub,
41 gfx::PluginWindowHandle handle); 44 gfx::PluginWindowHandle handle);
42 45
43 // GLSurface implementation 46 // GLSurface implementation
44 virtual bool Initialize() OVERRIDE; 47 virtual bool Initialize() OVERRIDE;
45 virtual void Destroy() OVERRIDE; 48 virtual void Destroy() OVERRIDE;
46 virtual bool DeferDraws() OVERRIDE; 49 virtual bool DeferDraws() OVERRIDE;
47 virtual bool IsOffscreen() OVERRIDE; 50 virtual bool IsOffscreen() OVERRIDE;
48 virtual bool SwapBuffers() OVERRIDE; 51 virtual bool SwapBuffers() OVERRIDE;
49 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; 52 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
50 virtual std::string GetExtensions() OVERRIDE; 53 virtual std::string GetExtensions() OVERRIDE;
51 virtual gfx::Size GetSize() OVERRIDE; 54 virtual gfx::Size GetSize() OVERRIDE;
52 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; 55 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE;
53 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; 56 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE;
54 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE; 57 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE;
55 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; 58 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE;
56 59
57 protected: 60 protected:
58 // ImageTransportSurface implementation 61 // ImageTransportSurface implementation
59 virtual void OnBufferPresented( 62 virtual void OnBufferPresented(
60 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE; 63 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE;
61 virtual void OnResizeViewACK() OVERRIDE; 64 virtual void OnResizeViewACK() OVERRIDE;
62 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE; 65 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE;
63 virtual void SetLatencyInfo(const ui::LatencyInfo&) OVERRIDE; 66 virtual void SetLatencyInfo(const ui::LatencyInfo&) OVERRIDE;
64 67
68 // GpuCommandBufferStub::DestructionObserver implementation.
69 virtual void OnWillDestroyStub() OVERRIDE;
70
65 private: 71 private:
66 virtual ~IOSurfaceImageTransportSurface() OVERRIDE; 72 virtual ~IOSurfaceImageTransportSurface() OVERRIDE;
67 73
68 void AdjustBufferAllocation(); 74 void AdjustBufferAllocation();
69 void UnrefIOSurface(); 75 void UnrefIOSurface();
70 void CreateIOSurface(); 76 void CreateIOSurface();
71 77
72 // Tracks the current buffer allocation state. 78 // Tracks the current buffer allocation state.
73 bool backbuffer_suggested_allocation_; 79 bool backbuffer_suggested_allocation_;
74 bool frontbuffer_suggested_allocation_; 80 bool frontbuffer_suggested_allocation_;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 io_surface_handle_(0), 137 io_surface_handle_(0),
132 context_(NULL), 138 context_(NULL),
133 scale_factor_(1.f), 139 scale_factor_(1.f),
134 made_current_(false), 140 made_current_(false),
135 is_swap_buffers_pending_(false), 141 is_swap_buffers_pending_(false),
136 did_unschedule_(false) { 142 did_unschedule_(false) {
137 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); 143 helper_.reset(new ImageTransportHelper(this, manager, stub, handle));
138 } 144 }
139 145
140 IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() { 146 IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() {
141 Destroy();
142 } 147 }
143 148
144 bool IOSurfaceImageTransportSurface::Initialize() { 149 bool IOSurfaceImageTransportSurface::Initialize() {
145 // Only support IOSurfaces if the GL implementation is the native desktop GL. 150 // Only support IOSurfaces if the GL implementation is the native desktop GL.
146 // IO surfaces will not work with, for example, OSMesa software renderer 151 // IO surfaces will not work with, for example, OSMesa software renderer
147 // GL contexts. 152 // GL contexts.
148 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL && 153 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL &&
149 gfx::GetGLImplementation() != gfx::kGLImplementationAppleGL) 154 gfx::GetGLImplementation() != gfx::kGLImplementationAppleGL)
150 return false; 155 return false;
151 156
152 if (!helper_->Initialize()) 157 if (!helper_->Initialize())
153 return false; 158 return false;
154 return NoOpGLSurfaceCGL::Initialize(); 159
160 if (!NoOpGLSurfaceCGL::Initialize())
no sievers 2013/06/05 00:21:16 I guess for correctness it should call helper_->De
piman 2013/06/05 00:33:32 You're probably right, though it's a NOOP anyway.
no sievers 2013/06/05 00:38:04 Done.
161 return false;
162
163 helper_->stub()->AddDestructionObserver(this);
164 return true;
155 } 165 }
156 166
157 void IOSurfaceImageTransportSurface::Destroy() { 167 void IOSurfaceImageTransportSurface::Destroy() {
158 UnrefIOSurface(); 168 UnrefIOSurface();
159 169
160 helper_->Destroy(); 170 helper_->Destroy();
161 NoOpGLSurfaceCGL::Destroy(); 171 NoOpGLSurfaceCGL::Destroy();
162 } 172 }
163 173
164 bool IOSurfaceImageTransportSurface::DeferDraws() { 174 bool IOSurfaceImageTransportSurface::DeferDraws() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 scale_factor_ = scale_factor; 316 scale_factor_ = scale_factor;
307 317
308 CreateIOSurface(); 318 CreateIOSurface();
309 } 319 }
310 320
311 void IOSurfaceImageTransportSurface::SetLatencyInfo( 321 void IOSurfaceImageTransportSurface::SetLatencyInfo(
312 const ui::LatencyInfo& latency_info) { 322 const ui::LatencyInfo& latency_info) {
313 latency_info_ = latency_info; 323 latency_info_ = latency_info;
314 } 324 }
315 325
326 void IOSurfaceImageTransportSurface::OnWillDestroyStub() {
327 helper_->stub()->RemoveDestructionObserver(this);
328 Destroy();
329 }
330
316 void IOSurfaceImageTransportSurface::UnrefIOSurface() { 331 void IOSurfaceImageTransportSurface::UnrefIOSurface() {
317 // If we have resources to destroy, then make sure that we have a current 332 // If we have resources to destroy, then make sure that we have a current
318 // context which we can use to delete the resources. 333 // context which we can use to delete the resources.
319 if (context_ || fbo_id_ || texture_id_) { 334 if (context_ || fbo_id_ || texture_id_) {
320 DCHECK(gfx::GLContext::GetCurrent() == context_); 335 DCHECK(gfx::GLContext::GetCurrent() == context_);
321 DCHECK(context_->IsCurrent(this)); 336 DCHECK(context_->IsCurrent(this));
322 DCHECK(CGLGetCurrentContext()); 337 DCHECK(CGLGetCurrentContext());
323 } 338 }
324 339
325 if (fbo_id_) { 340 if (fbo_id_) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 manager, stub, surface.get(), false)); 499 manager, stub, surface.get(), false));
485 } 500 }
486 } 501 }
487 502
488 // static 503 // static
489 void ImageTransportSurface::SetAllowOSMesaForTesting(bool allow) { 504 void ImageTransportSurface::SetAllowOSMesaForTesting(bool allow) {
490 g_allow_os_mesa = allow; 505 g_allow_os_mesa = allow;
491 } 506 }
492 507
493 } // namespace content 508 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_command_buffer_stub.cc ('k') | gpu/command_buffer/service/gl_context_virtual.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698