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/offscreen_context_command_buffer.h" |
| 6 |
| 7 namespace content { |
| 8 |
| 9 OffscreenContextCommandBuffer::OffscreenContextCommandBuffer( |
| 10 OffscreenContextCommandBufferClient* client) |
| 11 : client_(client) { |
| 12 } |
| 13 |
| 14 OffscreenContextCommandBuffer::~OffscreenContextCommandBuffer() { |
| 15 if (context3d_) { |
| 16 context3d_->setContextLostCallback(NULL); |
| 17 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
| 18 } |
| 19 } |
| 20 |
| 21 WebGraphicsContext3DCommandBufferImpl* OffscreenContextCommandBuffer:: |
| 22 Context3d() { |
| 23 if (context3d_) |
| 24 return context3d_.get(); |
| 25 |
| 26 context3d_.reset(client_->CreateOffscreenContext()); |
| 27 if (context3d_ && |
| 28 (!context3d_->makeContextCurrent() || |
| 29 context3d_->getGraphicsResetStatusARB())) |
| 30 context3d_.reset(); |
| 31 |
| 32 client_->DidCreateContext(this, !!context3d_); |
| 33 if (!context3d_) |
| 34 return NULL; |
| 35 |
| 36 context3d_->setContextLostCallback(this); |
| 37 // TODO(danakj): Talk to the GPU mem manager directly. |
| 38 context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this); |
| 39 return context3d_.get(); |
| 40 } |
| 41 |
| 42 void OffscreenContextCommandBuffer::onContextLost() { |
| 43 // Save the context3d until the notifications are done, but requests for a |
| 44 // context should create a new one. |
| 45 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d = |
| 46 context3d_.Pass(); |
| 47 if (context3d) |
| 48 context3d->setMemoryAllocationChangedCallbackCHROMIUM(NULL); |
| 49 |
| 50 // Inform the superclass. |
| 51 DidLoseContext(); |
| 52 |
| 53 client_->DidLoseContext(this); |
| 54 } |
| 55 |
| 56 // WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation. |
| 57 void OffscreenContextCommandBuffer::onMemoryAllocationChanged( |
| 58 WebKit::WebGraphicsMemoryAllocation allocation) { |
| 59 SetGaneshContextMemoryLimit(!!allocation.gpuResourceSizeInBytes); |
| 60 } |
| 61 |
| 62 } // namespace content |
OLD | NEW |