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

Side by Side Diff: src/core/SkAnnotation.cpp

Issue 1761793003: Revert of move annotations to canvas virtual (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « samplecode/SampleFilterFuzz.cpp ('k') | src/core/SkAnnotationKeys.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkAnnotation.h" 8 #include "SkAnnotation.h"
9 #include "SkAnnotationKeys.h" 9 #include "SkData.h"
10 #include "SkCanvas.h" 10 #include "SkPaint.h"
11 #include "SkPoint.h" 11 #include "SkPoint.h"
12 #include "SkRect.h" 12 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h"
14
15 SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) {
16 if (nullptr == value) {
17 value = SkData::NewEmpty();
18 } else {
19 value->ref();
20 }
21 fData = value;
22 }
23
24 SkAnnotation::~SkAnnotation() {
25 fData->unref();
26 }
27
28 SkData* SkAnnotation::find(const char key[]) const {
29 return fKey.equals(key) ? fData : nullptr;
30 }
31
32 SkAnnotation::SkAnnotation(SkReadBuffer& buffer) {
33 buffer.readString(&fKey);
34 fData = buffer.readByteArrayAsData();
35 }
36
37 void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const {
38 buffer.writeString(fKey.c_str());
39 buffer.writeDataAsByteArray(fData);
40 }
13 41
14 const char* SkAnnotationKeys::URL_Key() { 42 const char* SkAnnotationKeys::URL_Key() {
15 return "SkAnnotationKey_URL"; 43 return "SkAnnotationKey_URL";
16 }; 44 };
17 45
18 const char* SkAnnotationKeys::Define_Named_Dest_Key() { 46 const char* SkAnnotationKeys::Define_Named_Dest_Key() {
19 return "SkAnnotationKey_Define_Named_Dest"; 47 return "SkAnnotationKey_Define_Named_Dest";
20 }; 48 };
21 49
22 const char* SkAnnotationKeys::Link_Named_Dest_Key() { 50 const char* SkAnnotationKeys::Link_Named_Dest_Key() {
23 return "SkAnnotationKey_Link_Named_Dest"; 51 return "SkAnnotationKey_Link_Named_Dest";
24 }; 52 };
25 53
26 //////////////////////////////////////////////////////////////////////////////// ////////////////// 54 ///////////////////////////////////////////////////////////////////////////////
55
56 #include "SkCanvas.h"
57
58 static void annotate_paint(SkPaint& paint, const char* key, SkData* value) {
59 paint.setAnnotation(SkAnnotation::Create(key, value))->unref();
60 }
27 61
28 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) { 62 void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {
29 if (nullptr == value) { 63 if (nullptr == value) {
30 return; 64 return;
31 } 65 }
32 canvas->drawAnnotation(rect, SkAnnotationKeys::URL_Key(), value); 66 SkPaint paint;
67 annotate_paint(paint, SkAnnotationKeys::URL_Key(), value);
68 canvas->drawRect(rect, paint);
33 } 69 }
34 70
35 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) { 71 void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) {
36 if (nullptr == name) { 72 if (nullptr == name) {
37 return; 73 return;
38 } 74 }
39 const SkRect rect = SkRect::MakeXYWH(point.x(), point.y(), 0, 0); 75 SkPaint paint;
40 canvas->drawAnnotation(rect, SkAnnotationKeys::Define_Named_Dest_Key(), name ); 76 annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name);
77 canvas->drawPoint(point.x(), point.y(), paint);
41 } 78 }
42 79
43 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n ame) { 80 void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* n ame) {
44 if (nullptr == name) { 81 if (nullptr == name) {
45 return; 82 return;
46 } 83 }
47 canvas->drawAnnotation(rect, SkAnnotationKeys::Link_Named_Dest_Key(), name); 84 SkPaint paint;
85 annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name);
86 canvas->drawRect(rect, paint);
48 } 87 }
OLDNEW
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/core/SkAnnotationKeys.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698