Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: cc/blink/web_external_texture_layer_impl.cc

Issue 2261623002: Make DrawingBuffer and Canvas2DLayerBridge be cc::TextureLayerClients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webmailbox: fix-passrefptr Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/blink/web_external_texture_layer_impl.h ('k') | components/test_runner/test_plugin.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "cc/blink/web_external_texture_layer_impl.h" 5 #include "cc/blink/web_external_texture_layer_impl.h"
6 6
7 #include "base/memory/ptr_util.h"
8 #include "cc/blink/web_external_bitmap_impl.h"
9 #include "cc/blink/web_layer_impl.h" 7 #include "cc/blink/web_layer_impl.h"
10 #include "cc/layers/texture_layer.h" 8 #include "cc/layers/texture_layer.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/WebSize.h"
17 #include "third_party/khronos/GLES2/gl2.h"
18 9
19 using cc::TextureLayer; 10 using cc::TextureLayer;
20 11
21 namespace cc_blink { 12 namespace cc_blink {
22 13
23 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( 14 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl(
24 blink::WebExternalTextureLayerClient* client) 15 cc::TextureLayerClient* client) {
25 : client_(client) { 16 scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(client);
26 cc::TextureLayerClient* cc_client = client_ ? this : nullptr;
27 scoped_refptr<TextureLayer> layer = TextureLayer::CreateForMailbox(cc_client);
28 layer->SetIsDrawable(true); 17 layer->SetIsDrawable(true);
29 layer_.reset(new WebLayerImpl(layer)); 18 layer_.reset(new WebLayerImpl(layer));
30 } 19 }
31 20
32 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { 21 WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() {
33 static_cast<TextureLayer*>(layer_->layer())->ClearClient(); 22 static_cast<TextureLayer*>(layer_->layer())->ClearClient();
34 } 23 }
35 24
36 blink::WebLayer* WebExternalTextureLayerImpl::layer() { 25 blink::WebLayer* WebExternalTextureLayerImpl::layer() {
37 return layer_.get(); 26 return layer_.get();
(...skipping 16 matching lines...) Expand all
54 43
55 void WebExternalTextureLayerImpl::setBlendBackgroundColor(bool blend) { 44 void WebExternalTextureLayerImpl::setBlendBackgroundColor(bool blend) {
56 static_cast<TextureLayer*>(layer_->layer())->SetBlendBackgroundColor(blend); 45 static_cast<TextureLayer*>(layer_->layer())->SetBlendBackgroundColor(blend);
57 } 46 }
58 47
59 void WebExternalTextureLayerImpl::setNearestNeighbor(bool nearest_neighbor) { 48 void WebExternalTextureLayerImpl::setNearestNeighbor(bool nearest_neighbor) {
60 static_cast<TextureLayer*>(layer_->layer()) 49 static_cast<TextureLayer*>(layer_->layer())
61 ->SetNearestNeighbor(nearest_neighbor); 50 ->SetNearestNeighbor(nearest_neighbor);
62 } 51 }
63 52
64 bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
65 cc::TextureMailbox* mailbox,
66 std::unique_ptr<cc::SingleReleaseCallback>* release_callback,
67 bool use_shared_memory) {
68 blink::WebExternalTextureMailbox client_mailbox;
69 WebExternalBitmapImpl* bitmap = nullptr;
70
71 if (use_shared_memory)
72 bitmap = AllocateBitmap();
73 if (!client_->prepareMailbox(&client_mailbox, bitmap)) {
74 if (bitmap)
75 free_bitmaps_.push_back(base::WrapUnique(bitmap));
76 return false;
77 }
78 gpu::Mailbox name;
79 name.SetName(client_mailbox.name);
80 if (bitmap) {
81 *mailbox = cc::TextureMailbox(bitmap->shared_bitmap(), bitmap->size());
82 } else {
83 gpu::SyncToken sync_token;
84 static_assert(sizeof(sync_token) <= sizeof(client_mailbox.syncToken),
85 "Size of web external sync token too small.");
86 if (client_mailbox.validSyncToken)
87 memcpy(&sync_token, client_mailbox.syncToken, sizeof(sync_token));
88
89 gfx::Size size;
90 if (client_mailbox.allowOverlay) {
91 size = gfx::Size(client_mailbox.textureSize.width,
92 client_mailbox.textureSize.height);
93 }
94
95 *mailbox = cc::TextureMailbox(
96 name, sync_token, client_mailbox.textureTarget, size,
97 client_mailbox.allowOverlay, false);
98 }
99 mailbox->set_nearest_neighbor(client_mailbox.nearestNeighbor);
100
101 if (mailbox->IsValid()) {
102 *release_callback = cc::SingleReleaseCallback::Create(
103 base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox,
104 this->AsWeakPtr(),
105 client_mailbox,
106 bitmap));
107 }
108
109 return true;
110 }
111
112 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() {
113 if (!free_bitmaps_.empty()) {
114 WebExternalBitmapImpl* result = free_bitmaps_.back().release();
115 free_bitmaps_.pop_back();
116 return result;
117 }
118 return new WebExternalBitmapImpl;
119 }
120
121 // static
122 void WebExternalTextureLayerImpl::DidReleaseMailbox(
123 base::WeakPtr<WebExternalTextureLayerImpl> layer,
124 const blink::WebExternalTextureMailbox& mailbox,
125 WebExternalBitmapImpl* bitmap,
126 const gpu::SyncToken& sync_token,
127 bool lost_resource) {
128 DCHECK(layer);
129 blink::WebExternalTextureMailbox available_mailbox;
130 static_assert(sizeof(sync_token) <= sizeof(available_mailbox.syncToken),
131 "Size of web external sync token too small.");
132 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name));
133 memcpy(available_mailbox.syncToken, sync_token.GetConstData(),
134 sizeof(sync_token));
135 available_mailbox.validSyncToken = sync_token.HasData();
136 if (bitmap)
137 layer->free_bitmaps_.push_back(base::WrapUnique(bitmap));
138 layer->client_->mailboxReleased(available_mailbox, lost_resource);
139 }
140
141 } // namespace cc_blink 53 } // namespace cc_blink
OLDNEW
« no previous file with comments | « cc/blink/web_external_texture_layer_impl.h ('k') | components/test_runner/test_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698