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

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

Issue 13884018: cc: Add base64 encoding to picture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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
« cc/resources/picture.h ('K') | « 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 "base/base64.h"
5 #include "base/debug/trace_event.h" 6 #include "base/debug/trace_event.h"
6 #include "cc/debug/rendering_stats.h" 7 #include "cc/debug/rendering_stats.h"
7 #include "cc/layers/content_layer_client.h" 8 #include "cc/layers/content_layer_client.h"
8 #include "cc/resources/picture.h" 9 #include "cc/resources/picture.h"
tfarina 2013/04/13 00:49:01 nit: this should be the first include.
9 #include "skia/ext/analysis_canvas.h" 10 #include "skia/ext/analysis_canvas.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkData.h" 12 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkDrawFilter.h" 13 #include "third_party/skia/include/core/SkDrawFilter.h"
13 #include "third_party/skia/include/core/SkPaint.h" 14 #include "third_party/skia/include/core/SkPaint.h"
15 #include "third_party/skia/include/core/SkStream.h"
14 #include "third_party/skia/include/utils/SkPictureUtils.h" 16 #include "third_party/skia/include/utils/SkPictureUtils.h"
15 #include "ui/gfx/rect_conversions.h" 17 #include "ui/gfx/rect_conversions.h"
16 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
17 19
18 namespace { 20 namespace {
19 // URI label for a lazily decoded SkPixelRef. 21 // URI label for a lazily decoded SkPixelRef.
20 const char kLabelLazyDecoded[] = "lazy"; 22 const char kLabelLazyDecoded[] = "lazy";
21 23
22 class DisableLCDTextFilter : public SkDrawFilter { 24 class DisableLCDTextFilter : public SkDrawFilter {
23 public: 25 public:
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 canvas->clipRect(gfx::RectToSkRect(content_rect)); 145 canvas->clipRect(gfx::RectToSkRect(content_rect));
144 canvas->scale(contents_scale, contents_scale); 146 canvas->scale(contents_scale, contents_scale);
145 canvas->translate(layer_rect_.x(), layer_rect_.y()); 147 canvas->translate(layer_rect_.x(), layer_rect_.y());
146 // Pictures by default have LCD text enabled. 148 // Pictures by default have LCD text enabled.
147 if (!enable_lcd_text) 149 if (!enable_lcd_text)
148 canvas->setDrawFilter(&disable_lcd_text_filter); 150 canvas->setDrawFilter(&disable_lcd_text_filter);
149 canvas->drawPicture(*picture_); 151 canvas->drawPicture(*picture_);
150 canvas->restore(); 152 canvas->restore();
151 } 153 }
152 154
155 void Picture::AsBase64String(std::string* output) const {
tfarina 2013/04/13 00:49:01 the order of implementation should match with the
156 SkDynamicMemoryWStream stream;
157 picture_->serialize(&stream);
158 size_t serialized_size = stream.bytesWritten();
159 scoped_ptr<char[]> serialized_picture(new char[serialized_size]);
160 stream.copyTo(serialized_picture.get());
161 base::Base64Encode(std::string(serialized_picture.get(), serialized_size),
162 output);
163 }
164
165 void Picture::SetPictureFromBase64String(const std::string & encoded) {
166 std::string decoded;
167 base::Base64Decode(encoded, &decoded);
168 SkMemoryStream stream(decoded.data(), decoded.size());
169 picture_ = skia::AdoptRef(new SkPicture(&stream));
170 }
171
153 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, 172 void Picture::GatherPixelRefs(const gfx::Rect& layer_rect,
154 std::list<skia::LazyPixelRef*>& pixel_ref_list) { 173 std::list<skia::LazyPixelRef*>& pixel_ref_list) {
155 DCHECK(picture_); 174 DCHECK(picture_);
156 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs( 175 SkData* pixel_refs = SkPictureUtils::GatherPixelRefs(
157 picture_.get(), SkRect::MakeXYWH(layer_rect.x(), 176 picture_.get(), SkRect::MakeXYWH(layer_rect.x(),
158 layer_rect.y(), 177 layer_rect.y(),
159 layer_rect.width(), 178 layer_rect.width(),
160 layer_rect.height())); 179 layer_rect.height()));
161 if (!pixel_refs) 180 if (!pixel_refs)
162 return; 181 return;
163 182
164 void* data = const_cast<void*>(pixel_refs->data()); 183 void* data = const_cast<void*>(pixel_refs->data());
165 if (!data) { 184 if (!data) {
166 pixel_refs->unref(); 185 pixel_refs->unref();
167 return; 186 return;
168 } 187 }
169 188
170 SkPixelRef** refs = reinterpret_cast<SkPixelRef**>(data); 189 SkPixelRef** refs = reinterpret_cast<SkPixelRef**>(data);
171 for (size_t i = 0; i < pixel_refs->size() / sizeof(*refs); ++i) { 190 for (size_t i = 0; i < pixel_refs->size() / sizeof(*refs); ++i) {
172 if (*refs && (*refs)->getURI() && !strncmp( 191 if (*refs && (*refs)->getURI() && !strncmp(
173 (*refs)->getURI(), kLabelLazyDecoded, 4)) { 192 (*refs)->getURI(), kLabelLazyDecoded, 4)) {
174 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); 193 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs));
175 } 194 }
176 refs++; 195 refs++;
177 } 196 }
178 pixel_refs->unref(); 197 pixel_refs->unref();
179 } 198 }
180 199
181 } // namespace cc 200 } // namespace cc
OLDNEW
« cc/resources/picture.h ('K') | « cc/resources/picture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698