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 "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" | 9 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" |
10 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" | 10 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" |
11 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 11 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
12 #include "third_party/WebKit/public/platform/WebSize.h" | 12 #include "third_party/WebKit/public/platform/WebSize.h" |
13 #include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h" | |
13 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | 14 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" |
14 | 15 |
15 using cc::TextureLayer; | 16 using cc::TextureLayer; |
16 using cc::ResourceUpdateQueue; | 17 using cc::ResourceUpdateQueue; |
17 | 18 |
18 namespace webkit { | 19 namespace webkit { |
19 | 20 |
20 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( | 21 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( |
21 WebKit::WebExternalTextureLayerClient* client, | 22 WebKit::WebExternalTextureLayerClient* client, |
22 bool mailbox) | 23 bool mailbox) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 } | 104 } |
104 | 105 |
105 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { | 106 WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { |
106 DCHECK(client_); | 107 DCHECK(client_); |
107 return client_->context(); | 108 return client_->context(); |
108 } | 109 } |
109 | 110 |
110 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( | 111 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( |
111 cc::TextureMailbox* mailbox) { | 112 cc::TextureMailbox* mailbox) { |
112 WebKit::WebExternalTextureMailbox client_mailbox; | 113 WebKit::WebExternalTextureMailbox client_mailbox; |
113 if (!client_->prepareMailbox(&client_mailbox)) { | 114 WebExternalBitmapImpl* bitmap = NULL; |
115 | |
116 if (static_cast<TextureLayer*>(layer_->layer())->MustUseSharedMemory()) | |
117 bitmap = AllocateBitmap(); | |
118 if (!client_->prepareMailbox(&client_mailbox, bitmap)) { | |
114 return false; | 119 return false; |
115 } | 120 } |
116 gpu::Mailbox name; | 121 gpu::Mailbox name; |
117 name.SetName(client_mailbox.name); | 122 name.SetName(client_mailbox.name); |
118 cc::TextureMailbox::ReleaseCallback callback = | 123 cc::TextureMailbox::ReleaseCallback callback = |
119 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, | 124 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, |
120 this->AsWeakPtr(), | 125 this->AsWeakPtr(), |
121 client_mailbox); | 126 client_mailbox, |
122 *mailbox = cc::TextureMailbox(name, callback, client_mailbox.syncPoint); | 127 bitmap); |
128 if (bitmap) | |
piman
2013/07/01 22:45:01
nit: needs braces
| |
129 *mailbox = cc::TextureMailbox( | |
130 bitmap->getSharedMemory(), bitmap->getSize(), callback); | |
131 else | |
132 *mailbox = cc::TextureMailbox(name, callback, client_mailbox.syncPoint); | |
123 return true; | 133 return true; |
124 } | 134 } |
125 | 135 |
136 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { | |
137 if (!free_bitmaps_.empty()) { | |
138 WebExternalBitmapImpl* result = free_bitmaps_.back(); | |
139 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); | |
140 return result; | |
141 } | |
142 return new WebExternalBitmapImpl; | |
143 } | |
144 | |
145 // static | |
126 void WebExternalTextureLayerImpl::DidReleaseMailbox( | 146 void WebExternalTextureLayerImpl::DidReleaseMailbox( |
147 base::WeakPtr<WebExternalTextureLayerImpl> layer, | |
127 const WebKit::WebExternalTextureMailbox& mailbox, | 148 const WebKit::WebExternalTextureMailbox& mailbox, |
149 WebExternalBitmapImpl* bitmap, | |
128 unsigned sync_point, | 150 unsigned sync_point, |
129 bool lost_resource) { | 151 bool lost_resource) { |
130 if (lost_resource) | 152 if (lost_resource || !layer) { |
153 delete bitmap; | |
131 return; | 154 return; |
155 } | |
132 | 156 |
133 WebKit::WebExternalTextureMailbox available_mailbox; | 157 WebKit::WebExternalTextureMailbox available_mailbox; |
134 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); | 158 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); |
135 available_mailbox.syncPoint = sync_point; | 159 available_mailbox.syncPoint = sync_point; |
136 client_->mailboxReleased(available_mailbox); | 160 if (bitmap) |
161 layer->free_bitmaps_.push_back(bitmap); | |
162 layer->client_->mailboxReleased(available_mailbox); | |
137 } | 163 } |
138 | 164 |
139 } // namespace webkit | 165 } // namespace webkit |
OLD | NEW |