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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp

Issue 2165913003: Invalidate m_image after GPU-GPU texture copy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 3 formats still fails on windows Created 4 years, 5 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 | « third_party/WebKit/Source/platform/graphics/StaticBitmapImage.h ('k') | no next file » | 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 "platform/graphics/StaticBitmapImage.h" 5 #include "platform/graphics/StaticBitmapImage.h"
6 6
7 #include "gpu/command_buffer/client/gles2_interface.h" 7 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "platform/graphics/GraphicsContext.h" 8 #include "platform/graphics/GraphicsContext.h"
9 #include "platform/graphics/ImageObserver.h" 9 #include "platform/graphics/ImageObserver.h"
10 #include "public/platform/Platform.h" 10 #include "public/platform/Platform.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 backendTexture.fHeight = m_mailbox.textureSize.height; 97 backendTexture.fHeight = m_mailbox.textureSize.height;
98 backendTexture.fConfig = kSkia8888_GrPixelConfig; 98 backendTexture.fConfig = kSkia8888_GrPixelConfig;
99 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu reInfo); 99 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu reInfo);
100 sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendT exture); 100 sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendT exture);
101 m_image = fromSkSp(skImage); 101 m_image = fromSkSp(skImage);
102 return textureId; 102 return textureId;
103 } 103 }
104 104
105 void StaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* provider, GL uint destinationTexture, GLenum internalFormat, GLenum destType, bool flipY) 105 void StaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* provider, GL uint destinationTexture, GLenum internalFormat, GLenum destType, bool flipY)
106 { 106 {
107 GLuint textureId = textureIdForWebGL(provider); 107 GLuint textureId = switchStorageToSkImageForWebGL(provider);
108 gpu::gles2::GLES2Interface* gl = provider->contextGL(); 108 gpu::gles2::GLES2Interface* gl = provider->contextGL();
109 if (!gl) 109 if (!gl)
110 return; 110 return;
111 gl->CopyTextureCHROMIUM(textureId, destinationTexture, internalFormat, destT ype, flipY, false, false); 111 gl->CopyTextureCHROMIUM(textureId, destinationTexture, internalFormat, destT ype, flipY, false, false);
112 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); 112 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM();
113 gl->Flush(); 113 gl->Flush();
114 GLbyte syncToken[24]; 114 GLbyte syncToken[24];
115 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken); 115 gl->GenSyncTokenCHROMIUM(fenceSync, syncToken);
116 // Get a new mailbox because we cannot retain a texture in the WebGL context .
117 switchStorageToMailbox(provider);
116 } 118 }
117 119
118 bool StaticBitmapImage::switchStorageToMailbox(WebGraphicsContext3DProvider* pro vider) 120 bool StaticBitmapImage::switchStorageToMailbox(WebGraphicsContext3DProvider* pro vider)
119 { 121 {
120 m_mailbox.textureSize = WebSize(m_image->width(), m_image->height()); 122 m_mailbox.textureSize = WebSize(m_image->width(), m_image->height());
121 GrContext* grContext = provider->grContext(); 123 GrContext* grContext = provider->grContext();
122 if (!grContext) 124 if (!grContext)
123 return false; 125 return false;
124 grContext->flush(); 126 grContext->flush();
125 m_mailbox.textureTarget = GL_TEXTURE_2D; 127 m_mailbox.textureTarget = GL_TEXTURE_2D;
126 gpu::gles2::GLES2Interface* gl = provider->contextGL(); 128 gpu::gles2::GLES2Interface* gl = provider->contextGL();
127 if (!gl) 129 if (!gl)
128 return false; 130 return false;
129 GLuint textureID = skia::GrBackendObjectToGrGLTextureInfo(m_image->getTextur eHandle(true))->fID; 131 GLuint textureID = skia::GrBackendObjectToGrGLTextureInfo(m_image->getTextur eHandle(true))->fID;
130 gl->BindTexture(GL_TEXTURE_2D, textureID); 132 gl->BindTexture(GL_TEXTURE_2D, textureID);
131 133
132 gl->GenMailboxCHROMIUM(m_mailbox.name); 134 gl->GenMailboxCHROMIUM(m_mailbox.name);
133 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name); 135 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name);
134 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM(); 136 const GLuint64 fenceSync = gl->InsertFenceSyncCHROMIUM();
135 gl->Flush(); 137 gl->Flush();
136 gl->GenSyncTokenCHROMIUM(fenceSync, m_mailbox.syncToken); 138 gl->GenSyncTokenCHROMIUM(fenceSync, m_mailbox.syncToken);
137 m_mailbox.validSyncToken = true; 139 m_mailbox.validSyncToken = true;
138 gl->BindTexture(GL_TEXTURE_2D, 0); 140 gl->BindTexture(GL_TEXTURE_2D, 0);
139 grContext->resetContext(kTextureBinding_GrGLBackendState); 141 grContext->resetContext(kTextureBinding_GrGLBackendState);
142 m_image = nullptr;
140 return true; 143 return true;
141 } 144 }
142 145
143 // This function is called only in the case that m_image is texture backed. 146 // This function is called only in the case that m_image is texture backed.
144 GLuint StaticBitmapImage::textureIdForWebGL(WebGraphicsContext3DProvider* contex tProvider) 147 GLuint StaticBitmapImage::switchStorageToSkImageForWebGL(WebGraphicsContext3DPro vider* contextProvider)
145 { 148 {
146 DCHECK(!m_image || m_image->isTextureBacked()); 149 DCHECK(!m_image || m_image->isTextureBacked());
147 GLuint textureId = 0; 150 GLuint textureId = 0;
148 if (m_image) { 151 if (m_image) {
149 // SkImage is texture-backed on the shared context 152 // SkImage is texture-backed on the shared context
150 if (!hasMailbox()) { 153 if (!hasMailbox()) {
151 std::unique_ptr<WebGraphicsContext3DProvider> sharedProvider = wrapU nique(Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); 154 std::unique_ptr<WebGraphicsContext3DProvider> sharedProvider = wrapU nique(Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
152 if (!switchStorageToMailbox(sharedProvider.get())) 155 if (!switchStorageToMailbox(sharedProvider.get()))
153 return 0; 156 return 0;
154 textureId = switchStorageToSkImage(contextProvider); 157 textureId = switchStorageToSkImage(contextProvider);
155 // Get a new mailbox because we cannot retain a texture in the WebGL context.
156 if (!switchStorageToMailbox(contextProvider))
157 return 0;
158 return textureId; 158 return textureId;
159 } 159 }
160 } 160 }
161 DCHECK(hasMailbox()); 161 DCHECK(hasMailbox());
162 textureId = switchStorageToSkImage(contextProvider); 162 textureId = switchStorageToSkImage(contextProvider);
163 if (!switchStorageToMailbox(contextProvider))
164 return 0;
165 return textureId; 163 return textureId;
166 } 164 }
167 165
168 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() 166 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame()
169 { 167 {
170 if (m_image) 168 if (m_image)
171 return m_image; 169 return m_image;
172 // No mailbox, return null; 170 // No mailbox, return null;
173 if (!hasMailbox()) 171 if (!hasMailbox())
174 return nullptr; 172 return nullptr;
175 // Has mailbox, consume mailbox, prepare a new mailbox if contextProvider is not null (3D). 173 // Has mailbox, consume mailbox, prepare a new mailbox if contextProvider is not null (3D).
176 DCHECK(isMainThread()); 174 DCHECK(isMainThread());
177 // TODO(xidachen): make this work on a worker thread. 175 // TODO(xidachen): make this work on a worker thread.
178 std::unique_ptr<WebGraphicsContext3DProvider> sharedProvider = wrapUnique(Pl atform::current()->createSharedOffscreenGraphicsContext3DProvider()); 176 std::unique_ptr<WebGraphicsContext3DProvider> sharedProvider = wrapUnique(Pl atform::current()->createSharedOffscreenGraphicsContext3DProvider());
179 if (!switchStorageToSkImage(sharedProvider.get())) 177 if (!switchStorageToSkImage(sharedProvider.get()))
180 return nullptr; 178 return nullptr;
181 return m_image; 179 return m_image;
182 } 180 }
183 181
184 } // namespace blink 182 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/StaticBitmapImage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698