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

Side by Side 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: Respond to comments. Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « cc/resources/picture.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/resources/picture.h" 5 #include "cc/resources/picture.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 return false; 80 return false;
81 } 81 }
82 82
83 } // namespace 83 } // namespace
84 84
85 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) { 85 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) {
86 return make_scoped_refptr(new Picture(layer_rect)); 86 return make_scoped_refptr(new Picture(layer_rect));
87 } 87 }
88 88
89 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) {
90 bool success;
91 scoped_refptr<Picture> picture =
92 make_scoped_refptr(new Picture(value, &success));
93 if (!success)
94 picture = NULL;
95 return picture;
96 }
97
98 Picture::Picture(gfx::Rect layer_rect) 89 Picture::Picture(gfx::Rect layer_rect)
99 : layer_rect_(layer_rect) { 90 : layer_rect_(layer_rect) {
100 // Instead of recording a trace event for object creation here, we wait for 91 // Instead of recording a trace event for object creation here, we wait for
101 // the picture to be recorded in Picture::Record. 92 // the picture to be recorded in Picture::Record.
102 } 93 }
103 94
104 Picture::Picture(const base::Value* raw_value, bool* success) { 95 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) {
105 const base::DictionaryValue* value = NULL; 96 const base::DictionaryValue* value = NULL;
106 if (!raw_value->GetAsDictionary(&value)) { 97 if (!raw_value->GetAsDictionary(&value)) {
vmpstr 2013/06/27 17:22:53 nit: you don't need braces here and below (where t
scroggo 2013/06/27 18:28:59 Done.
107 *success = false; 98 return NULL;
108 return;
109 } 99 }
110 100
111 // Decode the picture from base64. 101 // Decode the picture from base64.
112 std::string encoded; 102 std::string encoded;
113 if (!value->GetString("skp64", &encoded)) { 103 if (!value->GetString("skp64", &encoded)) {
114 *success = false; 104 return NULL;
115 return;
116 } 105 }
117 106
118 std::string decoded; 107 std::string decoded;
119 base::Base64Decode(encoded, &decoded); 108 base::Base64Decode(encoded, &decoded);
120 SkMemoryStream stream(decoded.data(), decoded.size()); 109 SkMemoryStream stream(decoded.data(), decoded.size());
121 110
122 const base::Value* layer_rect = NULL; 111 const base::Value* layer_rect_value = NULL;
123 if (!value->Get("params.layer_rect", &layer_rect)) { 112 if (!value->Get("params.layer_rect", &layer_rect_value)) {
124 *success = false; 113 return NULL;
125 return;
126 }
127 if (!MathUtil::FromValue(layer_rect, &layer_rect_)) {
128 *success = false;
129 return;
130 } 114 }
131 115
132 const base::Value* opaque_rect = NULL; 116 gfx::Rect layer_rect;
133 if (!value->Get("params.opaque_rect", &opaque_rect)) { 117 if (!MathUtil::FromValue(layer_rect_value, &layer_rect)) {
134 *success = false; 118 return NULL;
135 return;
136 } 119 }
137 if (!MathUtil::FromValue(opaque_rect, &opaque_rect_)) { 120
138 *success = false; 121 const base::Value* opaque_rect_value = NULL;
139 return; 122 if (!value->Get("params.opaque_rect", &opaque_rect_value)) {
123 return NULL;
124 }
125
126 gfx::Rect opaque_rect;
127 if (!MathUtil::FromValue(opaque_rect_value, &opaque_rect)) {
128 return NULL;
140 } 129 }
141 130
142 // Read the picture. This creates an empty picture on failure. 131 // Read the picture. This creates an empty picture on failure.
143 picture_ = skia::AdoptRef(new SkPicture(&stream, success, &DecodeBitmap)); 132 SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap);
133 if (NULL == skpicture) {
vmpstr 2013/06/27 17:22:53 nit: I think we typically do the skpicture == NULL
scroggo 2013/06/27 18:28:59 Done.
134 return NULL;
135 }
136 return make_scoped_refptr(new Picture(skpicture, layer_rect, opaque_rect));
137 }
138
139 Picture::Picture(SkPicture* picture,
140 gfx::Rect layer_rect,
141 gfx::Rect opaque_rect) :
142 layer_rect_(layer_rect),
143 opaque_rect_(opaque_rect),
144 picture_(skia::AdoptRef(picture)) {
144 } 145 }
145 146
146 Picture::Picture(const skia::RefPtr<SkPicture>& picture, 147 Picture::Picture(const skia::RefPtr<SkPicture>& picture,
147 gfx::Rect layer_rect, 148 gfx::Rect layer_rect,
148 gfx::Rect opaque_rect, 149 gfx::Rect opaque_rect,
149 const PixelRefMap& pixel_refs) : 150 const PixelRefMap& pixel_refs) :
150 layer_rect_(layer_rect), 151 layer_rect_(layer_rect),
151 opaque_rect_(opaque_rect), 152 opaque_rect_(opaque_rect),
152 picture_(picture), 153 picture_(picture),
153 pixel_refs_(pixel_refs) { 154 pixel_refs_(pixel_refs) {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); 449 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release());
449 raster_data->SetDouble("scale", scale); 450 raster_data->SetDouble("scale", scale);
450 raster_data->SetDouble("rect_x", rect.x()); 451 raster_data->SetDouble("rect_x", rect.x());
451 raster_data->SetDouble("rect_y", rect.y()); 452 raster_data->SetDouble("rect_y", rect.y());
452 raster_data->SetDouble("rect_width", rect.width()); 453 raster_data->SetDouble("rect_width", rect.width());
453 raster_data->SetDouble("rect_height", rect.height()); 454 raster_data->SetDouble("rect_height", rect.height());
454 return TracedValue::FromValue(raster_data.release()); 455 return TracedValue::FromValue(raster_data.release());
455 } 456 }
456 457
457 } // namespace cc 458 } // namespace cc
OLDNEW
« 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