Commit 1521ca7e authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Move memory dump internals from SharedImageFactory to SharedImageBacking

This CL moves the memory dump internals into SharedImageBacking, which
will allow for new backing types to implement their own dump logic.

Bug: 891059
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I4f239ab76e75d3b51fe3a120e7c34b20376f559c
Reviewed-on: https://chromium-review.googlesource.com/c/1279167
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600096}
parent ae8140f1
......@@ -219,6 +219,7 @@ target(link_target_type, "gles2_sources") {
"shader_translator.h",
"shader_translator_cache.cc",
"shader_translator_cache.h",
"shared_image_backing.cc",
"shared_image_backing.h",
"shared_image_backing_factory.h",
"shared_image_backing_factory_gl_texture.cc",
......
// Copyright 2018 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 "gpu/command_buffer/service/shared_image_backing.h"
namespace gpu {
SharedImageBacking::SharedImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage)
: mailbox_(mailbox),
format_(format),
size_(size),
color_space_(color_space),
usage_(usage) {}
SharedImageBacking::~SharedImageBacking() = default;
size_t SharedImageBacking::EstimatedSize() const {
return 0;
}
} // namespace gpu
......@@ -11,6 +11,13 @@
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h"
namespace base {
namespace trace_event {
class ProcessMemoryDump;
class MemoryAllocatorDump;
} // namespace trace_event
} // namespace base
namespace gpu {
class MailboxManager;
......@@ -20,33 +27,42 @@ class MailboxManager;
// TODO(ericrk): Add SharedImageRepresentation and Begin/End logic.
class SharedImageBacking {
public:
SharedImageBacking(viz::ResourceFormat format,
SharedImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage)
: format_(format),
size_(size),
color_space_(color_space),
usage_(usage) {}
uint32_t usage);
virtual ~SharedImageBacking() {}
virtual ~SharedImageBacking();
viz::ResourceFormat format() const { return format_; }
const gfx::Size& size() const { return size_; }
const gfx::ColorSpace& color_space() const { return color_space_; }
uint32_t usage() const { return usage_; }
const Mailbox& mailbox() const { return mailbox_; }
// Memory dump helpers:
// Returns the estimated size of the backing. If 0 is returned, the dump will
// be omitted.
virtual size_t EstimatedSize() const;
// Allows the backing to attach additional data to the dump or dump
// additional sub paths.
virtual void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) {}
// Prepares the backing for use with the legacy mailbox system.
// TODO(ericrk): Remove this once the new codepath is complete.
virtual bool ProduceLegacyMailbox(const Mailbox& mailbox,
MailboxManager* mailbox_manager) = 0;
virtual bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) = 0;
virtual void Destroy(bool have_context) = 0;
private:
viz::ResourceFormat format_;
gfx::Size size_;
gfx::ColorSpace color_space_;
uint32_t usage_;
const Mailbox mailbox_;
const viz::ResourceFormat format_;
const gfx::Size size_;
const gfx::ColorSpace color_space_;
const uint32_t usage_;
};
} // namespace gpu
......
......@@ -16,11 +16,13 @@ class ColorSpace;
namespace gpu {
class SharedImageBacking;
struct Mailbox;
class SharedImageBackingFactory {
public:
virtual ~SharedImageBackingFactory() = default;
virtual std::unique_ptr<SharedImageBacking> CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
......
......@@ -4,11 +4,9 @@
#include "gpu/command_buffer/service/shared_image_backing_factory_gl_texture.h"
#include <inttypes.h>
#include "base/feature_list.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
......@@ -32,22 +30,22 @@ namespace gpu {
// as a gles2::Texture. Can be used with the legacy mailbox implementation.
class SharedImageBackingGLTexture : public SharedImageBacking {
public:
SharedImageBackingGLTexture(viz::ResourceFormat format,
SharedImageBackingGLTexture(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
gles2::Texture* texture)
: SharedImageBacking(format, size, color_space, usage),
: SharedImageBacking(mailbox, format, size, color_space, usage),
texture_(texture) {
DCHECK(texture_);
}
~SharedImageBackingGLTexture() override { DCHECK(!texture_); }
bool ProduceLegacyMailbox(const Mailbox& mailbox,
MailboxManager* mailbox_manager) override {
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override {
DCHECK(texture_);
mailbox_manager->ProduceTexture(mailbox, texture_);
mailbox_manager->ProduceTexture(mailbox(), texture_);
return true;
}
......@@ -57,6 +55,28 @@ class SharedImageBackingGLTexture : public SharedImageBacking {
texture_ = nullptr;
}
size_t EstimatedSize() const override { return texture_->estimated_size(); }
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override {
// Add a |service_guid| which expresses shared ownership between the
// various GPU dumps.
auto client_guid = GetSharedImageGUIDForTracing(mailbox());
auto service_guid =
gl::GetGLTextureServiceGUIDForTracing(texture_->service_id());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
// TODO(piman): coalesce constant with TextureManager::DumpTextureRef.
int importance = 2; // This client always owns the ref.
pmd->AddOwnershipEdge(client_guid, service_guid, importance);
// Dump all sub-levels held by the texture. They will appear below the
// main gl/textures/client_X/mailbox_Y dump.
texture_->DumpLevelMemory(pmd, client_tracing_id, dump_name);
}
private:
gles2::Texture* texture_ = nullptr;
};
......@@ -67,12 +87,13 @@ class SharedImageBackingGLTexture : public SharedImageBacking {
class SharedImageBackingPassthroughGLTexture : public SharedImageBacking {
public:
SharedImageBackingPassthroughGLTexture(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
scoped_refptr<gles2::TexturePassthrough> passthrough_texture)
: SharedImageBacking(format, size, color_space, usage),
: SharedImageBacking(mailbox, format, size, color_space, usage),
passthrough_texture_(std::move(passthrough_texture)) {
DCHECK(passthrough_texture_);
}
......@@ -81,10 +102,9 @@ class SharedImageBackingPassthroughGLTexture : public SharedImageBacking {
DCHECK(!passthrough_texture_);
}
bool ProduceLegacyMailbox(const Mailbox& mailbox,
MailboxManager* mailbox_manager) override {
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override {
DCHECK(passthrough_texture_);
mailbox_manager->ProduceTexture(mailbox, passthrough_texture_.get());
mailbox_manager->ProduceTexture(mailbox(), passthrough_texture_.get());
return true;
}
......@@ -200,6 +220,7 @@ SharedImageBackingFactoryGLTexture::~SharedImageBackingFactoryGLTexture() =
std::unique_ptr<SharedImageBacking>
SharedImageBackingFactoryGLTexture::CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
......@@ -307,7 +328,8 @@ SharedImageBackingFactoryGLTexture::CreateSharedImage(
if (image)
passthrough_texture->SetLevelImage(target, 0, image.get());
backing = std::make_unique<SharedImageBackingPassthroughGLTexture>(
format, size, color_space, usage, std::move(passthrough_texture));
mailbox, format, size, color_space, usage,
std::move(passthrough_texture));
} else {
gles2::Texture* texture = new gles2::Texture(service_id);
texture->SetLightweightRef(memory_tracker_.get());
......@@ -328,7 +350,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImage(
texture->SetLevelImage(target, 0, image.get(), gles2::Texture::BOUND);
texture->SetImmutable(true);
backing = std::make_unique<SharedImageBackingGLTexture>(
format, size, color_space, usage, texture);
mailbox, format, size, color_space, usage, texture);
}
api->glBindTextureFn(target, old_texture_binding);
......
......@@ -25,6 +25,7 @@ class SharedImageBacking;
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct GpuPreferences;
struct Mailbox;
class ImageFactory;
namespace gles2 {
......@@ -47,6 +48,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture
// SharedImageBackingFactory implementation.
std::unique_ptr<SharedImageBacking> CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
......
......@@ -58,18 +58,18 @@ class SharedImageBackingFactoryGLTextureTest
};
TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
auto backing =
backing_factory_->CreateSharedImage(format, size, color_space, usage);
auto backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
EXPECT_TRUE(backing);
// TODO(ericrk): Validate via a SharedImageRepresentation. For now use legacy
// mailbox.
auto mailbox = Mailbox::Generate();
EXPECT_TRUE(backing->ProduceLegacyMailbox(mailbox, &mailbox_manager_));
EXPECT_TRUE(backing->ProduceLegacyMailbox(&mailbox_manager_));
TextureBase* texture_base = mailbox_manager_.ConsumeTexture(mailbox);
ASSERT_TRUE(texture_base);
GLenum expected_target = GL_TEXTURE_2D;
......@@ -90,18 +90,18 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
}
TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_SCANOUT;
auto backing =
backing_factory_->CreateSharedImage(format, size, color_space, usage);
auto backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
EXPECT_TRUE(backing);
// TODO(ericrk): Validate via a SharedImageRepresentation. For now use legacy
// mailbox.
auto mailbox = Mailbox::Generate();
EXPECT_TRUE(backing->ProduceLegacyMailbox(mailbox, &mailbox_manager_));
EXPECT_TRUE(backing->ProduceLegacyMailbox(&mailbox_manager_));
TextureBase* texture_base = mailbox_manager_.ConsumeTexture(mailbox);
ASSERT_TRUE(texture_base);
GLenum target = texture_base->target();
......@@ -121,27 +121,29 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
}
TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidFormat) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::UYVY_422;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
auto backing =
backing_factory_->CreateSharedImage(format, size, color_space, usage);
auto backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
EXPECT_FALSE(backing);
}
TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(0, 0);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
auto backing =
backing_factory_->CreateSharedImage(format, size, color_space, usage);
auto backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
EXPECT_FALSE(backing);
size = gfx::Size(INT_MAX, INT_MAX);
backing =
backing_factory_->CreateSharedImage(format, size, color_space, usage);
backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
EXPECT_FALSE(backing);
}
......
......@@ -34,9 +34,7 @@ SharedImageFactory::SharedImageFactory(
SharedImageManager* shared_image_manager,
ImageFactory* image_factory,
gles2::MemoryTracker* tracker)
: use_passthrough_(gpu_preferences.use_passthrough_cmd_decoder &&
gles2::PassthroughCommandDecoderSupported()),
mailbox_manager_(mailbox_manager),
: mailbox_manager_(mailbox_manager),
shared_image_manager_(shared_image_manager),
backing_factory_(
std::make_unique<SharedImageBackingFactoryGLTexture>(gpu_preferences,
......@@ -66,11 +64,11 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
std::unique_ptr<SharedImageBacking> backing;
if (wrapped_sk_image_factory_ &&
(usage & SHARED_IMAGE_USAGE_OOP_RASTERIZATION)) {
backing = wrapped_sk_image_factory_->CreateSharedImage(format, size,
color_space, usage);
backing = wrapped_sk_image_factory_->CreateSharedImage(
mailbox, format, size, color_space, usage);
} else {
backing =
backing_factory_->CreateSharedImage(format, size, color_space, usage);
backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
}
if (!backing) {
......@@ -79,14 +77,14 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
}
// TODO(ericrk): Handle the non-legacy case.
if (!backing->ProduceLegacyMailbox(mailbox, mailbox_manager_)) {
if (!backing->ProduceLegacyMailbox(mailbox_manager_)) {
LOG(ERROR)
<< "CreateSharedImage: could not convert backing to legacy mailbox.";
backing->Destroy(true /* have_context */);
return false;
}
if (!shared_image_manager_->Register(mailbox, std::move(backing))) {
if (!shared_image_manager_->Register(std::move(backing))) {
LOG(ERROR) << "CreateSharedImage: Could not register backing with "
"SharedImageManager.";
backing->Destroy(true /* have_context */);
......@@ -120,59 +118,9 @@ bool SharedImageFactory::OnMemoryDump(
base::trace_event::ProcessMemoryDump* pmd,
int client_id,
uint64_t client_tracing_id) {
if (use_passthrough_)
return true;
// TODO(ericrk): Move some of this to SharedImageBacking.
for (const auto& mailbox : mailboxes_) {
uint64_t estimated_size = 0;
TextureBase* texture_base = mailbox_manager_->ConsumeTexture(mailbox);
gles2::Texture* texture = nullptr;
switch (texture_base->GetType()) {
case TextureBase::Type::kValidated:
texture = gles2::Texture::CheckedCast(texture_base);
estimated_size = texture->estimated_size();
break;
case TextureBase::Type::kSkImage:
estimated_size =
raster::WrappedSkImage::CheckedCast(texture_base)->estimated_size();
break;
default:
NOTREACHED();
continue;
}
// Unique name in the process.
std::string dump_name =
base::StringPrintf("gpu/shared-images/client_0x%" PRIX32 "/mailbox_%s",
client_id, mailbox.ToDebugString().c_str());
base::trace_event::MemoryAllocatorDump* dump =
pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
estimated_size);
// Add a mailbox guid which expresses shared ownership with the client
// process.
// This must match the client-side.
auto client_guid = GetSharedImageGUIDForTracing(mailbox);
pmd->CreateSharedGlobalAllocatorDump(client_guid);
pmd->AddOwnershipEdge(dump->guid(), client_guid);
// Add a |service_guid| which expresses shared ownership between the
// various GPU dumps.
auto service_guid =
gl::GetGLTextureServiceGUIDForTracing(texture->GetTracingId());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
// TODO(piman): coalesce constant with TextureManager::DumpTextureRef.
int importance = 2; // This client always owns the ref.
pmd->AddOwnershipEdge(client_guid, service_guid, importance);
// Dump all sub-levels held by the texture. They will appear below the
// main gl/textures/client_X/mailbox_Y dump.
if (texture)
texture->DumpLevelMemory(pmd, client_tracing_id, dump_name);
shared_image_manager_->OnMemoryDump(mailbox, pmd, client_id,
client_tracing_id);
}
return true;
......
......@@ -60,7 +60,6 @@ class GPU_GLES2_EXPORT SharedImageFactory {
uint64_t client_tracing_id);
private:
bool use_passthrough_;
MailboxManager* mailbox_manager_;
SharedImageManager* shared_image_manager_;
......
......@@ -4,7 +4,32 @@
#include "gpu/command_buffer/service/shared_image_manager.h"
#include <inttypes.h>
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "ui/gl/trace_util.h"
namespace gpu {
// Overrides for flat_set lookups:
bool operator<(const gpu::SharedImageManager::BackingAndRefCount& lhs,
const gpu::SharedImageManager::BackingAndRefCount& rhs) {
return lhs.backing->mailbox() < rhs.backing->mailbox();
}
bool operator<(const gpu::Mailbox& lhs,
const gpu::SharedImageManager::BackingAndRefCount& rhs) {
return lhs < rhs.backing->mailbox();
}
bool operator<(const gpu::SharedImageManager::BackingAndRefCount& lhs,
const gpu::Mailbox& rhs) {
return lhs.backing->mailbox() < rhs;
}
SharedImageManager::SharedImageManager() = default;
......@@ -12,14 +37,12 @@ SharedImageManager::~SharedImageManager() {
DCHECK(images_.empty());
}
bool SharedImageManager::Register(const Mailbox& mailbox,
std::unique_ptr<SharedImageBacking> backing) {
auto found = images_.find(mailbox);
bool SharedImageManager::Register(std::unique_ptr<SharedImageBacking> backing) {
auto found = images_.find(backing->mailbox());
if (found != images_.end())
return false;
images_.emplace(mailbox,
BackingAndRefCount(std::move(backing), 1 /* ref_count */));
images_.emplace(std::move(backing), 1 /* ref_count */);
return true;
}
......@@ -31,13 +54,51 @@ void SharedImageManager::Unregister(const Mailbox& mailbox, bool have_context) {
return;
}
found->second.ref_count--;
if (found->second.ref_count == 0) {
found->second.backing->Destroy(have_context);
found->ref_count--;
if (found->ref_count == 0) {
found->backing->Destroy(have_context);
images_.erase(found);
}
}
void SharedImageManager::OnMemoryDump(const Mailbox& mailbox,
base::trace_event::ProcessMemoryDump* pmd,
int client_id,
uint64_t client_tracing_id) {
auto found = images_.find(mailbox);
if (found == images_.end()) {
LOG(ERROR) << "SharedImageManager::OnMemoryDump: Trying to dump memory for "
"a non existent mailbox.";
return;
}
auto* backing = found->backing.get();
size_t estimated_size = backing->EstimatedSize();
if (estimated_size == 0)
return;
// Unique name in the process.
std::string dump_name =
base::StringPrintf("gpu/shared-images/client_0x%" PRIX32 "/mailbox_%s",
client_id, mailbox.ToDebugString().c_str());
base::trace_event::MemoryAllocatorDump* dump =
pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
estimated_size);
// Add a mailbox guid which expresses shared ownership with the client
// process.
// This must match the client-side.
auto client_guid = GetSharedImageGUIDForTracing(mailbox);
pmd->CreateSharedGlobalAllocatorDump(client_guid);
pmd->AddOwnershipEdge(dump->guid(), client_guid);
// Allow the SharedImageBacking to attach additional data to the dump
// or dump additional sub-paths.
backing->OnMemoryDump(dump_name, dump, pmd, client_tracing_id);
}
SharedImageManager::BackingAndRefCount::BackingAndRefCount(
std::unique_ptr<SharedImageBacking> backing,
uint32_t ref_count)
......
......@@ -5,7 +5,7 @@
#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_MANAGER_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_MANAGER_H_
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/gpu_gles2_export.h"
......@@ -20,8 +20,7 @@ class GPU_GLES2_EXPORT SharedImageManager {
// Registers a SharedImageBacking with the manager and returns true on
// success. On success, the backing has one ref which may be released by
// calling Unregister.
bool Register(const Mailbox& mailbox,
std::unique_ptr<SharedImageBacking> backing);
bool Register(std::unique_ptr<SharedImageBacking> backing);
// Releases the registration ref. If a backing reaches zero refs, it is
// destroyed.
......@@ -31,6 +30,12 @@ class GPU_GLES2_EXPORT SharedImageManager {
// SharedImageRepresentation. Representations also take a ref on the
// mailbox, releasing it when the representation is destroyed.
// Dump memory for the given mailbox.
void OnMemoryDump(const Mailbox& mailbox,
base::trace_event::ProcessMemoryDump* pmd,
int client_id,
uint64_t client_tracing_id);
private:
struct BackingAndRefCount {
BackingAndRefCount(std::unique_ptr<SharedImageBacking> backing,
......@@ -41,7 +46,12 @@ class GPU_GLES2_EXPORT SharedImageManager {
std::unique_ptr<SharedImageBacking> backing;
uint32_t ref_count = 0;
};
base::flat_map<Mailbox, BackingAndRefCount> images_;
friend bool operator<(const BackingAndRefCount& lhs,
const BackingAndRefCount& rhs);
friend bool operator<(const Mailbox& lhs, const BackingAndRefCount& rhs);
friend bool operator<(const BackingAndRefCount& lhs, const Mailbox& rhs);
base::flat_set<BackingAndRefCount> images_;
DISALLOW_COPY_AND_ASSIGN(SharedImageManager);
};
......
......@@ -6,7 +6,11 @@
#include "base/hash.h"
#include "base/logging.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/raster_decoder_context_state.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
......@@ -15,6 +19,7 @@
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/trace_util.h"
namespace gpu {
namespace raster {
......@@ -23,22 +28,22 @@ namespace {
class WrappedSkImageBacking : public SharedImageBacking {
public:
WrappedSkImageBacking(viz::ResourceFormat format,
WrappedSkImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
std::unique_ptr<WrappedSkImage> wrapped_sk_image)
: SharedImageBacking(format, size, color_space, usage),
: SharedImageBacking(mailbox, format, size, color_space, usage),
wrapped_sk_image_(std::move(wrapped_sk_image)) {
DCHECK(!!wrapped_sk_image_);
}
~WrappedSkImageBacking() override { DCHECK(!wrapped_sk_image_); }
bool ProduceLegacyMailbox(const Mailbox& mailbox,
MailboxManager* mailbox_manager) override {
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override {
DCHECK(!!wrapped_sk_image_);
mailbox_manager->ProduceTexture(mailbox, wrapped_sk_image_.get());
mailbox_manager->ProduceTexture(mailbox(), wrapped_sk_image_.get());
return true;
}
......@@ -47,6 +52,26 @@ class WrappedSkImageBacking : public SharedImageBacking {
wrapped_sk_image_.reset();
}
size_t EstimatedSize() const override {
return wrapped_sk_image_->estimated_size();
}
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override {
// Add a |service_guid| which expresses shared ownership between the
// various GPU dumps.
auto client_guid = GetSharedImageGUIDForTracing(mailbox());
auto service_guid = gl::GetGLTextureServiceGUIDForTracing(
wrapped_sk_image_->GetTracingId());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
// TODO(piman): coalesce constant with TextureManager::DumpTextureRef.
int importance = 2; // This client always owns the ref.
pmd->AddOwnershipEdge(client_guid, service_guid, importance);
}
private:
std::unique_ptr<WrappedSkImage> wrapped_sk_image_;
......@@ -62,6 +87,7 @@ WrappedSkImageFactory::WrappedSkImageFactory(
WrappedSkImageFactory::~WrappedSkImageFactory() = default;
std::unique_ptr<SharedImageBacking> WrappedSkImageFactory::CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
......@@ -69,8 +95,8 @@ std::unique_ptr<SharedImageBacking> WrappedSkImageFactory::CreateSharedImage(
std::unique_ptr<WrappedSkImage> texture(new WrappedSkImage(context_state_));
if (!texture->Initialize(size, format))
return nullptr;
return std::make_unique<WrappedSkImageBacking>(format, size, color_space,
usage, std::move(texture));
return std::make_unique<WrappedSkImageBacking>(
mailbox, format, size, color_space, usage, std::move(texture));
}
WrappedSkImage::WrappedSkImage(raster::RasterDecoderContextState* context_state)
......
......@@ -31,6 +31,7 @@ class GPU_GLES2_EXPORT WrappedSkImageFactory
// SharedImageBackingFactory implementation:
std::unique_ptr<SharedImageBacking> CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment