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

Unified Diff: third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp

Issue 2196963002: Add a new class AcceleratedStaticBitmap : StaticBitmapImage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + minor clean up 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp b/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
similarity index 63%
copy from third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp
copy to third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
index d22047c4ab1f12a27c603bcc683772020f40fd0c..4edc487659396e3618008b615538eeab3ef0b13e 100644
--- a/third_party/WebKit/Source/platform/graphics/StaticBitmapImage.cpp
+++ b/third_party/WebKit/Source/platform/graphics/AcceleratedStaticBitmapImage.cpp
@@ -1,108 +1,51 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/graphics/StaticBitmapImage.h"
+#include "platform/graphics/AcceleratedStaticBitmapImage.h"
#include "gpu/command_buffer/client/gles2_interface.h"
-#include "platform/graphics/GraphicsContext.h"
-#include "platform/graphics/ImageObserver.h"
+#include "platform/graphics/StaticBitmapImage.h"
+#include "platform/graphics/skia/SkiaUtils.h"
#include "public/platform/Platform.h"
#include "public/platform/WebGraphicsContext3DProvider.h"
#include "skia/ext/texture_handle.h"
-#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
-#include "third_party/skia/include/core/SkPaint.h"
-#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "wtf/PtrUtil.h"
#include <memory>
namespace blink {
-PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(PassRefPtr<SkImage> image)
+PassRefPtr<AcceleratedStaticBitmapImage> AcceleratedStaticBitmapImage::create(WebExternalTextureMailbox& mailbox)
{
- if (!image)
- return nullptr;
- return adoptRef(new StaticBitmapImage(image));
+ return adoptRef(new AcceleratedStaticBitmapImage(mailbox));
}
-PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(WebExternalTextureMailbox& mailbox)
+PassRefPtr<AcceleratedStaticBitmapImage> AcceleratedStaticBitmapImage::create(PassRefPtr<SkImage> image)
{
- return adoptRef(new StaticBitmapImage(mailbox));
+ return adoptRef(new AcceleratedStaticBitmapImage(image));
}
-StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image)
+AcceleratedStaticBitmapImage::AcceleratedStaticBitmapImage(WebExternalTextureMailbox& mailbox)
+ : StaticBitmapImage()
+ , m_mailbox(mailbox)
{
- ASSERT(m_image);
}
-StaticBitmapImage::StaticBitmapImage(WebExternalTextureMailbox& mailbox) : m_mailbox(mailbox)
+AcceleratedStaticBitmapImage::AcceleratedStaticBitmapImage(PassRefPtr<SkImage> image)
+ : StaticBitmapImage(image)
{
}
-StaticBitmapImage::~StaticBitmapImage() { }
-
-IntSize StaticBitmapImage::size() const
-{
- if (!m_image)
- return IntSize(m_mailbox.textureSize.width, m_mailbox.textureSize.height);
- return IntSize(m_image->width(), m_image->height());
-}
-
-bool StaticBitmapImage::isTextureBacked()
-{
- return m_image && m_image->isTextureBacked();
-}
-
-bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode)
-{
- return m_image->isOpaque();
-}
-
-void StaticBitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect,
- const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode clampMode)
-{
- FloatRect adjustedSrcRect = srcRect;
- adjustedSrcRect.intersect(SkRect::Make(m_image->bounds()));
-
- if (dstRect.isEmpty() || adjustedSrcRect.isEmpty())
- return; // Nothing to draw.
-
- canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint,
- WebCoreClampingModeToSkiaRectConstraint(clampMode));
-
- if (ImageObserver* observer = getImageObserver())
- observer->didDraw(this);
-}
-
-GLuint StaticBitmapImage::switchStorageToSkImage(WebGraphicsContext3DProvider* provider)
+IntSize AcceleratedStaticBitmapImage::size() const
{
- if (!provider)
- return 0;
- GrContext* grContext = provider->grContext();
- if (!grContext)
- return 0;
- gpu::gles2::GLES2Interface* gl = provider->contextGL();
- if (!gl)
- return 0;
- gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken);
- GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name);
- GrGLTextureInfo textureInfo;
- textureInfo.fTarget = GL_TEXTURE_2D;
- textureInfo.fID = textureId;
- GrBackendTextureDesc backendTexture;
- backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin;
- backendTexture.fWidth = m_mailbox.textureSize.width;
- backendTexture.fHeight = m_mailbox.textureSize.height;
- backendTexture.fConfig = kSkia8888_GrPixelConfig;
- backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textureInfo);
- sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendTexture);
- m_image = fromSkSp(skImage);
- return textureId;
+ if (m_image)
+ return IntSize(m_image->width(), m_image->height());
+ return IntSize(m_mailbox.textureSize.width, m_mailbox.textureSize.height);
}
-void StaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* provider, GLuint destinationTexture, GLenum internalFormat, GLenum destType, bool flipY)
+void AcceleratedStaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* provider, GLuint destinationTexture, GLenum internalFormat, GLenum destType, bool flipY)
{
GLuint textureId = switchStorageToSkImageForWebGL(provider);
gpu::gles2::GLES2Interface* gl = provider->contextGL();
@@ -117,7 +60,7 @@ void StaticBitmapImage::copyToTexture(WebGraphicsContext3DProvider* provider, GL
switchStorageToMailbox(provider);
}
-bool StaticBitmapImage::switchStorageToMailbox(WebGraphicsContext3DProvider* provider)
+bool AcceleratedStaticBitmapImage::switchStorageToMailbox(WebGraphicsContext3DProvider* provider)
{
m_mailbox.textureSize = WebSize(m_image->width(), m_image->height());
GrContext* grContext = provider->grContext();
@@ -144,7 +87,7 @@ bool StaticBitmapImage::switchStorageToMailbox(WebGraphicsContext3DProvider* pro
}
// This function is called only in the case that m_image is texture backed.
-GLuint StaticBitmapImage::switchStorageToSkImageForWebGL(WebGraphicsContext3DProvider* contextProvider)
+GLuint AcceleratedStaticBitmapImage::switchStorageToSkImageForWebGL(WebGraphicsContext3DProvider* contextProvider)
{
DCHECK(!m_image || m_image->isTextureBacked());
GLuint textureId = 0;
@@ -163,11 +106,36 @@ GLuint StaticBitmapImage::switchStorageToSkImageForWebGL(WebGraphicsContext3DPro
return textureId;
}
-PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame()
+GLuint AcceleratedStaticBitmapImage::switchStorageToSkImage(WebGraphicsContext3DProvider* provider)
+{
+ if (!provider)
+ return 0;
+ GrContext* grContext = provider->grContext();
+ if (!grContext)
+ return 0;
+ gpu::gles2::GLES2Interface* gl = provider->contextGL();
+ if (!gl)
+ return 0;
+ gl->WaitSyncTokenCHROMIUM(m_mailbox.syncToken);
+ GLuint textureId = gl->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, m_mailbox.name);
+ GrGLTextureInfo textureInfo;
+ textureInfo.fTarget = GL_TEXTURE_2D;
+ textureInfo.fID = textureId;
+ GrBackendTextureDesc backendTexture;
+ backendTexture.fOrigin = kBottomLeft_GrSurfaceOrigin;
+ backendTexture.fWidth = m_mailbox.textureSize.width;
+ backendTexture.fHeight = m_mailbox.textureSize.height;
+ backendTexture.fConfig = kSkia8888_GrPixelConfig;
+ backendTexture.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(textureInfo);
+ sk_sp<SkImage> skImage = SkImage::MakeFromAdoptedTexture(grContext, backendTexture);
+ m_image = fromSkSp(skImage);
+ return textureId;
+}
+
+PassRefPtr<SkImage> AcceleratedStaticBitmapImage::imageForCurrentFrame()
{
if (m_image)
return m_image;
- // No mailbox, return null;
if (!hasMailbox())
return nullptr;
// Has mailbox, consume mailbox, prepare a new mailbox if contextProvider is not null (3D).

Powered by Google App Engine
This is Rietveld 408576698