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

Side by Side Diff: content/renderer/skia_benchmarking_extension.cc

Issue 1823133002: Use sk_sp-based picture recording APIs in Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android_webview 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/renderer/skia_benchmarking_extension.h" 5 #include "content/renderer/skia_benchmarking_extension.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 22 matching lines...) Expand all
33 #include "ui/gfx/skia_util.h" 33 #include "ui/gfx/skia_util.h"
34 #include "v8/include/v8.h" 34 #include "v8/include/v8.h"
35 35
36 namespace content { 36 namespace content {
37 37
38 namespace { 38 namespace {
39 39
40 class Picture { 40 class Picture {
41 public: 41 public:
42 gfx::Rect layer_rect; 42 gfx::Rect layer_rect;
43 skia::RefPtr<SkPicture> picture; 43 skia::RefPtr<SkPicture> picture;
tomhudson 2016/03/24 19:52:40 We could change this to sk_sp<>?
f(malita) 2016/03/24 20:22:41 Good point, it's a local type. Done.
44 }; 44 };
45 45
46 bool DecodeBitmap(const void* buffer, size_t size, SkBitmap* bm) { 46 bool DecodeBitmap(const void* buffer, size_t size, SkBitmap* bm) {
47 const unsigned char* data = static_cast<const unsigned char*>(buffer); 47 const unsigned char* data = static_cast<const unsigned char*>(buffer);
48 // Try PNG first. 48 // Try PNG first.
49 if (gfx::PNGCodec::Decode(data, size, bm)) 49 if (gfx::PNGCodec::Decode(data, size, bm))
50 return true; 50 return true;
51 // Try JPEG. 51 // Try JPEG.
52 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size)); 52 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size));
53 if (decoded_jpeg) { 53 if (decoded_jpeg) {
54 *bm = *decoded_jpeg; 54 *bm = *decoded_jpeg;
55 return true; 55 return true;
56 } 56 }
57 return false; 57 return false;
58 } 58 }
59 59
60 scoped_ptr<base::Value> ParsePictureArg(v8::Isolate* isolate, 60 scoped_ptr<base::Value> ParsePictureArg(v8::Isolate* isolate,
61 v8::Local<v8::Value> arg) { 61 v8::Local<v8::Value> arg) {
62 scoped_ptr<content::V8ValueConverter> converter( 62 scoped_ptr<content::V8ValueConverter> converter(
63 content::V8ValueConverter::create()); 63 content::V8ValueConverter::create());
64 return scoped_ptr<base::Value>( 64 return scoped_ptr<base::Value>(
65 converter->FromV8Value(arg, isolate->GetCurrentContext())); 65 converter->FromV8Value(arg, isolate->GetCurrentContext()));
66 } 66 }
67 67
68 scoped_ptr<Picture> CreatePictureFromEncodedString(const std::string& encoded) { 68 scoped_ptr<Picture> CreatePictureFromEncodedString(const std::string& encoded) {
69 std::string decoded; 69 std::string decoded;
70 base::Base64Decode(encoded, &decoded); 70 base::Base64Decode(encoded, &decoded);
71 SkMemoryStream stream(decoded.data(), decoded.size()); 71 SkMemoryStream stream(decoded.data(), decoded.size());
72 72
73 SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap); 73 sk_sp<SkPicture> skpicture =
74 SkPicture::MakeFromStream(&stream, &DecodeBitmap);
74 if (!skpicture) 75 if (!skpicture)
75 return nullptr; 76 return nullptr;
76 77
77 scoped_ptr<Picture> picture(new Picture); 78 scoped_ptr<Picture> picture(new Picture);
78 picture->layer_rect = gfx::SkIRectToRect(skpicture->cullRect().roundOut()); 79 picture->layer_rect = gfx::SkIRectToRect(skpicture->cullRect().roundOut());
79 picture->picture = skia::AdoptRef(skpicture); 80 picture->picture = skia::AdoptRef(std::move(skpicture));
80 return picture; 81 return picture;
81 } 82 }
82 83
83 scoped_ptr<Picture> ParsePictureStr(v8::Isolate* isolate, 84 scoped_ptr<Picture> ParsePictureStr(v8::Isolate* isolate,
84 v8::Local<v8::Value> arg) { 85 v8::Local<v8::Value> arg) {
85 scoped_ptr<base::Value> picture_value = ParsePictureArg(isolate, arg); 86 scoped_ptr<base::Value> picture_value = ParsePictureArg(isolate, arg);
86 if (!picture_value) 87 if (!picture_value)
87 return nullptr; 88 return nullptr;
88 // Decode the picture from base64. 89 // Decode the picture from base64.
89 std::string encoded; 90 std::string encoded;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 v8::Local<v8::Object> result = v8::Object::New(isolate); 332 v8::Local<v8::Object> result = v8::Object::New(isolate);
332 result->Set(v8::String::NewFromUtf8(isolate, "width"), 333 result->Set(v8::String::NewFromUtf8(isolate, "width"),
333 v8::Number::New(isolate, picture->layer_rect.width())); 334 v8::Number::New(isolate, picture->layer_rect.width()));
334 result->Set(v8::String::NewFromUtf8(isolate, "height"), 335 result->Set(v8::String::NewFromUtf8(isolate, "height"),
335 v8::Number::New(isolate, picture->layer_rect.height())); 336 v8::Number::New(isolate, picture->layer_rect.height()));
336 337
337 args->Return(result); 338 args->Return(result);
338 } 339 }
339 340
340 } // namespace content 341 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698