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

Side by Side Diff: cc/texture_layer_impl.cc

Issue 11638028: Mailbox support for texture layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « cc/texture_layer_impl.h ('k') | cc/texture_layer_unittest.cc » ('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 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 "cc/texture_layer_impl.h" 5 #include "cc/texture_layer_impl.h"
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "cc/layer_tree_impl.h"
8 #include "cc/quad_sink.h" 9 #include "cc/quad_sink.h"
9 #include "cc/renderer.h" 10 #include "cc/renderer.h"
10 #include "cc/texture_draw_quad.h" 11 #include "cc/texture_draw_quad.h"
11 12
12 namespace cc { 13 namespace cc {
13 14
14 TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* treeImpl, int id) 15 TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* treeImpl, int id, bool usesMai lbox)
15 : LayerImpl(treeImpl, id) 16 : LayerImpl(treeImpl, id)
16 , m_textureId(0) 17 , m_textureId(0)
17 , m_externalTextureResource(0) 18 , m_externalTextureResource(0)
18 , m_premultipliedAlpha(true) 19 , m_premultipliedAlpha(true)
19 , m_flipped(true) 20 , m_flipped(true)
20 , m_uvRect(0, 0, 1, 1) 21 , m_uvRect(0, 0, 1, 1)
22 , m_hasPendingMailbox(false)
23 , m_usesMailbox(usesMailbox)
21 { 24 {
22 m_vertexOpacity[0] = 1.0f; 25 m_vertexOpacity[0] = 1.0f;
23 m_vertexOpacity[1] = 1.0f; 26 m_vertexOpacity[1] = 1.0f;
24 m_vertexOpacity[2] = 1.0f; 27 m_vertexOpacity[2] = 1.0f;
25 m_vertexOpacity[3] = 1.0f; 28 m_vertexOpacity[3] = 1.0f;
26 } 29 }
27 30
28 TextureLayerImpl::~TextureLayerImpl() 31 TextureLayerImpl::~TextureLayerImpl()
29 { 32 {
33 if (m_externalTextureResource) {
34 DCHECK(m_usesMailbox);
35 ResourceProvider* provider = layerTreeImpl()->resource_provider();
36 provider->deleteResource(m_externalTextureResource);
37 }
38 if (m_hasPendingMailbox && !m_pendingMailboxName.empty())
39 m_pendingMailboxReleaseCallback.Run(0);
40 }
41
42 void TextureLayerImpl::setTextureMailbox(const std::string& mailboxName, const b ase::Callback<void(unsigned)>& releaseCallback)
43 {
44 DCHECK(m_usesMailbox);
45 // Same mailbox name was commited, nothing to do.
46 if (m_pendingMailboxName.compare(mailboxName) == 0)
47 return;
48 // Two commits without a draw, ack the previous mailbox.
49 if (m_hasPendingMailbox && !m_pendingMailboxReleaseCallback.is_null())
50 m_pendingMailboxReleaseCallback.Run(0);
51
52 m_pendingMailboxName = mailboxName;
53 m_hasPendingMailbox = true;
54 m_pendingMailboxReleaseCallback = releaseCallback;
30 } 55 }
31 56
32 void TextureLayerImpl::willDraw(ResourceProvider* resourceProvider) 57 void TextureLayerImpl::willDraw(ResourceProvider* resourceProvider)
33 { 58 {
34 if (!m_textureId) 59 if (!m_usesMailbox) {
60 if (!m_textureId)
61 return;
62 DCHECK(!m_externalTextureResource);
63 m_externalTextureResource = resourceProvider->createResourceFromExternal Texture(m_textureId);
35 return; 64 return;
36 DCHECK(!m_externalTextureResource); 65 }
37 m_externalTextureResource = resourceProvider->createResourceFromExternalText ure(m_textureId); 66
67 if (!m_hasPendingMailbox)
68 return;
69
70 if (m_externalTextureResource) {
71 resourceProvider->deleteResource(m_externalTextureResource);
72 m_externalTextureResource = 0;
73 }
74 if (!m_pendingMailboxName.empty())
75 m_externalTextureResource = resourceProvider->createResourceFromTextureM ailbox(m_pendingMailboxName, m_pendingMailboxReleaseCallback);
76 m_hasPendingMailbox = false;
38 } 77 }
39 78
40 void TextureLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQu adsData) 79 void TextureLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQu adsData)
41 { 80 {
42 if (!m_externalTextureResource) 81 if (!m_externalTextureResource)
43 return; 82 return;
44 83
45 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState()); 84 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState());
46 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); 85 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
47 86
48 gfx::Rect quadRect(gfx::Point(), contentBounds()); 87 gfx::Rect quadRect(gfx::Point(), contentBounds());
49 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect()); 88 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
50 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); 89 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
51 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResourc e, m_premultipliedAlpha, m_uvRect, m_vertexOpacity, m_flipped); 90 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResourc e, m_premultipliedAlpha, m_uvRect, m_vertexOpacity, m_flipped);
52 91
53 // Perform explicit clipping on a quad to avoid setting a scissor later. 92 // Perform explicit clipping on a quad to avoid setting a scissor later.
54 if (sharedQuadState->is_clipped && quad->PerformClipping()) 93 if (sharedQuadState->is_clipped && quad->PerformClipping())
55 sharedQuadState->is_clipped = false; 94 sharedQuadState->is_clipped = false;
56 if (!quad->rect.IsEmpty()) 95 if (!quad->rect.IsEmpty())
57 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); 96 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
58 } 97 }
59 98
60 void TextureLayerImpl::didDraw(ResourceProvider* resourceProvider) 99 void TextureLayerImpl::didDraw(ResourceProvider* resourceProvider)
61 { 100 {
101 if (m_usesMailbox)
102 return;
62 if (!m_externalTextureResource) 103 if (!m_externalTextureResource)
63 return; 104 return;
64 // FIXME: the following assert will not be true when sending resources to a 105 // FIXME: the following assert will not be true when sending resources to a
65 // parent compositor. A synchronization scheme (double-buffering or 106 // parent compositor. A synchronization scheme (double-buffering or
66 // pipelining of updates) for the client will need to exist to solve this. 107 // pipelining of updates) for the client will need to exist to solve this.
67 DCHECK(!resourceProvider->inUseByConsumer(m_externalTextureResource)); 108 DCHECK(!resourceProvider->inUseByConsumer(m_externalTextureResource));
68 resourceProvider->deleteResource(m_externalTextureResource); 109 resourceProvider->deleteResource(m_externalTextureResource);
69 m_externalTextureResource = 0; 110 m_externalTextureResource = 0;
70 } 111 }
71 112
(...skipping 16 matching lines...) Expand all
88 m_textureId = 0; 129 m_textureId = 0;
89 m_externalTextureResource = 0; 130 m_externalTextureResource = 0;
90 } 131 }
91 132
92 const char* TextureLayerImpl::layerTypeAsString() const 133 const char* TextureLayerImpl::layerTypeAsString() const
93 { 134 {
94 return "TextureLayer"; 135 return "TextureLayer";
95 } 136 }
96 137
97 } // namespace cc 138 } // namespace cc
OLDNEW
« no previous file with comments | « cc/texture_layer_impl.h ('k') | cc/texture_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698