Commit 4c5b23ef authored by thestig's avatar thestig Committed by Commit bot

Use base::FooValue::From() to simplify gpu code.

Clean up compositor_model_bench code.
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2145543002
Cr-Commit-Position: refs/heads/master@{#405244}
parent d4179235
......@@ -1394,14 +1394,11 @@ GpuControlList::~GpuControlList() {
bool GpuControlList::LoadList(
const std::string& json_context,
GpuControlList::OsFilter os_filter) {
std::unique_ptr<base::Value> root = base::JSONReader::Read(json_context);
if (root.get() == NULL || !root->IsType(base::Value::TYPE_DICTIONARY))
std::unique_ptr<base::DictionaryValue> root =
base::DictionaryValue::From(base::JSONReader::Read(json_context));
if (!root)
return false;
base::DictionaryValue* root_dictionary =
static_cast<base::DictionaryValue*>(root.get());
DCHECK(root_dictionary);
return LoadList(*root_dictionary, os_filter);
return LoadList(*root, os_filter);
}
bool GpuControlList::LoadList(const base::DictionaryValue& parsed_json,
......
......@@ -19,6 +19,7 @@
#include <queue>
#include <string>
#include <utility>
#include <vector>
#include "base/at_exit.h"
......@@ -59,20 +60,18 @@ void _update_loop(Simulator* sim);
class Simulator {
public:
Simulator(int seconds_per_test, const base::FilePath& output_path)
: current_sim_(NULL),
output_path_(output_path),
seconds_per_test_(seconds_per_test),
display_(NULL),
window_(0),
gl_context_(NULL),
window_width_(WINDOW_WIDTH),
window_height_(WINDOW_HEIGHT),
weak_factory_(this) {
}
: output_path_(output_path),
seconds_per_test_(seconds_per_test),
display_(nullptr),
window_(0),
gl_context_(nullptr),
window_width_(WINDOW_WIDTH),
window_height_(WINDOW_HEIGHT),
weak_factory_(this) {}
~Simulator() {
// Cleanup GL.
glXMakeCurrent(display_, 0, NULL);
glXMakeCurrent(display_, 0, nullptr);
glXDestroyContext(display_, gl_context_);
// Destroy window and display.
......@@ -153,7 +152,7 @@ class Simulator {
// Initialize X11. Returns true if successful. This method creates the
// X11 window. Further initialization is done in X11VideoRenderer.
bool InitX11() {
display_ = XOpenDisplay(NULL);
display_ = XOpenDisplay(nullptr);
if (!display_) {
LOG(FATAL) << "Cannot open display";
return false;
......@@ -212,7 +211,7 @@ class Simulator {
if (!glXMakeCurrent(display_, window_, gl_context_)) {
glXDestroyContext(display_, gl_context_);
gl_context_ = NULL;
gl_context_ = nullptr;
return false;
}
......@@ -221,32 +220,26 @@ class Simulator {
bool InitializeNextTest() {
SimulationSpecification& spec = sims_remaining_.front();
LOG(INFO) << "Initializing test for " << spec.simulation_name <<
"(" << ModelToString(spec.model_under_test) << ")";
LOG(INFO) << "Initializing test for " << spec.simulation_name << "("
<< ModelToString(spec.model_under_test) << ")";
const base::FilePath& path = spec.input_path;
RenderNode* root = NULL;
if (!(root = BuildRenderTreeFromFile(path))) {
LOG(ERROR) << "Couldn't parse test configuration file " <<
path.LossyDisplayName();
std::unique_ptr<RenderNode> root = BuildRenderTreeFromFile(path);
if (!root) {
LOG(ERROR) << "Couldn't parse test configuration file "
<< path.LossyDisplayName();
return false;
}
current_sim_ = ConstructSimulationModel(spec.model_under_test,
root,
window_width_,
window_height_);
if (!current_sim_)
return false;
return true;
current_sim_ = ConstructSimulationModel(
spec.model_under_test, std::move(root), window_width_, window_height_);
return !!current_sim_;
}
void CleanupCurrentTest() {
LOG(INFO) << "Finished test " << sims_remaining_.front().simulation_name;
delete current_sim_;
current_sim_ = NULL;
current_sim_.reset();
}
void UpdateCurrentTest() {
......@@ -276,8 +269,8 @@ class Simulator {
FILE* f = base::OpenFile(output_path_, "w");
if (!f) {
LOG(ERROR) << "Failed to open output file " <<
output_path_.LossyDisplayName();
LOG(ERROR) << "Failed to open output file "
<< output_path_.LossyDisplayName();
exit(-1);
}
......@@ -338,7 +331,7 @@ class Simulator {
}
// Simulation task list for this execution
RenderModelSimulator* current_sim_;
std::unique_ptr<RenderModelSimulator> current_sim_;
queue<SimulationSpecification> sims_remaining_;
queue<SimulationSpecification> sims_completed_;
base::FilePath output_path_;
......
......@@ -39,11 +39,11 @@ class ForwardRenderNodeVisitor : public RenderNodeVisitor {
}
};
ForwardRenderSimulator::ForwardRenderSimulator(RenderNode* root,
ForwardRenderSimulator::ForwardRenderSimulator(std::unique_ptr<RenderNode> root,
int window_width,
int window_height)
: RenderModelSimulator(root) {
textures_.reset(new TextureGenerator(root));
: RenderModelSimulator(std::move(root)) {
textures_.reset(new TextureGenerator(root_.get()));
visitor_.reset(new ForwardRenderNodeVisitor());
glViewport(0, 0, window_width, window_height);
glDisable(GL_DEPTH_TEST);
......
......@@ -17,9 +17,9 @@ class ForwardRenderNodeVisitor;
class ForwardRenderSimulator : public RenderModelSimulator {
public:
explicit ForwardRenderSimulator(RenderNode* root,
int window_width,
int window_height);
ForwardRenderSimulator(std::unique_ptr<RenderNode> root,
int window_width,
int window_height);
~ForwardRenderSimulator() override;
void Update() override;
void Resize(int width, int height) override;
......
......@@ -5,7 +5,9 @@
#include "gpu/tools/compositor_model_bench/render_models.h"
#include <string>
#include <utility>
#include "base/memory/ptr_util.h"
#include "gpu/tools/compositor_model_bench/forward_render_model.h"
const char* ModelToString(RenderModel m) {
......@@ -17,25 +19,24 @@ const char* ModelToString(RenderModel m) {
}
}
RenderModelSimulator::RenderModelSimulator(RenderNode* root) : root_(root) {
}
RenderModelSimulator::RenderModelSimulator(std::unique_ptr<RenderNode> root)
: root_(std::move(root)) {}
RenderModelSimulator::~RenderModelSimulator() {
}
RenderModelSimulator* ConstructSimulationModel(RenderModel model,
RenderNode* render_tree_root,
int window_width,
int window_height) {
std::unique_ptr<RenderModelSimulator> ConstructSimulationModel(
RenderModel model,
std::unique_ptr<RenderNode> render_tree_root,
int window_width,
int window_height) {
switch (model) {
case ForwardRenderModel:
return new ForwardRenderSimulator(render_tree_root,
window_width,
window_height);
return base::WrapUnique(new ForwardRenderSimulator(
std::move(render_tree_root), window_width, window_height));
default:
LOG(ERROR) << "Unrecognized render model. "
"If we know its name, then it's..." << ModelToString(model);
return 0;
return nullptr;
}
}
......@@ -26,17 +26,19 @@ class RenderModelSimulator {
virtual void Resize(int width, int height) = 0;
protected:
explicit RenderModelSimulator(RenderNode* root);
explicit RenderModelSimulator(std::unique_ptr<RenderNode> root);
std::unique_ptr<RenderNode> root_;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(RenderModelSimulator);
};
RenderModelSimulator* ConstructSimulationModel(RenderModel model,
RenderNode* render_tree_root,
int window_width,
int window_height);
std::unique_ptr<RenderModelSimulator> ConstructSimulationModel(
RenderModel model,
std::unique_ptr<RenderNode> render_tree_root,
int window_width,
int window_height);
#endif // GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_MODELS_H_
......@@ -208,7 +208,7 @@ class RenderNodeVisitor {
virtual void EndVisitCCNode(CCNode* v);
};
RenderNode* BuildRenderTreeFromFile(const base::FilePath& path);
std::unique_ptr<RenderNode> BuildRenderTreeFromFile(const base::FilePath& path);
#endif // GPU_TOOLS_COMPOSITOR_MODEL_BENCH_RENDER_TREE_H_
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