Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/gpu/client/context_provider_command_buffer.h" | |
| 6 | |
| 7 #include "webkit/gpu/grcontext_for_webgraphicscontext3d.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 class ContextProviderCommandBuffer::LostContextCallbackProxy | |
| 12 : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | |
| 13 public: | |
| 14 LostContextCallbackProxy(ContextProviderCommandBuffer* provider) | |
| 15 : provider_(provider) { | |
| 16 provider_->context3d_->setContextLostCallback(this); | |
| 17 } | |
| 18 | |
| 19 virtual void onContextLost() { | |
| 20 provider_->OnLostContext(); | |
| 21 } | |
| 22 | |
| 23 private: | |
| 24 ContextProviderCommandBuffer* provider_; | |
| 25 }; | |
| 26 | |
| 27 class ContextProviderCommandBuffer::MemoryAllocationCallbackProxy | |
| 28 : public WebKit::WebGraphicsContext3D:: | |
| 29 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM { | |
| 30 public: | |
| 31 MemoryAllocationCallbackProxy(ContextProviderCommandBuffer* provider) | |
| 32 : provider_(provider) { | |
| 33 provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); | |
| 34 } | |
| 35 | |
| 36 void onMemoryAllocationChanged(WebKit::WebGraphicsMemoryAllocation alloc) { | |
| 37 provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 ContextProviderCommandBuffer* provider_; | |
| 42 }; | |
| 43 | |
| 44 ContextProviderCommandBuffer::ContextProviderCommandBuffer() | |
| 45 : destroyed_(false) { | |
| 46 } | |
| 47 | |
| 48 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() {} | |
| 49 | |
| 50 bool ContextProviderCommandBuffer::InitializeOnMainThread() { | |
| 51 if (destroyed_) | |
| 52 return false; | |
| 53 if (context3d_) | |
| 54 return true; | |
| 55 | |
| 56 context3d_ = CreateOffscreenContext3d().Pass(); | |
| 57 destroyed_ = !context3d_; | |
| 58 return !!context3d_; | |
| 59 } | |
| 60 | |
| 61 bool ContextProviderCommandBuffer::BindToCurrentThread() { | |
| 62 if (lost_context_callback_proxy_) | |
| 63 return true; | |
| 64 | |
| 65 bool result = context3d_->makeContextCurrent(); | |
| 66 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); | |
| 67 return result; | |
| 68 } | |
| 69 | |
| 70 WebGraphicsContext3DCommandBufferImpl* | |
| 71 ContextProviderCommandBuffer::Context3d() { | |
| 72 return context3d_.get(); | |
| 73 } | |
| 74 | |
| 75 class GrContext* ContextProviderCommandBuffer::GrContext() { | |
| 76 if (gr_context_) | |
| 77 return gr_context_->get(); | |
| 78 | |
| 79 gr_context_.reset( | |
| 80 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get())); | |
| 81 memory_allocation_callback_proxy_.reset( | |
| 82 new MemoryAllocationCallbackProxy(this)); | |
| 83 return gr_context_->get(); | |
| 84 } | |
| 85 | |
| 86 void ContextProviderCommandBuffer::VerifyContexts() { | |
| 87 if (!destroyed_ && context3d_->isContextLost()) | |
| 88 OnLostContext(); | |
| 89 } | |
| 90 | |
| 91 void ContextProviderCommandBuffer::OnLostContext() { | |
| 92 destroyed_ = true; | |
|
piman
2013/02/21 22:49:48
The pattern is a bit iffy because you set this on
danakj
2013/02/22 01:56:31
Done, and thanks for the explanations!
Renamed al
| |
| 93 } | |
| 94 | |
| 95 void ContextProviderCommandBuffer::OnMemoryAllocationChanged( | |
| 96 bool nonzero_allocation) { | |
| 97 if (gr_context_) | |
| 98 gr_context_->SetMemoryLimit(nonzero_allocation); | |
| 99 } | |
| 100 | |
| 101 } // namespace content | |
| OLD | NEW |