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

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: 1.0 -> 1.0f 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
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"
6
7 #include "base/base64.h"
5 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
6 #include "cc/debug/rendering_stats.h" 9 #include "cc/debug/rendering_stats.h"
7 #include "cc/layers/content_layer_client.h" 10 #include "cc/layers/content_layer_client.h"
8 #include "cc/resources/picture.h"
9 #include "skia/ext/analysis_canvas.h" 11 #include "skia/ext/analysis_canvas.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 12 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkData.h" 13 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkDrawFilter.h" 14 #include "third_party/skia/include/core/SkDrawFilter.h"
13 #include "third_party/skia/include/core/SkPaint.h" 15 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkStream.h"
14 #include "third_party/skia/include/utils/SkPictureUtils.h" 17 #include "third_party/skia/include/utils/SkPictureUtils.h"
15 #include "ui/gfx/rect_conversions.h" 18 #include "ui/gfx/rect_conversions.h"
16 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
17 20
18 namespace { 21 namespace {
19 // URI label for a lazily decoded SkPixelRef. 22 // URI label for a lazily decoded SkPixelRef.
20 const char kLabelLazyDecoded[] = "lazy"; 23 const char kLabelLazyDecoded[] = "lazy";
21 24
22 class DisableLCDTextFilter : public SkDrawFilter { 25 class DisableLCDTextFilter : public SkDrawFilter {
23 public: 26 public:
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 for (size_t i = 0; i < pixel_refs->size() / sizeof(*refs); ++i) { 174 for (size_t i = 0; i < pixel_refs->size() / sizeof(*refs); ++i) {
172 if (*refs && (*refs)->getURI() && !strncmp( 175 if (*refs && (*refs)->getURI() && !strncmp(
173 (*refs)->getURI(), kLabelLazyDecoded, 4)) { 176 (*refs)->getURI(), kLabelLazyDecoded, 4)) {
174 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs)); 177 pixel_ref_list.push_back(static_cast<skia::LazyPixelRef*>(*refs));
175 } 178 }
176 refs++; 179 refs++;
177 } 180 }
178 pixel_refs->unref(); 181 pixel_refs->unref();
179 } 182 }
180 183
184 void Picture::AsBase64String(std::string* output) const {
185 SkDynamicMemoryWStream stream;
186 picture_->serialize(&stream);
187 size_t serialized_size = stream.bytesWritten();
188 scoped_ptr<char[]> serialized_picture(new char[serialized_size]);
189 stream.copyTo(serialized_picture.get());
190 base::Base64Encode(std::string(serialized_picture.get(), serialized_size),
191 output);
192 }
193
194 void Picture::SetPictureFromBase64String(const std::string & encoded) {
195 std::string decoded;
196 base::Base64Decode(encoded, &decoded);
197 SkMemoryStream stream(decoded.data(), decoded.size());
198 picture_ = skia::AdoptRef(new SkPicture(&stream));
199 }
200
181 } // namespace cc 201 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698