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

Side by Side Diff: webkit/renderer/compositor_bindings/web_external_texture_layer_impl.cc

Issue 317163002: Moving compositor_bindings from webkit to content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing dependencies due to failing ios bots Created 6 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/renderer/compositor_bindings/web_external_texture_layer_impl.h"
6
7 #include "cc/layers/texture_layer.h"
8 #include "cc/resources/resource_update_queue.h"
9 #include "cc/resources/single_release_callback.h"
10 #include "cc/resources/texture_mailbox.h"
11 #include "third_party/WebKit/public/platform/WebExternalTextureLayerClient.h"
12 #include "third_party/WebKit/public/platform/WebExternalTextureMailbox.h"
13 #include "third_party/WebKit/public/platform/WebFloatRect.h"
14 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
15 #include "third_party/WebKit/public/platform/WebSize.h"
16 #include "third_party/khronos/GLES2/gl2.h"
17 #include "webkit/renderer/compositor_bindings/web_external_bitmap_impl.h"
18 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
19
20 using cc::TextureLayer;
21 using cc::ResourceUpdateQueue;
22
23 namespace webkit {
24
25 WebExternalTextureLayerImpl::WebExternalTextureLayerImpl(
26 blink::WebExternalTextureLayerClient* client)
27 : client_(client) {
28 cc::TextureLayerClient* cc_client = client_ ? this : NULL;
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() { return layer_.get(); }
39
40 void WebExternalTextureLayerImpl::clearTexture() {
41 TextureLayer *layer = static_cast<TextureLayer*>(layer_->layer());
42 layer->ClearTexture();
43 }
44
45 void WebExternalTextureLayerImpl::setOpaque(bool opaque) {
46 static_cast<TextureLayer*>(layer_->layer())->SetContentsOpaque(opaque);
47 }
48
49 void WebExternalTextureLayerImpl::setPremultipliedAlpha(
50 bool premultiplied_alpha) {
51 static_cast<TextureLayer*>(layer_->layer())->SetPremultipliedAlpha(
52 premultiplied_alpha);
53 }
54
55 void WebExternalTextureLayerImpl::setBlendBackgroundColor(bool blend) {
56 static_cast<TextureLayer*>(layer_->layer())->SetBlendBackgroundColor(blend);
57 }
58
59 void WebExternalTextureLayerImpl::setRateLimitContext(bool rate_limit) {
60 static_cast<TextureLayer*>(layer_->layer())->SetRateLimitContext(rate_limit);
61 }
62
63 bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
64 cc::TextureMailbox* mailbox,
65 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
66 bool use_shared_memory) {
67 blink::WebExternalTextureMailbox client_mailbox;
68 WebExternalBitmapImpl* bitmap = NULL;
69
70 if (use_shared_memory)
71 bitmap = AllocateBitmap();
72 if (!client_->prepareMailbox(&client_mailbox, bitmap)) {
73 if (bitmap)
74 free_bitmaps_.push_back(bitmap);
75 return false;
76 }
77 gpu::Mailbox name;
78 name.SetName(client_mailbox.name);
79 if (bitmap) {
80 *mailbox = cc::TextureMailbox(bitmap->shared_memory(), bitmap->size());
81 } else {
82 *mailbox =
83 cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint);
84 }
85 mailbox->set_allow_overlay(client_mailbox.allowOverlay);
86
87 if (mailbox->IsValid()) {
88 *release_callback = cc::SingleReleaseCallback::Create(base::Bind(
89 &WebExternalTextureLayerImpl::DidReleaseMailbox,
90 this->AsWeakPtr(),
91 client_mailbox,
92 bitmap));
93 }
94
95 return true;
96 }
97
98 WebExternalBitmapImpl* WebExternalTextureLayerImpl::AllocateBitmap() {
99 if (!free_bitmaps_.empty()) {
100 WebExternalBitmapImpl* result = free_bitmaps_.back();
101 free_bitmaps_.weak_erase(free_bitmaps_.end() - 1);
102 return result;
103 }
104 return new WebExternalBitmapImpl;
105 }
106
107 // static
108 void WebExternalTextureLayerImpl::DidReleaseMailbox(
109 base::WeakPtr<WebExternalTextureLayerImpl> layer,
110 const blink::WebExternalTextureMailbox& mailbox,
111 WebExternalBitmapImpl* bitmap,
112 unsigned sync_point,
113 bool lost_resource) {
114 if (lost_resource || !layer) {
115 delete bitmap;
116 return;
117 }
118
119 blink::WebExternalTextureMailbox available_mailbox;
120 memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name));
121 available_mailbox.syncPoint = sync_point;
122 if (bitmap)
123 layer->free_bitmaps_.push_back(bitmap);
124 layer->client_->mailboxReleased(available_mailbox);
125 }
126
127 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698