| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "webkit/compositor_bindings/web_external_texture_layer_impl.h" | 5 #include "webkit/compositor_bindings/web_external_texture_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/layers/texture_layer.h" | 7 #include "cc/layers/texture_layer.h" |
| 8 #include "cc/resources/resource_update_queue.h" | 8 #include "cc/resources/resource_update_queue.h" |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayerClient.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayerClient.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureM
ailbox.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 12 #include "webkit/compositor_bindings/web_layer_impl.h" | 13 #include "webkit/compositor_bindings/web_layer_impl.h" |
| 13 | 14 |
| 14 using cc::TextureLayer; | 15 using cc::TextureLayer; |
| 15 using cc::ResourceUpdateQueue; | 16 using cc::ResourceUpdateQueue; |
| 16 | 17 |
| 17 namespace webkit { | 18 namespace webkit { |
| 18 | 19 |
| 19 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( | 20 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( |
| 20 WebKit::WebExternalTextureLayerClient* client) | 21 WebKit::WebExternalTextureLayerClient* client, |
| 21 : client_(client) { | 22 bool mailbox) |
| 23 : client_(client), |
| 24 uses_mailbox_(mailbox) { |
| 22 scoped_refptr<TextureLayer> layer; | 25 scoped_refptr<TextureLayer> layer; |
| 23 if (client_) | 26 cc::TextureLayerClient* cc_client = client_ ? this : NULL; |
| 24 layer = TextureLayer::Create(this); | 27 if (mailbox) |
| 28 layer = TextureLayer::CreateForMailbox(cc_client); |
| 25 else | 29 else |
| 26 layer = TextureLayer::Create(NULL); | 30 layer = TextureLayer::Create(cc_client); |
| 27 layer->SetIsDrawable(true); | 31 layer->SetIsDrawable(true); |
| 28 layer_.reset(new WebLayerImpl(layer)); | 32 layer_.reset(new WebLayerImpl(layer)); |
| 29 } | 33 } |
| 30 | 34 |
| 31 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { | 35 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { |
| 32 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); | 36 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); |
| 33 } | 37 } |
| 34 | 38 |
| 35 WebKit::WebLayer* WebExternalTextureLayerImpl::layer() { return layer_.get(); } | 39 WebKit::WebLayer* WebExternalTextureLayerImpl::layer() { return layer_.get(); } |
| 36 | 40 |
| 41 void WebExternalTextureLayerImpl::clearTexture() { |
| 42 if (uses_mailbox_) { |
| 43 static_cast<TextureLayer*>(layer_->layer())->SetTextureMailbox( |
| 44 cc::TextureMailbox()); |
| 45 } else { |
| 46 static_cast<TextureLayer*>(layer_->layer())->SetTextureId(0); |
| 47 } |
| 48 } |
| 49 |
| 37 void WebExternalTextureLayerImpl::setTextureId(unsigned id) { | 50 void WebExternalTextureLayerImpl::setTextureId(unsigned id) { |
| 38 static_cast<TextureLayer*>(layer_->layer())->SetTextureId(id); | 51 static_cast<TextureLayer*>(layer_->layer())->SetTextureId(id); |
| 39 } | 52 } |
| 40 | 53 |
| 41 void WebExternalTextureLayerImpl::setFlipped(bool flipped) { | 54 void WebExternalTextureLayerImpl::setFlipped(bool flipped) { |
| 42 static_cast<TextureLayer*>(layer_->layer())->SetFlipped(flipped); | 55 static_cast<TextureLayer*>(layer_->layer())->SetFlipped(flipped); |
| 43 } | 56 } |
| 44 | 57 |
| 45 void WebExternalTextureLayerImpl::setUVRect(const WebKit::WebFloatRect& rect) { | 58 void WebExternalTextureLayerImpl::setUVRect(const WebKit::WebFloatRect& rect) { |
| 46 static_cast<TextureLayer*>(layer_->layer())->SetUV( | 59 static_cast<TextureLayer*>(layer_->layer())->SetUV( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 DCHECK(client_); | 100 DCHECK(client_); |
| 88 WebTextureUpdaterImpl updater_impl(queue); | 101 WebTextureUpdaterImpl updater_impl(queue); |
| 89 return client_->prepareTexture(updater_impl); | 102 return client_->prepareTexture(updater_impl); |
| 90 } | 103 } |
| 91 | 104 |
| 92 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { | 105 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { |
| 93 DCHECK(client_); | 106 DCHECK(client_); |
| 94 return client_->context(); | 107 return client_->context(); |
| 95 } | 108 } |
| 96 | 109 |
| 97 } // namespace webkit | 110 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( |
| 111 cc::TextureMailbox* out_mailbox) { |
| 112 WebKit::WebExternalTextureMailbox mailbox; |
| 113 if (!client_->prepareMailbox(&mailbox)) { |
| 114 return false; |
| 115 } |
| 116 gpu::Mailbox name; |
| 117 name.SetName(mailbox.name); |
| 118 cc::TextureMailbox::ReleaseCallback callback = |
| 119 base::Bind(&WebExternalTextureLayerImpl::mailboxReleased, |
| 120 this->AsWeakPtr(), |
| 121 mailbox); |
| 122 *out_mailbox = cc::TextureMailbox(name, callback, mailbox.syncPoint); |
| 123 return true; |
| 124 } |
| 125 |
| 126 void WebExternalTextureLayerImpl::mailboxReleased( |
| 127 const WebKit::WebExternalTextureMailbox &mailbox, |
| 128 unsigned sync_point) { |
| 129 WebKit::WebExternalTextureMailbox available_mailbox; |
| 130 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); |
| 131 available_mailbox.syncPoint = sync_point; |
| 132 client_->mailboxReleased(available_mailbox); |
| 133 } |
| 134 |
| 135 } // namespace webkit |
| OLD | NEW |