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

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

Issue 1228083004: add src-rect-constraint to drawImageRect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 5 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 | « src/core/SkMiniRecorder.h ('k') | src/core/SkPictureFlat.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 2015 Google Inc. 2 * Copyright 2015 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkLazyPtr.h" 9 #include "SkLazyPtr.h"
10 #include "SkMiniRecorder.h" 10 #include "SkMiniRecorder.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 SkASSERT(fState == State::kEmpty); 66 SkASSERT(fState == State::kEmpty);
67 } 67 }
68 68
69 #define TRY_TO_STORE(Type, ...) \ 69 #define TRY_TO_STORE(Type, ...) \
70 if (fState != State::kEmpty) { return false; } \ 70 if (fState != State::kEmpty) { return false; } \
71 fState = State::k##Type; \ 71 fState = State::k##Type; \
72 new (fBuffer.get()) Type(__VA_ARGS__); \ 72 new (fBuffer.get()) Type(__VA_ARGS__); \
73 return true 73 return true
74 74
75 bool SkMiniRecorder::drawBitmapRectToRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst, 75 bool SkMiniRecorder::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst,
76 const SkPaint* p, SkCanvas::DrawBitmap RectFlags flags) { 76 const SkPaint* p, SkCanvas::SrcRectConstrain t constraint) {
77 SkRect bounds; 77 SkRect bounds;
78 if (!src) { 78 if (!src) {
79 bm.getBounds(&bounds); 79 bm.getBounds(&bounds);
80 src = &bounds; 80 src = &bounds;
81 } 81 }
82 SkTLazy<SkPaint> defaultPaint; 82 SkTLazy<SkPaint> defaultPaint;
83 if (!p) { 83 if (!p) {
84 p = defaultPaint.init(); 84 p = defaultPaint.init();
85 } 85 }
86 TRY_TO_STORE(DrawBitmapRectToRectFixedSize, *p, bm, *src, dst, flags); 86 TRY_TO_STORE(DrawBitmapRectFixedSize, *p, bm, *src, dst, constraint);
87 } 87 }
88 88
89 bool SkMiniRecorder::drawRect(const SkRect& rect, const SkPaint& paint) { 89 bool SkMiniRecorder::drawRect(const SkRect& rect, const SkPaint& paint) {
90 TRY_TO_STORE(DrawRect, paint, rect); 90 TRY_TO_STORE(DrawRect, paint, rect);
91 } 91 }
92 92
93 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) { 93 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
94 TRY_TO_STORE(DrawPath, paint, path); 94 TRY_TO_STORE(DrawPath, paint, path);
95 } 95 }
96 96
97 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c onst SkPaint& p) { 97 bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c onst SkPaint& p) {
98 TRY_TO_STORE(DrawTextBlob, p, b, x, y); 98 TRY_TO_STORE(DrawTextBlob, p, b, x, y);
99 } 99 }
100 #undef TRY_TO_STORE 100 #undef TRY_TO_STORE
101 101
102 102
103 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { 103 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) {
104 #define CASE(Type) \ 104 #define CASE(Type) \
105 case State::k##Type: \ 105 case State::k##Type: \
106 fState = State::kEmpty; \ 106 fState = State::kEmpty; \
107 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB uffer.get()))) 107 return SkNEW_ARGS(SkMiniPicture<Type>, (cull, reinterpret_cast<Type*>(fB uffer.get())))
108 108
109 switch (fState) { 109 switch (fState) {
110 case State::kEmpty: return SkRef(gEmptyPicture.get()); 110 case State::kEmpty: return SkRef(gEmptyPicture.get());
111 CASE(DrawBitmapRectToRectFixedSize); 111 CASE(DrawBitmapRectFixedSize);
112 CASE(DrawPath); 112 CASE(DrawPath);
113 CASE(DrawRect); 113 CASE(DrawRect);
114 CASE(DrawTextBlob); 114 CASE(DrawTextBlob);
115 } 115 }
116 SkASSERT(false); 116 SkASSERT(false);
117 return nullptr; 117 return nullptr;
118 #undef CASE 118 #undef CASE
119 } 119 }
120 120
121 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { 121 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) {
122 #define CASE(Type) \ 122 #define CASE(Type) \
123 case State::k##Type: { \ 123 case State::k##Type: { \
124 fState = State::kEmpty; \ 124 fState = State::kEmpty; \
125 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ 125 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \
126 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ 126 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \
127 op->~Type(); \ 127 op->~Type(); \
128 } return 128 } return
129 129
130 switch (fState) { 130 switch (fState) {
131 case State::kEmpty: return; 131 case State::kEmpty: return;
132 CASE(DrawBitmapRectToRectFixedSize); 132 CASE(DrawBitmapRectFixedSize);
133 CASE(DrawPath); 133 CASE(DrawPath);
134 CASE(DrawRect); 134 CASE(DrawRect);
135 CASE(DrawTextBlob); 135 CASE(DrawTextBlob);
136 } 136 }
137 SkASSERT(false); 137 SkASSERT(false);
138 #undef CASE 138 #undef CASE
139 } 139 }
OLDNEW
« no previous file with comments | « src/core/SkMiniRecorder.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698