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

Side by Side Diff: cc/resources/picture.cc

Issue 563963002: cc: Remove opaque rect from cc::Picture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pictureopaque: Created 6 years, 3 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
« no previous file with comments | « cc/resources/picture.h ('k') | cc/resources/picture_unittest.cc » ('j') | 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 std::string decoded; 115 std::string decoded;
116 base::Base64Decode(encoded, &decoded); 116 base::Base64Decode(encoded, &decoded);
117 SkMemoryStream stream(decoded.data(), decoded.size()); 117 SkMemoryStream stream(decoded.data(), decoded.size());
118 118
119 // Read the picture. This creates an empty picture on failure. 119 // Read the picture. This creates an empty picture on failure.
120 SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap); 120 SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap);
121 if (skpicture == NULL) 121 if (skpicture == NULL)
122 return NULL; 122 return NULL;
123 123
124 gfx::Rect layer_rect(skpicture->width(), skpicture->height()); 124 gfx::Rect layer_rect(skpicture->width(), skpicture->height());
125 gfx::Rect opaque_rect(skpicture->width(), skpicture->height()); 125 return make_scoped_refptr(new Picture(skpicture, layer_rect));
126
127 return make_scoped_refptr(new Picture(skpicture, layer_rect, opaque_rect));
128 } 126 }
129 127
130 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) { 128 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) {
131 const base::DictionaryValue* value = NULL; 129 const base::DictionaryValue* value = NULL;
132 if (!raw_value->GetAsDictionary(&value)) 130 if (!raw_value->GetAsDictionary(&value))
133 return NULL; 131 return NULL;
134 132
135 // Decode the picture from base64. 133 // Decode the picture from base64.
136 std::string encoded; 134 std::string encoded;
137 if (!value->GetString("skp64", &encoded)) 135 if (!value->GetString("skp64", &encoded))
138 return NULL; 136 return NULL;
139 137
140 std::string decoded; 138 std::string decoded;
141 base::Base64Decode(encoded, &decoded); 139 base::Base64Decode(encoded, &decoded);
142 SkMemoryStream stream(decoded.data(), decoded.size()); 140 SkMemoryStream stream(decoded.data(), decoded.size());
143 141
144 const base::Value* layer_rect_value = NULL; 142 const base::Value* layer_rect_value = NULL;
145 if (!value->Get("params.layer_rect", &layer_rect_value)) 143 if (!value->Get("params.layer_rect", &layer_rect_value))
146 return NULL; 144 return NULL;
147 145
148 gfx::Rect layer_rect; 146 gfx::Rect layer_rect;
149 if (!MathUtil::FromValue(layer_rect_value, &layer_rect)) 147 if (!MathUtil::FromValue(layer_rect_value, &layer_rect))
150 return NULL; 148 return NULL;
151 149
152 const base::Value* opaque_rect_value = NULL;
153 if (!value->Get("params.opaque_rect", &opaque_rect_value))
154 return NULL;
155
156 gfx::Rect opaque_rect;
157 if (!MathUtil::FromValue(opaque_rect_value, &opaque_rect))
158 return NULL;
159
160 // Read the picture. This creates an empty picture on failure. 150 // Read the picture. This creates an empty picture on failure.
161 SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap); 151 SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap);
162 if (skpicture == NULL) 152 if (skpicture == NULL)
163 return NULL; 153 return NULL;
164 154
165 return make_scoped_refptr(new Picture(skpicture, layer_rect, opaque_rect)); 155 return make_scoped_refptr(new Picture(skpicture, layer_rect));
166 } 156 }
167 157
168 Picture::Picture(SkPicture* picture, 158 Picture::Picture(SkPicture* picture, const gfx::Rect& layer_rect)
169 const gfx::Rect& layer_rect, 159 : layer_rect_(layer_rect),
170 const gfx::Rect& opaque_rect) : 160 picture_(skia::AdoptRef(picture)),
171 layer_rect_(layer_rect), 161 cell_size_(layer_rect.size()) {
172 opaque_rect_(opaque_rect),
173 picture_(skia::AdoptRef(picture)),
174 cell_size_(layer_rect.size()) {
175 } 162 }
176 163
177 Picture::Picture(const skia::RefPtr<SkPicture>& picture, 164 Picture::Picture(const skia::RefPtr<SkPicture>& picture,
178 const gfx::Rect& layer_rect, 165 const gfx::Rect& layer_rect,
179 const gfx::Rect& opaque_rect,
180 const PixelRefMap& pixel_refs) : 166 const PixelRefMap& pixel_refs) :
181 layer_rect_(layer_rect), 167 layer_rect_(layer_rect),
182 opaque_rect_(opaque_rect),
183 picture_(picture), 168 picture_(picture),
184 pixel_refs_(pixel_refs), 169 pixel_refs_(pixel_refs),
185 cell_size_(layer_rect.size()) { 170 cell_size_(layer_rect.size()) {
186 } 171 }
187 172
188 Picture::~Picture() { 173 Picture::~Picture() {
189 TRACE_EVENT_OBJECT_DELETED_WITH_ID( 174 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
190 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::Picture", this); 175 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::Picture", this);
191 } 176 }
192 177
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 picture_ = skia::AdoptRef(recorder.endRecording()); 265 picture_ = skia::AdoptRef(recorder.endRecording());
281 DCHECK(picture_); 266 DCHECK(picture_);
282 267
283 if (recording) { 268 if (recording) {
284 // SkRecording requires it's the only one holding onto canvas before we 269 // SkRecording requires it's the only one holding onto canvas before we
285 // may call releasePlayback(). (This helps enforce thread-safety.) 270 // may call releasePlayback(). (This helps enforce thread-safety.)
286 canvas.clear(); 271 canvas.clear();
287 playback_.reset(recording->releasePlayback()); 272 playback_.reset(recording->releasePlayback());
288 } 273 }
289 274
290 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect);
291
292 EmitTraceSnapshot(); 275 EmitTraceSnapshot();
293 } 276 }
294 277
295 void Picture::GatherPixelRefs( 278 void Picture::GatherPixelRefs(
296 const SkTileGridFactory::TileGridInfo& tile_grid_info) { 279 const SkTileGridFactory::TileGridInfo& tile_grid_info) {
297 TRACE_EVENT2("cc", "Picture::GatherPixelRefs", 280 TRACE_EVENT2("cc", "Picture::GatherPixelRefs",
298 "width", layer_rect_.width(), 281 "width", layer_rect_.width(),
299 "height", layer_rect_.height()); 282 "height", layer_rect_.height());
300 283
301 DCHECK(picture_); 284 DCHECK(picture_);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 skia::RefPtr<SkPicture> picture(skia::AdoptRef(recorder.endRecording())); 393 skia::RefPtr<SkPicture> picture(skia::AdoptRef(recorder.endRecording()));
411 picture->serialize(&stream, &EncodeBitmap); 394 picture->serialize(&stream, &EncodeBitmap);
412 } else { 395 } else {
413 // Serialize the picture. 396 // Serialize the picture.
414 picture_->serialize(&stream, &EncodeBitmap); 397 picture_->serialize(&stream, &EncodeBitmap);
415 } 398 }
416 399
417 // Encode the picture as base64. 400 // Encode the picture as base64.
418 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 401 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
419 res->Set("params.layer_rect", MathUtil::AsValue(layer_rect_).release()); 402 res->Set("params.layer_rect", MathUtil::AsValue(layer_rect_).release());
420 res->Set("params.opaque_rect", MathUtil::AsValue(opaque_rect_).release());
421 403
422 size_t serialized_size = stream.bytesWritten(); 404 size_t serialized_size = stream.bytesWritten();
423 scoped_ptr<char[]> serialized_picture(new char[serialized_size]); 405 scoped_ptr<char[]> serialized_picture(new char[serialized_size]);
424 stream.copyTo(serialized_picture.get()); 406 stream.copyTo(serialized_picture.get());
425 std::string b64_picture; 407 std::string b64_picture;
426 base::Base64Encode(std::string(serialized_picture.get(), serialized_size), 408 base::Base64Encode(std::string(serialized_picture.get(), serialized_size),
427 &b64_picture); 409 &b64_picture);
428 res->SetString("skp64", b64_picture); 410 res->SetString("skp64", b64_picture);
429 return res.PassAs<base::Value>(); 411 return res.PassAs<base::Value>();
430 } 412 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 scoped_refptr<base::debug::TracedValue> record_data = 543 scoped_refptr<base::debug::TracedValue> record_data =
562 new base::debug::TracedValue(); 544 new base::debug::TracedValue();
563 TracedValue::SetIDRef(this, record_data.get(), "picture_id"); 545 TracedValue::SetIDRef(this, record_data.get(), "picture_id");
564 record_data->BeginArray("layer_rect"); 546 record_data->BeginArray("layer_rect");
565 MathUtil::AddToTracedValue(layer_rect_, record_data.get()); 547 MathUtil::AddToTracedValue(layer_rect_, record_data.get());
566 record_data->EndArray(); 548 record_data->EndArray();
567 return record_data; 549 return record_data;
568 } 550 }
569 551
570 } // namespace cc 552 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture.h ('k') | cc/resources/picture_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698