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(), cc::ScopedReleaseCallback()); |
40 } | 42 } |
41 | 43 |
42 void WebExternalTextureLayerImpl::setOpaque(bool opaque) { | 44 void WebExternalTextureLayerImpl::setOpaque(bool opaque) { |
43 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); | 45 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); |
44 } | 46 } |
45 | 47 |
46 void WebExternalTextureLayerImpl::setPremultipliedAlpha( | 48 void WebExternalTextureLayerImpl::setPremultipliedAlpha( |
47 bool premultiplied_alpha) { | 49 bool premultiplied_alpha) { |
48 static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha( | 50 static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha( |
49 premultiplied_alpha); | 51 premultiplied_alpha); |
(...skipping 12 matching lines...) Expand all Loading... |
62 return 0; | 64 return 0; |
63 } | 65 } |
64 | 66 |
65 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { | 67 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { |
66 DCHECK(client_); | 68 DCHECK(client_); |
67 return client_->context(); | 69 return client_->context(); |
68 } | 70 } |
69 | 71 |
70 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( | 72 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( |
71 cc::TextureMailbox* mailbox, | 73 cc::TextureMailbox* mailbox, |
| 74 cc::ScopedReleaseCallback* release_callback, |
72 bool use_shared_memory) { | 75 bool use_shared_memory) { |
73 WebKit::WebExternalTextureMailbox client_mailbox; | 76 WebKit::WebExternalTextureMailbox client_mailbox; |
74 WebExternalBitmapImpl* bitmap = NULL; | 77 WebExternalBitmapImpl* bitmap = NULL; |
75 | 78 |
76 if (use_shared_memory) | 79 if (use_shared_memory) |
77 bitmap = AllocateBitmap(); | 80 bitmap = AllocateBitmap(); |
78 if (!client_->prepareMailbox(&client_mailbox, bitmap)) { | 81 if (!client_->prepareMailbox(&client_mailbox, bitmap)) { |
79 if (bitmap) | 82 if (bitmap) |
80 free_bitmaps_.push_back(bitmap); | 83 free_bitmaps_.push_back(bitmap); |
81 return false; | 84 return false; |
82 } | 85 } |
83 gpu::Mailbox name; | 86 gpu::Mailbox name; |
84 name.SetName(client_mailbox.name); | 87 name.SetName(client_mailbox.name); |
85 cc::TextureMailbox::ReleaseCallback callback = | 88 cc::ScopedReleaseCallback callback( |
86 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, | 89 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, |
87 this->AsWeakPtr(), | 90 this->AsWeakPtr(), |
88 client_mailbox, | 91 client_mailbox, |
89 bitmap); | 92 bitmap)); |
90 if (bitmap) { | 93 if (bitmap) |
91 *mailbox = | 94 *mailbox = cc::TextureMailbox(bitmap->shared_memory(), bitmap->size()); |
92 cc::TextureMailbox(bitmap->shared_memory(), bitmap->size(), callback); | 95 else |
93 } else { | 96 *mailbox = cc::TextureMailbox(name, client_mailbox.syncPoint); |
94 *mailbox = cc::TextureMailbox(name, callback, client_mailbox.syncPoint); | 97 *release_callback = callback.Pass(); |
95 } | |
96 return true; | 98 return true; |
97 } | 99 } |
98 | 100 |
99 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { | 101 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { |
100 if (!free_bitmaps_.empty()) { | 102 if (!free_bitmaps_.empty()) { |
101 WebExternalBitmapImpl* result = free_bitmaps_.back(); | 103 WebExternalBitmapImpl* result = free_bitmaps_.back(); |
102 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); | 104 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); |
103 return result; | 105 return result; |
104 } | 106 } |
105 return new WebExternalBitmapImpl; | 107 return new WebExternalBitmapImpl; |
(...skipping 13 matching lines...) Expand all Loading... |
119 | 121 |
120 WebKit::WebExternalTextureMailbox available_mailbox; | 122 WebKit::WebExternalTextureMailbox available_mailbox; |
121 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); | 123 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); |
122 available_mailbox.syncPoint = sync_point; | 124 available_mailbox.syncPoint = sync_point; |
123 if (bitmap) | 125 if (bitmap) |
124 layer->free_bitmaps_.push_back(bitmap); | 126 layer->free_bitmaps_.push_back(bitmap); |
125 layer->client_->mailboxReleased(available_mailbox); | 127 layer->client_->mailboxReleased(available_mailbox); |
126 } | 128 } |
127 | 129 |
128 } // namespace webkit | 130 } // namespace webkit |
OLD | NEW |