OLD | NEW |
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/memory/ptr_util.h" |
9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
10 #include "context_state.h" | 11 #include "context_state.h" |
11 #include "ui/gfx/codec/png_codec.h" | 12 #include "ui/gfx/codec/png_codec.h" |
12 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
13 | 14 |
14 namespace gpu { | 15 namespace gpu { |
15 namespace gles2 { | 16 namespace gles2 { |
16 namespace { | 17 namespace { |
17 | 18 |
18 const int kBytesPerPixel = 4; | 19 const int kBytesPerPixel = 4; |
19 | 20 |
20 class Snapshot : public base::trace_event::ConvertableToTraceFormat { | 21 class Snapshot : public base::trace_event::ConvertableToTraceFormat { |
21 public: | 22 public: |
22 static scoped_ptr<Snapshot> Create(const ContextState* state); | 23 static std::unique_ptr<Snapshot> Create(const ContextState* state); |
23 | 24 |
24 ~Snapshot() override {} | 25 ~Snapshot() override {} |
25 | 26 |
26 // Save a screenshot of the currently bound framebuffer. | 27 // Save a screenshot of the currently bound framebuffer. |
27 bool SaveScreenshot(const gfx::Size& size); | 28 bool SaveScreenshot(const gfx::Size& size); |
28 | 29 |
29 // base::trace_event::ConvertableToTraceFormat implementation. | 30 // base::trace_event::ConvertableToTraceFormat implementation. |
30 void AppendAsTraceFormat(std::string* out) const override; | 31 void AppendAsTraceFormat(std::string* out) const override; |
31 | 32 |
32 private: | 33 private: |
33 explicit Snapshot(const ContextState* state); | 34 explicit Snapshot(const ContextState* state); |
34 | 35 |
35 const ContextState* state_; | 36 const ContextState* state_; |
36 | 37 |
37 std::vector<unsigned char> screenshot_pixels_; | 38 std::vector<unsigned char> screenshot_pixels_; |
38 gfx::Size screenshot_size_; | 39 gfx::Size screenshot_size_; |
39 | 40 |
40 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 41 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
41 }; | 42 }; |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 Snapshot::Snapshot(const ContextState* state) : state_(state) {} | 46 Snapshot::Snapshot(const ContextState* state) : state_(state) {} |
46 | 47 |
47 scoped_ptr<Snapshot> Snapshot::Create(const ContextState* state) { | 48 std::unique_ptr<Snapshot> Snapshot::Create(const ContextState* state) { |
48 return make_scoped_ptr(new Snapshot(state)); | 49 return base::WrapUnique(new Snapshot(state)); |
49 } | 50 } |
50 | 51 |
51 bool Snapshot::SaveScreenshot(const gfx::Size& size) { | 52 bool Snapshot::SaveScreenshot(const gfx::Size& size) { |
52 screenshot_size_ = size; | 53 screenshot_size_ = size; |
53 screenshot_pixels_.resize(screenshot_size_.width() * | 54 screenshot_pixels_.resize(screenshot_size_.width() * |
54 screenshot_size_.height() * kBytesPerPixel); | 55 screenshot_size_.height() * kBytesPerPixel); |
55 | 56 |
56 glPixelStorei(GL_PACK_ALIGNMENT, kBytesPerPixel); | 57 glPixelStorei(GL_PACK_ALIGNMENT, kBytesPerPixel); |
57 glReadPixels(0, | 58 glReadPixels(0, |
58 0, | 59 0, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 base::StringPiece base64_input(reinterpret_cast<const char*>(&png_data[0]), | 93 base::StringPiece base64_input(reinterpret_cast<const char*>(&png_data[0]), |
93 png_data.size()); | 94 png_data.size()); |
94 std::string base64_output; | 95 std::string base64_output; |
95 Base64Encode(base64_input, &base64_output); | 96 Base64Encode(base64_input, &base64_output); |
96 | 97 |
97 *out += "\"screenshot\":\"" + base64_output + "\""; | 98 *out += "\"screenshot\":\"" + base64_output + "\""; |
98 } | 99 } |
99 *out += "}"; | 100 *out += "}"; |
100 } | 101 } |
101 | 102 |
102 scoped_ptr<GPUStateTracer> GPUStateTracer::Create(const ContextState* state) { | 103 std::unique_ptr<GPUStateTracer> GPUStateTracer::Create( |
103 return scoped_ptr<GPUStateTracer>(new GPUStateTracer(state)); | 104 const ContextState* state) { |
| 105 return std::unique_ptr<GPUStateTracer>(new GPUStateTracer(state)); |
104 } | 106 } |
105 | 107 |
106 GPUStateTracer::GPUStateTracer(const ContextState* state) : state_(state) { | 108 GPUStateTracer::GPUStateTracer(const ContextState* state) : state_(state) { |
107 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 109 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
108 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), "gpu::State", state_); | 110 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), "gpu::State", state_); |
109 } | 111 } |
110 | 112 |
111 GPUStateTracer::~GPUStateTracer() { | 113 GPUStateTracer::~GPUStateTracer() { |
112 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 114 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
113 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), "gpu::State", state_); | 115 TRACE_DISABLED_BY_DEFAULT("gpu.debug"), "gpu::State", state_); |
114 } | 116 } |
115 | 117 |
116 void GPUStateTracer::TakeSnapshotWithCurrentFramebuffer(const gfx::Size& size) { | 118 void GPUStateTracer::TakeSnapshotWithCurrentFramebuffer(const gfx::Size& size) { |
117 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), | 119 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
118 "GPUStateTracer::TakeSnapshotWithCurrentFramebuffer"); | 120 "GPUStateTracer::TakeSnapshotWithCurrentFramebuffer"); |
119 | 121 |
120 scoped_ptr<Snapshot> snapshot(Snapshot::Create(state_)); | 122 std::unique_ptr<Snapshot> snapshot(Snapshot::Create(state_)); |
121 | 123 |
122 // Only save a screenshot for now. | 124 // Only save a screenshot for now. |
123 if (!snapshot->SaveScreenshot(size)) | 125 if (!snapshot->SaveScreenshot(size)) |
124 return; | 126 return; |
125 | 127 |
126 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), | 128 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
127 "gpu::State", state_, | 129 "gpu::State", state_, |
128 std::move(snapshot)); | 130 std::move(snapshot)); |
129 } | 131 } |
130 | 132 |
131 } // namespace gles2 | 133 } // namespace gles2 |
132 } // namespace gpu | 134 } // namespace gpu |
OLD | NEW |