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

Side by Side Diff: gpu/command_buffer/service/gpu_state_tracer.cc

Issue 1717283003: tracing: Make ConvertableToTraceFormat move-only scoped_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "gpu/command_buffer/service/gpu_state_tracer.h" 5 #include "gpu/command_buffer/service/gpu_state_tracer.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "context_state.h" 10 #include "context_state.h"
11 #include "ui/gfx/codec/png_codec.h" 11 #include "ui/gfx/codec/png_codec.h"
12 #include "ui/gl/gl_bindings.h" 12 #include "ui/gl/gl_bindings.h"
13 13
14 namespace gpu { 14 namespace gpu {
15 namespace gles2 { 15 namespace gles2 {
16 namespace { 16 namespace {
17 17
18 const int kBytesPerPixel = 4; 18 const int kBytesPerPixel = 4;
19 19
20 class Snapshot : public base::trace_event::ConvertableToTraceFormat { 20 class Snapshot : public base::trace_event::ConvertableToTraceFormat {
21 public: 21 public:
22 static scoped_refptr<Snapshot> Create(const ContextState* state); 22 static scoped_ptr<Snapshot> Create(const ContextState* state);
23
24 ~Snapshot() override {}
23 25
24 // Save a screenshot of the currently bound framebuffer. 26 // Save a screenshot of the currently bound framebuffer.
25 bool SaveScreenshot(const gfx::Size& size); 27 bool SaveScreenshot(const gfx::Size& size);
26 28
27 // base::trace_event::ConvertableToTraceFormat implementation. 29 // base::trace_event::ConvertableToTraceFormat implementation.
28 void AppendAsTraceFormat(std::string* out) const override; 30 void AppendAsTraceFormat(std::string* out) const override;
29 31
30 private: 32 private:
31 explicit Snapshot(const ContextState* state); 33 explicit Snapshot(const ContextState* state);
32 ~Snapshot() override {}
33 34
34 const ContextState* state_; 35 const ContextState* state_;
35 36
36 std::vector<unsigned char> screenshot_pixels_; 37 std::vector<unsigned char> screenshot_pixels_;
37 gfx::Size screenshot_size_; 38 gfx::Size screenshot_size_;
38 39
39 DISALLOW_COPY_AND_ASSIGN(Snapshot); 40 DISALLOW_COPY_AND_ASSIGN(Snapshot);
40 }; 41 };
41 42
42 } // namespace 43 } // namespace
43 44
44 Snapshot::Snapshot(const ContextState* state) : state_(state) {} 45 Snapshot::Snapshot(const ContextState* state) : state_(state) {}
45 46
46 scoped_refptr<Snapshot> Snapshot::Create(const ContextState* state) { 47 scoped_ptr<Snapshot> Snapshot::Create(const ContextState* state) {
47 return scoped_refptr<Snapshot>(new Snapshot(state)); 48 return make_scoped_ptr(new Snapshot(state));
48 } 49 }
49 50
50 bool Snapshot::SaveScreenshot(const gfx::Size& size) { 51 bool Snapshot::SaveScreenshot(const gfx::Size& size) {
51 screenshot_size_ = size; 52 screenshot_size_ = size;
52 screenshot_pixels_.resize(screenshot_size_.width() * 53 screenshot_pixels_.resize(screenshot_size_.width() *
53 screenshot_size_.height() * kBytesPerPixel); 54 screenshot_size_.height() * kBytesPerPixel);
54 55
55 glPixelStorei(GL_PACK_ALIGNMENT, kBytesPerPixel); 56 glPixelStorei(GL_PACK_ALIGNMENT, kBytesPerPixel);
56 glReadPixels(0, 57 glReadPixels(0,
57 0, 58 0,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 110
110 GPUStateTracer::~GPUStateTracer() { 111 GPUStateTracer::~GPUStateTracer() {
111 TRACE_EVENT_OBJECT_DELETED_WITH_ID( 112 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
112 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), "gpu::State", state_); 113 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), "gpu::State", state_);
113 } 114 }
114 115
115 void GPUStateTracer::TakeSnapshotWithCurrentFramebuffer(const gfx::Size& size) { 116 void GPUStateTracer::TakeSnapshotWithCurrentFramebuffer(const gfx::Size& size) {
116 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), 117 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("gpu.debug"),
117 "GPUStateTracer::TakeSnapshotWithCurrentFramebuffer"); 118 "GPUStateTracer::TakeSnapshotWithCurrentFramebuffer");
118 119
119 scoped_refptr<Snapshot> snapshot(Snapshot::Create(state_)); 120 scoped_ptr<Snapshot> snapshot(Snapshot::Create(state_));
120 121
121 // Only save a screenshot for now. 122 // Only save a screenshot for now.
122 if (!snapshot->SaveScreenshot(size)) 123 if (!snapshot->SaveScreenshot(size))
123 return; 124 return;
124 125
125 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 126 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("gpu.debug"),
126 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), 127 "gpu::State", state_,
127 "gpu::State", 128 std::move(snapshot));
128 state_,
129 scoped_refptr<base::trace_event::ConvertableToTraceFormat>(snapshot));
130 } 129 }
131 130
132 } // namespace gles2 131 } // namespace gles2
133 } // namespace gpu 132 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698