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/renderer/compositor_bindings/web_external_texture_layer_impl.h" | 5 #include "webkit/renderer/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 "cc/resources/scoped_release_callback.h" |
| 10 #include "cc/resources/texture_mailbox.h" |
9 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" | 11 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" |
10 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" | 12 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" |
11 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 13 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
12 #include "third_party/WebKit/public/platform/WebSize.h" | 14 #include "third_party/WebKit/public/platform/WebSize.h" |
13 #include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h" | 15 #include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h" |
14 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | 16 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" |
15 | 17 |
16 using cc::TextureLayer; | 18 using cc::TextureLayer; |
17 using cc::ResourceUpdateQueue; | 19 using cc::ResourceUpdateQueue; |
18 | 20 |
(...skipping 10 matching lines...) Expand all Loading... |
29 | 31 |
30 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { | 32 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { |
31 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); | 33 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); |
32 } | 34 } |
33 | 35 |
34 WebKit::WebLayer* WebExternalTextureLayerImpl::layer() { return layer_.get(); } | 36 WebKit::WebLayer* WebExternalTextureLayerImpl::layer() { return layer_.get(); } |
35 | 37 |
36 void WebExternalTextureLayerImpl::clearTexture() { | 38 void WebExternalTextureLayerImpl::clearTexture() { |
37 TextureLayer *layer = static_cast<TextureLayer*>(layer_->layer()); | 39 TextureLayer *layer = static_cast<TextureLayer*>(layer_->layer()); |
38 layer->WillModifyTexture(); | 40 layer->WillModifyTexture(); |
39 layer->SetTextureMailbox(cc::TextureMailbox()); | 41 layer->SetTextureMailbox(cc::TextureMailbox(), |
| 42 scoped_ptr<cc::ScopedReleaseCallback>()); |
40 } | 43 } |
41 | 44 |
42 void WebExternalTextureLayerImpl::setOpaque(bool opaque) { | 45 void WebExternalTextureLayerImpl::setOpaque(bool opaque) { |
43 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); | 46 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); |
44 } | 47 } |
45 | 48 |
46 void WebExternalTextureLayerImpl::setPremultipliedAlpha( | 49 void WebExternalTextureLayerImpl::setPremultipliedAlpha( |
47 bool premultiplied_alpha) { | 50 bool premultiplied_alpha) { |
48 static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha( | 51 static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha( |
49 premultiplied_alpha); | 52 premultiplied_alpha); |
(...skipping 12 matching lines...) Expand all Loading... |
62 return 0; | 65 return 0; |
63 } | 66 } |
64 | 67 |
65 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { | 68 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { |
66 DCHECK(client_); | 69 DCHECK(client_); |
67 return client_->context(); | 70 return client_->context(); |
68 } | 71 } |
69 | 72 |
70 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( | 73 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( |
71 cc::TextureMailbox* mailbox, | 74 cc::TextureMailbox* mailbox, |
| 75 scoped_ptr<cc::ScopedReleaseCallback>* release_callback, |
72 bool use_shared_memory) { | 76 bool use_shared_memory) { |
73 WebKit::WebExternalTextureMailbox client_mailbox; | 77 WebKit::WebExternalTextureMailbox client_mailbox; |
74 WebExternalBitmapImpl* bitmap = NULL; | 78 WebExternalBitmapImpl* bitmap = NULL; |
75 | 79 |
76 if (use_shared_memory) | 80 if (use_shared_memory) |
77 bitmap = AllocateBitmap(); | 81 bitmap = AllocateBitmap(); |
78 if (!client_->prepareMailbox(&client_mailbox, bitmap)) { | 82 if (!client_->prepareMailbox(&client_mailbox, bitmap)) { |
79 if (bitmap) | 83 if (bitmap) |
80 free_bitmaps_.push_back(bitmap); | 84 free_bitmaps_.push_back(bitmap); |
81 return false; | 85 return false; |
82 } | 86 } |
83 gpu::Mailbox name; | 87 gpu::Mailbox name; |
84 name.SetName(client_mailbox.name); | 88 name.SetName(client_mailbox.name); |
85 cc::TextureMailbox::ReleaseCallback callback = | 89 scoped_ptr<cc::ScopedReleaseCallback> callback = |
86 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, | 90 cc::ScopedReleaseCallback::Create(base::Bind( |
87 this->AsWeakPtr(), | 91 &WebExternalTextureLayerImpl::DidReleaseMailbox, |
88 client_mailbox, | 92 this->AsWeakPtr(), |
89 bitmap); | 93 client_mailbox, |
90 if (bitmap) { | 94 bitmap)); |
91 *mailbox = | 95 if (bitmap) |
92 cc::TextureMailbox(bitmap->shared_memory(), bitmap->size(), callback); | 96 *mailbox = cc::TextureMailbox(bitmap->shared_memory(), bitmap->size()); |
93 } else { | 97 else |
94 *mailbox = cc::TextureMailbox(name, callback, client_mailbox.syncPoint); | 98 *mailbox = cc::TextureMailbox(name, client_mailbox.syncPoint); |
95 } | 99 *release_callback = callback.Pass(); |
96 return true; | 100 return true; |
97 } | 101 } |
98 | 102 |
99 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { | 103 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { |
100 if (!free_bitmaps_.empty()) { | 104 if (!free_bitmaps_.empty()) { |
101 WebExternalBitmapImpl* result = free_bitmaps_.back(); | 105 WebExternalBitmapImpl* result = free_bitmaps_.back(); |
102 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); | 106 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); |
103 return result; | 107 return result; |
104 } | 108 } |
105 return new WebExternalBitmapImpl; | 109 return new WebExternalBitmapImpl; |
(...skipping 13 matching lines...) Expand all Loading... |
119 | 123 |
120 WebKit::WebExternalTextureMailbox available_mailbox; | 124 WebKit::WebExternalTextureMailbox available_mailbox; |
121 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); | 125 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); |
122 available_mailbox.syncPoint = sync_point; | 126 available_mailbox.syncPoint = sync_point; |
123 if (bitmap) | 127 if (bitmap) |
124 layer->free_bitmaps_.push_back(bitmap); | 128 layer->free_bitmaps_.push_back(bitmap); |
125 layer->client_->mailboxReleased(available_mailbox); | 129 layer->client_->mailboxReleased(available_mailbox); |
126 } | 130 } |
127 | 131 |
128 } // namespace webkit | 132 } // namespace webkit |
OLD | NEW |