| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/compositor_bindings/web_external_texture_layer_impl.h" | |
| 6 | |
| 7 #include "cc/layers/texture_layer.h" | |
| 8 #include "cc/resources/resource_update_queue.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" | |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" | |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
| 13 #include "webkit/compositor_bindings/web_layer_impl.h" | |
| 14 | |
| 15 using cc::TextureLayer; | |
| 16 using cc::ResourceUpdateQueue; | |
| 17 | |
| 18 namespace webkit { | |
| 19 | |
| 20 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( | |
| 21 WebKit::WebExternalTextureLayerClient* client, | |
| 22 bool mailbox) | |
| 23 : client_(client), | |
| 24 uses_mailbox_(mailbox) { | |
| 25 scoped_refptr<TextureLayer> layer; | |
| 26 cc::TextureLayerClient* cc_client = client_ ? this : NULL; | |
| 27 if (mailbox) | |
| 28 layer = TextureLayer::CreateForMailbox(cc_client); | |
| 29 else | |
| 30 layer = TextureLayer::Create(cc_client); | |
| 31 layer->SetIsDrawable(true); | |
| 32 layer_.reset(new WebLayerImpl(layer)); | |
| 33 } | |
| 34 | |
| 35 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { | |
| 36 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); | |
| 37 } | |
| 38 | |
| 39 WebKit::WebLayer* WebExternalTextureLayerImpl::layer() { return layer_.get(); } | |
| 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 | |
| 50 void WebExternalTextureLayerImpl::setTextureId(unsigned id) { | |
| 51 static_cast<TextureLayer*>(layer_->layer())->SetTextureId(id); | |
| 52 } | |
| 53 | |
| 54 void WebExternalTextureLayerImpl::setFlipped(bool flipped) { | |
| 55 static_cast<TextureLayer*>(layer_->layer())->SetFlipped(flipped); | |
| 56 } | |
| 57 | |
| 58 void WebExternalTextureLayerImpl::setUVRect(const WebKit::WebFloatRect& rect) { | |
| 59 static_cast<TextureLayer*>(layer_->layer())->SetUV( | |
| 60 gfx::PointF(rect.x, rect.y), | |
| 61 gfx::PointF(rect.x + rect.width, rect.y + rect.height)); | |
| 62 } | |
| 63 | |
| 64 void WebExternalTextureLayerImpl::setOpaque(bool opaque) { | |
| 65 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); | |
| 66 } | |
| 67 | |
| 68 void WebExternalTextureLayerImpl::setPremultipliedAlpha( | |
| 69 bool premultiplied_alpha) { | |
| 70 static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha( | |
| 71 premultiplied_alpha); | |
| 72 } | |
| 73 | |
| 74 void WebExternalTextureLayerImpl::willModifyTexture() { | |
| 75 static_cast<TextureLayer*>(layer_->layer())->WillModifyTexture(); | |
| 76 } | |
| 77 | |
| 78 void WebExternalTextureLayerImpl::setRateLimitContext(bool rate_limit) { | |
| 79 static_cast<TextureLayer*>(layer_->layer())->SetRateLimitContext(rate_limit); | |
| 80 } | |
| 81 | |
| 82 class WebTextureUpdaterImpl : public WebKit::WebTextureUpdater { | |
| 83 public: | |
| 84 explicit WebTextureUpdaterImpl(ResourceUpdateQueue* queue) : queue_(queue) {} | |
| 85 | |
| 86 virtual void appendCopy(unsigned source_texture, | |
| 87 unsigned destination_texture, | |
| 88 WebKit::WebSize size) OVERRIDE { | |
| 89 cc::TextureCopier::Parameters copy = { source_texture, destination_texture, | |
| 90 size }; | |
| 91 queue_->AppendCopy(copy); | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 ResourceUpdateQueue* queue_; | |
| 96 }; | |
| 97 | |
| 98 unsigned WebExternalTextureLayerImpl::PrepareTexture( | |
| 99 ResourceUpdateQueue* queue) { | |
| 100 DCHECK(client_); | |
| 101 WebTextureUpdaterImpl updater_impl(queue); | |
| 102 return client_->prepareTexture(updater_impl); | |
| 103 } | |
| 104 | |
| 105 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { | |
| 106 DCHECK(client_); | |
| 107 return client_->context(); | |
| 108 } | |
| 109 | |
| 110 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( | |
| 111 cc::TextureMailbox* mailbox) { | |
| 112 WebKit::WebExternalTextureMailbox client_mailbox; | |
| 113 if (!client_->prepareMailbox(&client_mailbox)) { | |
| 114 return false; | |
| 115 } | |
| 116 gpu::Mailbox name; | |
| 117 name.SetName(client_mailbox.name); | |
| 118 cc::TextureMailbox::ReleaseCallback callback = | |
| 119 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, | |
| 120 this->AsWeakPtr(), | |
| 121 client_mailbox); | |
| 122 *mailbox = cc::TextureMailbox(name, callback, client_mailbox.syncPoint); | |
| 123 return true; | |
| 124 } | |
| 125 | |
| 126 void WebExternalTextureLayerImpl::DidReleaseMailbox( | |
| 127 const WebKit::WebExternalTextureMailbox& mailbox, | |
| 128 unsigned sync_point, | |
| 129 bool lost_resource) { | |
| 130 if (lost_resource) | |
| 131 return; | |
| 132 | |
| 133 WebKit::WebExternalTextureMailbox available_mailbox; | |
| 134 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); | |
| 135 available_mailbox.syncPoint = sync_point; | |
| 136 client_->mailboxReleased(available_mailbox); | |
| 137 } | |
| 138 | |
| 139 } // namespace webkit | |
| OLD | NEW |