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

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

Issue 1962413002: Implement transferToImageBitmap() in WebGLRenderingContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code clean up, almost identical to PS4 Created 4 years, 7 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
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 "platform/graphics/GraphicsContext.h" 8 #include "platform/graphics/GraphicsContext.h"
8 #include "platform/graphics/ImageObserver.h" 9 #include "platform/graphics/ImageObserver.h"
10 #include "public/platform/Platform.h"
11 #include "public/platform/WebGraphicsContext3DProvider.h"
12 #include "skia/ext/texture_handle.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkImage.h" 14 #include "third_party/skia/include/core/SkImage.h"
11 #include "third_party/skia/include/core/SkPaint.h" 15 #include "third_party/skia/include/core/SkPaint.h"
12 #include "third_party/skia/include/core/SkShader.h" 16 #include "third_party/skia/include/core/SkShader.h"
13 17
14 namespace blink { 18 namespace blink {
15 19
16 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag e) 20 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> imag e)
17 { 21 {
18 if (!image) 22 if (!image)
19 return nullptr; 23 return nullptr;
20 return adoptRef(new StaticBitmapImage(image)); 24 return adoptRef(new StaticBitmapImage(image));
21 } 25 }
22 26
27 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(WebExternalTextureMailbo x& mailbox)
28 {
29 return adoptRef(new StaticBitmapImage(mailbox));
30 }
31
23 StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image) 32 StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image)
24 { 33 {
25 ASSERT(m_image); 34 ASSERT(m_image);
26 } 35 }
27 36
37 StaticBitmapImage::StaticBitmapImage(WebExternalTextureMailbox& mailbox) : m_mai lbox(mailbox)
38 {
39 }
40
28 StaticBitmapImage::~StaticBitmapImage() { } 41 StaticBitmapImage::~StaticBitmapImage() { }
29 42
30 IntSize StaticBitmapImage::size() const 43 IntSize StaticBitmapImage::size() const
31 { 44 {
32 return IntSize(m_image->width(), m_image->height()); 45 return IntSize(m_image->width(), m_image->height());
33 } 46 }
34 47
35 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode) 48 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode)
36 { 49 {
37 return m_image->isOpaque(); 50 return m_image->isOpaque();
(...skipping 10 matching lines...) Expand all
48 61
49 canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint, 62 canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint,
50 WebCoreClampingModeToSkiaRectConstraint(clampMode)); 63 WebCoreClampingModeToSkiaRectConstraint(clampMode));
51 64
52 if (ImageObserver* observer = getImageObserver()) 65 if (ImageObserver* observer = getImageObserver())
53 observer->didDraw(this); 66 observer->didDraw(this);
54 } 67 }
55 68
56 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() 69 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame()
57 { 70 {
58 return m_image; 71 if (m_image)
72 return m_image;
73 DCHECK(isMainThread());
74 // In the place when we consume an ImageBitmap that is gpu texture backed,
75 // create a new SkImage from that texture.
76 // TODO(xidachen): make this work on a worker thread.
77 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current() ->createSharedOffscreenGraphicsContext3DProvider());
Ken Russell (switch to Gerrit) 2016/05/19 00:15:12 Someone who understands this code better needs to
xidachen 2016/05/19 13:48:29 I believe this can be verified. Please take a look
78 if (!provider)
79 return nullptr;
80 GrContext* grContext = provider->grContext();
81 if (!grContext)
82 return nullptr;
83 gpu::gles2::GLES2Interface* gl = provider->contextGL();
84 if (!gl)
85 return nullptr;
86 gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken);
87 GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mail box.name);
88 GrGLTextureInfo textureInfo;
89 textureInfo.fTarget = GL_TEXTURE_2D;
90 textureInfo.fID = textureId;
91 GrBackendTextureDesc backendTexture;
92 backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin;
93 backendTexture.fWidth = m_mailbox.textureSize.width;
94 backendTexture.fHeight = m_mailbox.textureSize.height;
95 backendTexture.fConfig = kSkia8888_GrPixelConfig;
96 backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textu reInfo);
97 sk_sp<SkImage> skImage = SkImage::MakeFromTexture(grContext, backendTexture) ;
Ken Russell (switch to Gerrit) 2016/05/19 00:15:11 junov@ or bsalomon@ should review this code for co
bsalomon 2016/05/19 12:57:20 It seems OK to me but want to raise two potential
xidachen 2016/05/19 13:48:29 Thanks for the comments. 1). In my opinion, it ret
Ken Russell (switch to Gerrit) 2016/05/19 18:04:47 It returns a texture of the type passed to CreateA
98 return fromSkSp(skImage);
59 } 99 }
60 100
61 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698