OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/gpu/gpu_benchmarking_extension.h" | 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "gin/handle.h" | 27 #include "gin/handle.h" |
28 #include "gin/object_template_builder.h" | 28 #include "gin/object_template_builder.h" |
29 #include "third_party/WebKit/public/web/WebImageCache.h" | 29 #include "third_party/WebKit/public/web/WebImageCache.h" |
30 #include "third_party/WebKit/public/web/WebKit.h" | 30 #include "third_party/WebKit/public/web/WebKit.h" |
31 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
32 #include "third_party/WebKit/public/web/WebView.h" | 32 #include "third_party/WebKit/public/web/WebView.h" |
33 #include "third_party/skia/include/core/SkData.h" | 33 #include "third_party/skia/include/core/SkData.h" |
34 #include "third_party/skia/include/core/SkGraphics.h" | 34 #include "third_party/skia/include/core/SkGraphics.h" |
35 #include "third_party/skia/include/core/SkPicture.h" | 35 #include "third_party/skia/include/core/SkPicture.h" |
36 #include "third_party/skia/include/core/SkPixelRef.h" | 36 #include "third_party/skia/include/core/SkPixelRef.h" |
| 37 #include "third_party/skia/include/core/SkPixelSerializer.h" |
37 #include "third_party/skia/include/core/SkStream.h" | 38 #include "third_party/skia/include/core/SkStream.h" |
38 #include "ui/gfx/codec/png_codec.h" | 39 #include "ui/gfx/codec/png_codec.h" |
39 #include "v8/include/v8.h" | 40 #include "v8/include/v8.h" |
40 | 41 |
41 using blink::WebCanvas; | 42 using blink::WebCanvas; |
42 using blink::WebLocalFrame; | 43 using blink::WebLocalFrame; |
43 using blink::WebImageCache; | 44 using blink::WebImageCache; |
44 using blink::WebPrivatePtr; | 45 using blink::WebPrivatePtr; |
45 using blink::WebSize; | 46 using blink::WebSize; |
46 using blink::WebView; | 47 using blink::WebView; |
47 | 48 |
48 namespace content { | 49 namespace content { |
49 | 50 |
50 namespace { | 51 namespace { |
51 | 52 |
52 // offset parameter is deprecated/ignored, and will be remove from the | 53 class PNGSerializer : public SkPixelSerializer { |
53 // signature in a future skia release. <reed@google.com> | 54 protected: |
54 SkData* EncodeBitmapToData(size_t* offset, const SkBitmap& bm) { | 55 bool onUseEncodedData(const void* data, size_t len) override { return true; } |
55 SkPixelRef* pr = bm.pixelRef(); | 56 |
56 if (pr != NULL) { | 57 SkData* onEncodePixels(const SkImageInfo& info, |
57 SkData* data = pr->refEncodedData(); | 58 const void* pixels, |
58 if (data != NULL) | 59 size_t row_bytes) override { |
59 return data; | 60 SkBitmap bm; |
| 61 // The const_cast is fine, since we only read from the bitmap. |
| 62 if (bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) { |
| 63 std::vector<unsigned char> vector; |
| 64 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { |
| 65 return SkData::NewWithCopy(&vector.front(), vector.size()); |
| 66 } |
| 67 } |
| 68 return nullptr; |
60 } | 69 } |
61 std::vector<unsigned char> vector; | 70 }; |
62 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { | |
63 return SkData::NewWithCopy(&vector.front(), vector.size()); | |
64 } | |
65 return NULL; | |
66 } | |
67 | 71 |
68 class SkPictureSerializer { | 72 class SkPictureSerializer { |
69 public: | 73 public: |
70 explicit SkPictureSerializer(const base::FilePath& dirpath) | 74 explicit SkPictureSerializer(const base::FilePath& dirpath) |
71 : dirpath_(dirpath), | 75 : dirpath_(dirpath), |
72 layer_id_(0) { | 76 layer_id_(0) { |
73 // Let skia register known effect subclasses. This basically enables | 77 // Let skia register known effect subclasses. This basically enables |
74 // reflection on those subclasses required for picture serialization. | 78 // reflection on those subclasses required for picture serialization. |
75 SkiaBenchmarking::Initialize(); | 79 SkiaBenchmarking::Initialize(); |
76 } | 80 } |
(...skipping 13 matching lines...) Expand all Loading... |
90 | 94 |
91 // Serialize picture to file. | 95 // Serialize picture to file. |
92 // TODO(alokp): Note that for this to work Chrome needs to be launched with | 96 // TODO(alokp): Note that for this to work Chrome needs to be launched with |
93 // --no-sandbox command-line flag. Get rid of this limitation. | 97 // --no-sandbox command-line flag. Get rid of this limitation. |
94 // CRBUG: 139640. | 98 // CRBUG: 139640. |
95 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | 99 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
96 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | 100 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
97 DCHECK(!filepath.empty()); | 101 DCHECK(!filepath.empty()); |
98 SkFILEWStream file(filepath.c_str()); | 102 SkFILEWStream file(filepath.c_str()); |
99 DCHECK(file.isValid()); | 103 DCHECK(file.isValid()); |
100 picture->serialize(&file, &EncodeBitmapToData); | 104 |
| 105 PNGSerializer serializer; |
| 106 picture->serialize(&file, &serializer); |
101 } | 107 } |
102 | 108 |
103 private: | 109 private: |
104 base::FilePath dirpath_; | 110 base::FilePath dirpath_; |
105 int layer_id_; | 111 int layer_id_; |
106 }; | 112 }; |
107 | 113 |
108 template <typename T> | 114 template <typename T> |
109 bool GetArg(gin::Arguments* args, T* value) { | 115 bool GetArg(gin::Arguments* args, T* value) { |
110 if (!args->GetNext(value)) { | 116 if (!args->GetNext(value)) { |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 | 807 |
802 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); | 808 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); |
803 } | 809 } |
804 | 810 |
805 bool GpuBenchmarking::HasGpuProcess() { | 811 bool GpuBenchmarking::HasGpuProcess() { |
806 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); | 812 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); |
807 return !!gpu_channel; | 813 return !!gpu_channel; |
808 } | 814 } |
809 | 815 |
810 } // namespace content | 816 } // namespace content |
OLD | NEW |