Commit 9095a6d3 authored by sadrul's avatar sadrul Committed by Commit bot

gpu: Move ShaderDiskCache into //gpu/ipc/host component.

BUG=643746, 604369
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Committed: https://crrev.com/4a4522e8d9a3ae704b7a17ebb412d2a94aa820c2
Review-Url: https://codereview.chromium.org/2555693005
Cr-Original-Commit-Position: refs/heads/master@{#437771}
Cr-Commit-Position: refs/heads/master@{#438165}
parent c1be1791
......@@ -670,8 +670,6 @@ source_set("browser") {
"gpu/gpu_process_host_ui_shim.h",
"gpu/shader_cache_factory.cc",
"gpu/shader_cache_factory.h",
"gpu/shader_disk_cache.cc",
"gpu/shader_disk_cache.h",
"histogram_controller.cc",
"histogram_controller.h",
"histogram_internals_request_job.cc",
......
......@@ -57,6 +57,7 @@
#include "content/public/common/service_names.mojom.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/ipc/host/shader_disk_cache.h"
#include "gpu/ipc/service/switches.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/message_filter.h"
......@@ -1173,7 +1174,7 @@ void GpuProcessHost::LoadedShader(const std::string& key,
void GpuProcessHost::CreateChannelCache(int32_t client_id) {
TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache");
scoped_refptr<ShaderDiskCache> cache =
scoped_refptr<gpu::ShaderDiskCache> cache =
GetShaderCacheFactorySingleton()->Get(client_id);
if (!cache.get())
return;
......
......@@ -42,6 +42,7 @@ struct ChannelHandle;
namespace gpu {
struct GpuPreferences;
class ShaderDiskCache;
struct SyncToken;
}
......@@ -52,7 +53,6 @@ class InterfaceProvider;
namespace content {
class BrowserChildProcessHostImpl;
class InProcessChildThreadParams;
class ShaderDiskCache;
typedef base::Thread* (*GpuMainThreadFactoryFunction)(
const InProcessChildThreadParams&, const gpu::GpuPreferences&);
......@@ -282,7 +282,7 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
// automatic execution of 3D content from those domains.
std::multiset<GURL> urls_with_live_offscreen_contexts_;
typedef std::map<int32_t, scoped_refptr<ShaderDiskCache>>
typedef std::map<int32_t, scoped_refptr<gpu::ShaderDiskCache>>
ClientIdToShaderCacheMap;
ClientIdToShaderCacheMap client_id_to_shader_cache_;
......
......@@ -5,18 +5,18 @@
#include "content/browser/gpu/shader_cache_factory.h"
#include "base/single_thread_task_runner.h"
#include "content/browser/gpu/shader_disk_cache.h"
#include "gpu/ipc/host/shader_disk_cache.h"
namespace content {
namespace {
ShaderCacheFactory* factory_instance = nullptr;
gpu::ShaderCacheFactory* factory_instance = nullptr;
void CreateFactoryInstance(
scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner) {
DCHECK(!factory_instance);
factory_instance = new ShaderCacheFactory(std::move(cache_task_runner));
factory_instance = new gpu::ShaderCacheFactory(std::move(cache_task_runner));
}
} // namespace
......@@ -32,7 +32,7 @@ void InitShaderCacheFactorySingleton(
}
}
ShaderCacheFactory* GetShaderCacheFactorySingleton() {
gpu::ShaderCacheFactory* GetShaderCacheFactorySingleton() {
DCHECK(!factory_instance || factory_instance->CalledOnValidThread());
return factory_instance;
}
......
......@@ -5,8 +5,8 @@
#ifndef CONTENT_BROWSER_GPU_SHADER_CACHE_FACTORY_H_
#define CONTENT_BROWSER_GPU_SHADER_CACHE_FACTORY_H_
#include "content/browser/gpu/shader_disk_cache.h"
#include "content/common/content_export.h"
#include "gpu/ipc/host/shader_disk_cache.h"
namespace content {
......@@ -20,7 +20,7 @@ CONTENT_EXPORT void InitShaderCacheFactorySingleton(
// Returns an instance previously created by InitShaderCacheFactorySingleton().
// This can return nullptr if an instance has not yet been created.
CONTENT_EXPORT ShaderCacheFactory* GetShaderCacheFactorySingleton();
CONTENT_EXPORT gpu::ShaderCacheFactory* GetShaderCacheFactorySingleton();
} // namespace content
......
......@@ -641,7 +641,7 @@ class StoragePartitionShaderClearTest : public testing::Test {
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<TestBrowserContext> browser_context_;
scoped_refptr<ShaderDiskCache> cache_;
scoped_refptr<gpu::ShaderDiskCache> cache_;
};
// Tests ---------------------------------------------------------------------
......
......@@ -1073,7 +1073,6 @@ test("content_unittests") {
"../browser/frame_host/render_widget_host_view_child_frame_unittest.cc",
"../browser/frame_host/render_widget_host_view_guest_unittest.cc",
"../browser/gpu/gpu_data_manager_impl_private_unittest.cc",
"../browser/gpu/shader_disk_cache_unittest.cc",
"../browser/host_zoom_map_impl_unittest.cc",
"../browser/indexed_db/indexed_db_active_blob_registry_unittest.cc",
"../browser/indexed_db/indexed_db_backing_store_unittest.cc",
......@@ -1407,6 +1406,7 @@ test("content_unittests") {
"//gin",
"//gpu",
"//gpu:test_support",
"//gpu/ipc/host",
"//ipc:test_support",
"//media:shared_memory_support",
"//media:test_support",
......
......@@ -302,6 +302,7 @@ test("gpu_unittests") {
"ipc/client/gpu_memory_buffer_impl_shared_memory_unittest.cc",
"ipc/client/gpu_memory_buffer_impl_test_template.h",
"ipc/common/struct_traits_unittest.cc",
"ipc/host/shader_disk_cache_unittest.cc",
]
if (is_mac) {
......@@ -326,8 +327,10 @@ test("gpu_unittests") {
"//gpu/command_buffer/common:gles2_utils",
"//gpu/ipc:gl_in_process_context",
"//gpu/ipc/common:test_interfaces",
"//gpu/ipc/host",
"//mojo/edk/system",
"//mojo/public/cpp/bindings",
"//net:test_support",
"//testing/gmock",
"//testing/gtest",
"//third_party/angle:translator",
......
......@@ -10,11 +10,14 @@ source_set("host") {
"gpu_memory_buffer_support.h",
"gpu_switches.cc",
"gpu_switches.h",
"shader_disk_cache.cc",
"shader_disk_cache.h",
]
deps = [
"//base",
"//gpu/ipc/common",
"//net",
"//ui/gfx",
"//ui/gl",
]
......
include_rules = [
"+net",
]
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/gpu/shader_disk_cache.h"
#include "gpu/ipc/host/shader_disk_cache.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
......@@ -13,7 +13,7 @@
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
namespace content {
namespace gpu {
namespace {
......@@ -77,7 +77,6 @@ class ShaderDiskReadHelper : public base::ThreadChecker {
ITERATION_FINISHED
};
void OnOpComplete(int rv);
int OpenNextEntry();
......@@ -109,11 +108,7 @@ class ShaderClearHelper : public base::ThreadChecker {
void Clear();
private:
enum OpType {
TERMINATE,
VERIFY_CACHE_SETUP,
DELETE_CACHE
};
enum OpType { TERMINATE, VERIFY_CACHE_SETUP, DELETE_CACHE };
void DoClearShaderCache(int rv);
......@@ -376,8 +371,7 @@ ShaderCacheFactory::ShaderCacheFactory(
scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner)
: cache_task_runner_(std::move(cache_task_runner)) {}
ShaderCacheFactory::~ShaderCacheFactory() {
}
ShaderCacheFactory::~ShaderCacheFactory() {}
void ShaderCacheFactory::SetCacheInfo(int32_t client_id,
const base::FilePath& path) {
......@@ -516,15 +510,15 @@ void ShaderDiskCache::Cache(const std::string& key, const std::string& shader) {
entries_.insert(std::make_pair(raw_ptr, std::move(shim)));
}
int ShaderDiskCache::Clear(
const base::Time begin_time, const base::Time end_time,
const net::CompletionCallback& completion_callback) {
int ShaderDiskCache::Clear(const base::Time begin_time,
const base::Time end_time,
const net::CompletionCallback& completion_callback) {
int rv;
if (begin_time.is_null()) {
rv = backend_->DoomAllEntries(completion_callback);
} else {
rv = backend_->DoomEntriesBetween(begin_time, end_time,
completion_callback);
rv =
backend_->DoomEntriesBetween(begin_time, end_time, completion_callback);
}
return rv;
}
......@@ -581,4 +575,4 @@ int ShaderDiskCache::SetCacheCompleteCallback(
return net::ERR_IO_PENDING;
}
} // namespace content
} // namespace gpu
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_
#define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_
#ifndef GPU_IPC_HOST_SHADER_DISK_CACHE_H_
#define GPU_IPC_HOST_SHADER_DISK_CACHE_H_
#include <stdint.h>
......@@ -15,10 +15,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "net/disk_cache/disk_cache.h"
namespace content {
namespace gpu {
class ShaderCacheFactory;
class ShaderDiskCacheEntry;
......@@ -27,8 +26,7 @@ class ShaderClearHelper;
// ShaderDiskCache is the interface to the on disk cache for
// GL shaders.
class CONTENT_EXPORT ShaderDiskCache
: public base::RefCounted<ShaderDiskCache> {
class ShaderDiskCache : public base::RefCounted<ShaderDiskCache> {
public:
using ShaderLoadedCallback =
base::Callback<void(const std::string&, const std::string&)>;
......@@ -45,10 +43,9 @@ class CONTENT_EXPORT ShaderDiskCache
// The return value is a net error code. If this method returns
// ERR_IO_PENDING, the |completion_callback| will be invoked when the
// operation completes.
int Clear(
const base::Time begin_time,
const base::Time end_time,
const net::CompletionCallback& completion_callback);
int Clear(const base::Time begin_time,
const base::Time end_time,
const net::CompletionCallback& completion_callback);
// Sets a callback for when the cache is available. If the cache is
// already available the callback will not be called and net::OK is returned.
......@@ -104,8 +101,7 @@ class CONTENT_EXPORT ShaderDiskCache
// ShaderCacheFactory maintains a cache of ShaderDiskCache objects
// so we only create one per profile directory.
class CONTENT_EXPORT ShaderCacheFactory
: NON_EXPORTED_BASE(public base::ThreadChecker) {
class ShaderCacheFactory : NON_EXPORTED_BASE(public base::ThreadChecker) {
public:
explicit ShaderCacheFactory(
scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner);
......@@ -156,6 +152,6 @@ class CONTENT_EXPORT ShaderCacheFactory
DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory);
};
} // namespace content
} // namespace gpu
#endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_
#endif // GPU_IPC_HOST_SHADER_DISK_CACHE_H_
......@@ -5,15 +5,14 @@
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/gpu/shader_disk_cache.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "gpu/ipc/host/shader_disk_cache.h"
#include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace gpu {
namespace {
const int kDefaultClientId = 42;
......@@ -25,9 +24,12 @@ const char kCacheValue[] = "cached value";
class ShaderDiskCacheTest : public testing::Test {
public:
ShaderDiskCacheTest()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
factory_ = base::MakeUnique<ShaderCacheFactory>(
BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE));
: cache_thread_("CacheThread") {
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
CHECK(cache_thread_.StartWithOptions(options));
factory_ =
base::MakeUnique<ShaderCacheFactory>(cache_thread_.task_runner());
}
~ShaderDiskCacheTest() override {}
......@@ -46,7 +48,8 @@ class ShaderDiskCacheTest : public testing::Test {
std::unique_ptr<ShaderCacheFactory> factory_;
base::ScopedTempDir temp_dir_;
content::TestBrowserThreadBundle thread_bundle_;
base::Thread cache_thread_;
base::MessageLoopForIO message_loop_;
DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheTest);
};
......@@ -76,4 +79,4 @@ TEST_F(ShaderDiskCacheTest, ClearsCache) {
EXPECT_EQ(0, cache->Size());
};
} // namespace content
} // namespace gpu
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