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

Side by Side Diff: blimp/test/support/compositor/picture_cache_test_support.cc

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from vmpstr, including adding //cc/blimp Created 4 years, 6 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 | « blimp/test/support/compositor/picture_cache_test_support.h ('k') | cc/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "blimp/test/support/compositor/picture_cache_test_support.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "blimp/common/blob_cache/blob_cache.h"
9 #include "blimp/common/blob_cache/id_util.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkColor.h"
12 #include "third_party/skia/include/core/SkData.h"
13 #include "third_party/skia/include/core/SkPicture.h"
14 #include "third_party/skia/include/core/SkPictureRecorder.h"
15 #include "third_party/skia/include/core/SkRefCnt.h"
16 #include "third_party/skia/include/core/SkStream.h"
17 #include "ui/gfx/geometry/point_f.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/skia_util.h"
21
22 namespace blimp {
23
24 sk_sp<const SkPicture> CreateSkPicture(SkColor color) {
25 SkPictureRecorder recorder;
26 sk_sp<SkCanvas> canvas =
27 sk_ref_sp(recorder.beginRecording(SkRect::MakeWH(1, 1)));
28 canvas->drawColor(color);
29 return recorder.finishRecordingAsPicture();
30 }
31
32 sk_sp<SkData> SerializePicture(sk_sp<const SkPicture> picture) {
33 SkDynamicMemoryWStream stream;
34 picture->serialize(&stream, nullptr);
35 DCHECK(stream.bytesWritten());
36 return sk_sp<SkData>(stream.copyToData());
37 }
38
39 BlobId GetBlobId(sk_sp<const SkPicture> picture) {
40 sk_sp<SkData> data = SerializePicture(picture);
41 return CalculateBlobId(data->data(), data->size());
42 }
43
44 sk_sp<const SkPicture> DeserializePicture(sk_sp<SkData> data) {
45 SkMemoryStream stream(data);
46 return SkPicture::MakeFromStream(&stream, nullptr);
47 }
48
49 bool PicturesEqual(sk_sp<const SkPicture> picture,
50 const cc::PictureData& picture_data) {
51 if (picture->uniqueID() != picture_data.unique_id) {
52 return false;
53 }
54 sk_sp<const SkPicture> deserialized_picture =
55 DeserializePicture(picture_data.data);
56 return GetBlobId(picture) == GetBlobId(deserialized_picture);
57 }
58
59 cc::PictureData CreatePictureData(sk_sp<const SkPicture> picture) {
60 return cc::PictureData(picture->uniqueID(), SerializePicture(picture));
61 }
62
63 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/test/support/compositor/picture_cache_test_support.h ('k') | cc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698