OLD | NEW |
---|---|
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 Loading... | |
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) { |
96 scoped_refptr<Picture> picture(NULL); | |
105 const base::DictionaryValue* value = NULL; | 97 const base::DictionaryValue* value = NULL; |
106 if (!raw_value->GetAsDictionary(&value)) { | 98 if (!raw_value->GetAsDictionary(&value)) { |
107 *success = false; | 99 return picture; |
vmpstr
2013/06/27 16:23:44
Can you return NULL here explicitly and declare |p
scroggo
2013/06/27 16:45:45
Done.
| |
108 return; | |
109 } | 100 } |
110 | 101 |
111 // Decode the picture from base64. | 102 // Decode the picture from base64. |
112 std::string encoded; | 103 std::string encoded; |
113 if (!value->GetString("skp64", &encoded)) { | 104 if (!value->GetString("skp64", &encoded)) { |
114 *success = false; | 105 return picture; |
115 return; | |
116 } | 106 } |
117 | 107 |
118 std::string decoded; | 108 std::string decoded; |
119 base::Base64Decode(encoded, &decoded); | 109 base::Base64Decode(encoded, &decoded); |
120 SkMemoryStream stream(decoded.data(), decoded.size()); | 110 SkMemoryStream stream(decoded.data(), decoded.size()); |
121 | 111 |
122 const base::Value* layer_rect = NULL; | 112 const base::Value* layer_rect_value = NULL; |
123 if (!value->Get("params.layer_rect", &layer_rect)) { | 113 if (!value->Get("params.layer_rect", &layer_rect_value)) { |
124 *success = false; | 114 return picture; |
125 return; | |
126 } | |
127 if (!MathUtil::FromValue(layer_rect, &layer_rect_)) { | |
128 *success = false; | |
129 return; | |
130 } | 115 } |
131 | 116 |
132 const base::Value* opaque_rect = NULL; | 117 gfx::Rect layer_rect; |
133 if (!value->Get("params.opaque_rect", &opaque_rect)) { | 118 if (!MathUtil::FromValue(layer_rect_value, &layer_rect)) { |
134 *success = false; | 119 return picture; |
135 return; | |
136 } | 120 } |
137 if (!MathUtil::FromValue(opaque_rect, &opaque_rect_)) { | 121 |
138 *success = false; | 122 const base::Value* opaque_rect_value = NULL; |
139 return; | 123 if (!value->Get("params.opaque_rect", &opaque_rect_value)) { |
124 return picture; | |
125 } | |
126 | |
127 gfx::Rect opaque_rect; | |
128 if (!MathUtil::FromValue(opaque_rect_value, &opaque_rect)) { | |
129 return picture; | |
140 } | 130 } |
141 | 131 |
142 // Read the picture. This creates an empty picture on failure. | 132 // Read the picture. This creates an empty picture on failure. |
143 picture_ = skia::AdoptRef(new SkPicture(&stream, success, &DecodeBitmap)); | 133 picture = new Picture(SkPicture::CreateFromStream(&stream, &DecodeBitmap), |
vmpstr
2013/06/27 16:23:44
What does CreateFromStream return in case of failu
scroggo
2013/06/27 16:45:45
NULL.
| |
134 layer_rect, opaque_rect); | |
135 return picture; | |
136 } | |
137 | |
138 Picture::Picture(SkPicture* picture, | |
139 gfx::Rect layer_rect, | |
140 gfx::Rect opaque_rect) : | |
141 layer_rect_(layer_rect), | |
142 opaque_rect_(opaque_rect), | |
143 picture_(skia::AdoptRef(picture)) { | |
144 } | 144 } |
145 | 145 |
146 Picture::Picture(const skia::RefPtr<SkPicture>& picture, | 146 Picture::Picture(const skia::RefPtr<SkPicture>& picture, |
147 gfx::Rect layer_rect, | 147 gfx::Rect layer_rect, |
148 gfx::Rect opaque_rect, | 148 gfx::Rect opaque_rect, |
149 const PixelRefMap& pixel_refs) : | 149 const PixelRefMap& pixel_refs) : |
150 layer_rect_(layer_rect), | 150 layer_rect_(layer_rect), |
151 opaque_rect_(opaque_rect), | 151 opaque_rect_(opaque_rect), |
152 picture_(picture), | 152 picture_(picture), |
153 pixel_refs_(pixel_refs) { | 153 pixel_refs_(pixel_refs) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); | 448 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); |
449 raster_data->SetDouble("scale", scale); | 449 raster_data->SetDouble("scale", scale); |
450 raster_data->SetDouble("rect_x", rect.x()); | 450 raster_data->SetDouble("rect_x", rect.x()); |
451 raster_data->SetDouble("rect_y", rect.y()); | 451 raster_data->SetDouble("rect_y", rect.y()); |
452 raster_data->SetDouble("rect_width", rect.width()); | 452 raster_data->SetDouble("rect_width", rect.width()); |
453 raster_data->SetDouble("rect_height", rect.height()); | 453 raster_data->SetDouble("rect_height", rect.height()); |
454 return TracedValue::FromValue(raster_data.release()); | 454 return TracedValue::FromValue(raster_data.release()); |
455 } | 455 } |
456 | 456 |
457 } // namespace cc | 457 } // namespace cc |
OLD | NEW |