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 { |
55 SkPixelRef* pr = bm.pixelRef(); | 56 // If its already encoded, we are fine with that. |
56 if (pr != NULL) { | 57 return true; |
57 SkData* data = pr->refEncodedData(); | |
58 if (data != NULL) | |
59 return data; | |
60 } | 58 } |
61 std::vector<unsigned char> vector; | 59 |
62 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { | 60 SkData* onEncodePixels(const SkImageInfo& info, |
63 return SkData::NewWithCopy(&vector.front(), vector.size()); | 61 void* pixels, |
62 size_t rowBytes) override { | |
piman
2014/12/19 20:21:42
nit: row_bytes
reed1
2014/12/19 21:30:02
Done.
| |
63 SkBitmap bm; | |
64 // The const_cast is fine, since we only read from the bitmap. | |
65 if (bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) { | |
piman
2014/12/19 20:21:42
nit: no need for const_cast, pixels is already non
reed1
2014/12/19 21:30:02
A pending change in skia will require this cast (t
| |
66 std::vector<unsigned char> vector; | |
67 if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { | |
68 return SkData::NewWithCopy(&vector.front(), vector.size()); | |
69 } | |
70 } | |
71 return NULL; | |
64 } | 72 } |
65 return NULL; | 73 }; |
66 } | |
67 | 74 |
68 class SkPictureSerializer { | 75 class SkPictureSerializer { |
69 public: | 76 public: |
70 explicit SkPictureSerializer(const base::FilePath& dirpath) | 77 explicit SkPictureSerializer(const base::FilePath& dirpath) |
71 : dirpath_(dirpath), | 78 : dirpath_(dirpath), |
72 layer_id_(0) { | 79 layer_id_(0) { |
73 // Let skia register known effect subclasses. This basically enables | 80 // Let skia register known effect subclasses. This basically enables |
74 // reflection on those subclasses required for picture serialization. | 81 // reflection on those subclasses required for picture serialization. |
75 SkiaBenchmarking::Initialize(); | 82 SkiaBenchmarking::Initialize(); |
76 } | 83 } |
(...skipping 13 matching lines...) Expand all Loading... | |
90 | 97 |
91 // Serialize picture to file. | 98 // Serialize picture to file. |
92 // TODO(alokp): Note that for this to work Chrome needs to be launched with | 99 // 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. | 100 // --no-sandbox command-line flag. Get rid of this limitation. |
94 // CRBUG: 139640. | 101 // CRBUG: 139640. |
95 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; | 102 std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp"; |
96 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); | 103 std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII(); |
97 DCHECK(!filepath.empty()); | 104 DCHECK(!filepath.empty()); |
98 SkFILEWStream file(filepath.c_str()); | 105 SkFILEWStream file(filepath.c_str()); |
99 DCHECK(file.isValid()); | 106 DCHECK(file.isValid()); |
100 picture->serialize(&file, &EncodeBitmapToData); | 107 |
108 PNGSerializer serializer; | |
109 picture->serialize(&file, &serializer); | |
101 } | 110 } |
102 | 111 |
103 private: | 112 private: |
104 base::FilePath dirpath_; | 113 base::FilePath dirpath_; |
105 int layer_id_; | 114 int layer_id_; |
106 }; | 115 }; |
107 | 116 |
108 template <typename T> | 117 template <typename T> |
109 bool GetArg(gin::Arguments* args, T* value) { | 118 bool GetArg(gin::Arguments* args, T* value) { |
110 if (!args->GetNext(value)) { | 119 if (!args->GetNext(value)) { |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 | 810 |
802 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); | 811 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); |
803 } | 812 } |
804 | 813 |
805 bool GpuBenchmarking::HasGpuProcess() { | 814 bool GpuBenchmarking::HasGpuProcess() { |
806 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); | 815 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); |
807 return !!gpu_channel; | 816 return !!gpu_channel; |
808 } | 817 } |
809 | 818 |
810 } // namespace content | 819 } // namespace content |
OLD | NEW |