OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "cc/blink/web_external_texture_layer_impl.h" | |
6 | |
7 #include "cc/blink/web_external_bitmap_impl.h" | |
8 #include "cc/blink/web_layer_impl.h" | |
9 #include "cc/layers/texture_layer.h" | |
10 #include "cc/resources/resource_update_queue.h" | |
11 #include "cc/resources/single_release_callback.h" | |
12 #include "cc/resources/texture_mailbox.h" | |
13 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h" | |
14 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h" | |
15 #include "third_party/WebKit/public/platform/WebFloatRect.h" | |
16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | |
17 #include "third_party/WebKit/public/platform/WebSize.h" | |
18 #include "third_party/khronos/GLES2/gl2.h" | |
19 | |
20 using cc::TextureLayer; | |
21 using cc::ResourceUpdateQueue; | |
22 | |
23 namespace cc_blink { | |
24 | |
25 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( | |
26 blink::WebExternalTextureLayerClient* client) | |
27 : client_(client) { | |
28 cc::TextureLayerClient* cc_client = client_ ? this : nullptr; | |
29 scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(cc_client); | |
30 layer->SetIsDrawable(true); | |
31 layer_.reset(new WebLayerImpl(layer)); | |
32 } | |
33 | |
34 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { | |
35 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); | |
36 } | |
37 | |
38 blink::WebLayer* WebExternalTextureLayerImpl::layer() { | |
39 return layer_.get(); | |
40 } | |
41 | |
42 void WebExternalTextureLayerImpl::clearTexture() { | |
43 TextureLayer* layer = static_cast<TextureLayer*>(layer_->layer()); | |
44 layer->ClearTexture(); | |
45 } | |
46 | |
47 void WebExternalTextureLayerImpl::setOpaque(bool opaque) { | |
48 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque); | |
49 } | |
50 | |
51 void WebExternalTextureLayerImpl::setPremultipliedAlpha( | |
52 bool premultiplied_alpha) { | |
53 static_cast<TextureLayer*>(layer_->layer()) | |
54 ->SetPremultipliedAlpha(premultiplied_alpha); | |
55 } | |
56 | |
57 void WebExternalTextureLayerImpl::setBlendBackgroundColor(bool blend) { | |
58 static_cast<TextureLayer*>(layer_->layer())->SetBlendBackgroundColor(blend); | |
59 } | |
60 | |
61 void WebExternalTextureLayerImpl::setRateLimitContext(bool rate_limit) { | |
62 static_cast<TextureLayer*>(layer_->layer())->SetRateLimitContext(rate_limit); | |
63 } | |
64 | |
65 void WebExternalTextureLayerImpl::setNearestNeighbor(bool nearest_neighbor) { | |
66 static_cast<TextureLayer*>(layer_->layer()) | |
67 ->SetNearestNeighbor(nearest_neighbor); | |
68 } | |
69 | |
70 bool WebExternalTextureLayerImpl::PrepareTextureMailbox( | |
71 cc::TextureMailbox* mailbox, | |
72 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | |
73 bool use_shared_memory) { | |
74 blink::WebExternalTextureMailbox client_mailbox; | |
75 WebExternalBitmapImpl* bitmap = nullptr; | |
76 | |
77 if (use_shared_memory) | |
78 bitmap = AllocateBitmap(); | |
79 if (!client_->prepareMailbox(&client_mailbox, bitmap)) { | |
80 if (bitmap) | |
81 free_bitmaps_.push_back(bitmap); | |
82 return false; | |
83 } | |
84 gpu::Mailbox name; | |
85 name.SetName(client_mailbox.name); | |
86 if (bitmap) { | |
87 *mailbox = cc::TextureMailbox(bitmap->shared_bitmap(), bitmap->size()); | |
88 } else { | |
89 *mailbox = | |
90 cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint); | |
91 } | |
92 mailbox->set_allow_overlay(client_mailbox.allowOverlay); | |
93 mailbox->set_nearest_neighbor(client_mailbox.nearestNeighbor); | |
94 | |
95 if (mailbox->IsValid()) { | |
96 *release_callback = cc::SingleReleaseCallback::Create( | |
97 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, | |
98 this->AsWeakPtr(), | |
99 client_mailbox, | |
100 bitmap)); | |
101 } | |
102 | |
103 return true; | |
104 } | |
105 | |
106 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() { | |
107 if (!free_bitmaps_.empty()) { | |
108 WebExternalBitmapImpl* result = free_bitmaps_.back(); | |
109 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1); | |
110 return result; | |
111 } | |
112 return new WebExternalBitmapImpl; | |
113 } | |
114 | |
115 // static | |
116 void WebExternalTextureLayerImpl::DidReleaseMailbox( | |
117 base::WeakPtr<WebExternalTextureLayerImpl> layer, | |
118 const blink::WebExternalTextureMailbox& mailbox, | |
119 WebExternalBitmapImpl* bitmap, | |
120 unsigned sync_point, | |
121 bool lost_resource) { | |
122 DCHECK(layer); | |
123 blink::WebExternalTextureMailbox available_mailbox; | |
124 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); | |
125 available_mailbox.syncPoint = sync_point; | |
126 if (bitmap) | |
127 layer->free_bitmaps_.push_back(bitmap); | |
128 layer->client_->mailboxReleased(available_mailbox, lost_resource); | |
129 } | |
130 | |
131 } // namespace cc_blink | |
OLD | NEW |