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

Unified Diff: cc/resources/picture.cc

Issue 18078003: Use factory for creating SkPicture from a stream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/picture.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture.cc
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc
index 86ed2e60d91d2b965c7a7d3656be3f927a5a08bb..491617a30df50031b3cc41aecc944990ae1af456 100644
--- a/cc/resources/picture.cc
+++ b/cc/resources/picture.cc
@@ -86,61 +86,56 @@ scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) {
return make_scoped_refptr(new Picture(layer_rect));
}
-scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) {
- bool success;
- scoped_refptr<Picture> picture =
- make_scoped_refptr(new Picture(value, &success));
- if (!success)
- picture = NULL;
- return picture;
-}
-
Picture::Picture(gfx::Rect layer_rect)
: layer_rect_(layer_rect) {
// Instead of recording a trace event for object creation here, we wait for
// the picture to be recorded in Picture::Record.
}
-Picture::Picture(const base::Value* raw_value, bool* success) {
+scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) {
const base::DictionaryValue* value = NULL;
- if (!raw_value->GetAsDictionary(&value)) {
- *success = false;
- return;
- }
+ if (!raw_value->GetAsDictionary(&value))
+ return NULL;
// Decode the picture from base64.
std::string encoded;
- if (!value->GetString("skp64", &encoded)) {
- *success = false;
- return;
- }
+ if (!value->GetString("skp64", &encoded))
+ return NULL;
std::string decoded;
base::Base64Decode(encoded, &decoded);
SkMemoryStream stream(decoded.data(), decoded.size());
- const base::Value* layer_rect = NULL;
- if (!value->Get("params.layer_rect", &layer_rect)) {
- *success = false;
- return;
- }
- if (!MathUtil::FromValue(layer_rect, &layer_rect_)) {
- *success = false;
- return;
- }
+ const base::Value* layer_rect_value = NULL;
+ if (!value->Get("params.layer_rect", &layer_rect_value))
+ return NULL;
- const base::Value* opaque_rect = NULL;
- if (!value->Get("params.opaque_rect", &opaque_rect)) {
- *success = false;
- return;
- }
- if (!MathUtil::FromValue(opaque_rect, &opaque_rect_)) {
- *success = false;
- return;
- }
+ gfx::Rect layer_rect;
+ if (!MathUtil::FromValue(layer_rect_value, &layer_rect))
+ return NULL;
+
+ const base::Value* opaque_rect_value = NULL;
+ if (!value->Get("params.opaque_rect", &opaque_rect_value))
+ return NULL;
+
+ gfx::Rect opaque_rect;
+ if (!MathUtil::FromValue(opaque_rect_value, &opaque_rect))
+ return NULL;
// Read the picture. This creates an empty picture on failure.
- picture_ = skia::AdoptRef(new SkPicture(&stream, success, &DecodeBitmap));
+ SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap);
+ if (skpicture == NULL)
+ return NULL;
+
+ return make_scoped_refptr(new Picture(skpicture, layer_rect, opaque_rect));
+}
+
+Picture::Picture(SkPicture* picture,
+ gfx::Rect layer_rect,
+ gfx::Rect opaque_rect) :
+ layer_rect_(layer_rect),
+ opaque_rect_(opaque_rect),
+ picture_(skia::AdoptRef(picture)) {
}
Picture::Picture(const skia::RefPtr<SkPicture>& picture,
« no previous file with comments | « cc/resources/picture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698