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

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