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

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

Issue 1220733006: Add support for drawBitmapRect() to SkMiniRecorder. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: 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/SkRecordDraw.cpp » ('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,
76 const SkPaint* p, SkCanvas::DrawBitmap RectFlags flags) {
77 SkRect bounds;
78 if (!src) {
79 bm.getBounds(&bounds);
80 src = &bounds;
81 }
82 SkTLazy<SkPaint> defaultPaint;
83 if (!p) {
84 p = defaultPaint.init();
85 }
86 TRY_TO_STORE(DrawBitmapRectToRectFixedSize, *p, bm, *src, dst, flags);
87 }
88
75 bool SkMiniRecorder::drawRect(const SkRect& rect, const SkPaint& paint) { 89 bool SkMiniRecorder::drawRect(const SkRect& rect, const SkPaint& paint) {
76 TRY_TO_STORE(DrawRect, paint, rect); 90 TRY_TO_STORE(DrawRect, paint, rect);
77 } 91 }
78 92
79 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) { 93 bool SkMiniRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
80 TRY_TO_STORE(DrawPath, paint, path); 94 TRY_TO_STORE(DrawPath, paint, path);
81 } 95 }
82 96
83 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) {
84 TRY_TO_STORE(DrawTextBlob, p, b, x, y); 98 TRY_TO_STORE(DrawTextBlob, p, b, x, y);
85 } 99 }
86 #undef TRY_TO_STORE 100 #undef TRY_TO_STORE
87 101
88 102
89 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) { 103 SkPicture* SkMiniRecorder::detachAsPicture(const SkRect& cull) {
90 #define CASE(Type) \ 104 #define CASE(Type) \
91 case State::k##Type: \ 105 case State::k##Type: \
92 fState = State::kEmpty; \ 106 fState = State::kEmpty; \
93 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())))
94 108
95 switch (fState) { 109 switch (fState) {
96 case State::kEmpty: return SkRef(gEmptyPicture.get()); 110 case State::kEmpty: return SkRef(gEmptyPicture.get());
111 CASE(DrawBitmapRectToRectFixedSize);
97 CASE(DrawPath); 112 CASE(DrawPath);
98 CASE(DrawRect); 113 CASE(DrawRect);
99 CASE(DrawTextBlob); 114 CASE(DrawTextBlob);
100 } 115 }
101 SkASSERT(false); 116 SkASSERT(false);
102 return nullptr; 117 return nullptr;
103 #undef CASE 118 #undef CASE
104 } 119 }
105 120
106 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) { 121 void SkMiniRecorder::flushAndReset(SkCanvas* canvas) {
107 #define CASE(Type) \ 122 #define CASE(Type) \
108 case State::k##Type: { \ 123 case State::k##Type: { \
109 fState = State::kEmpty; \ 124 fState = State::kEmpty; \
110 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \ 125 Type* op = reinterpret_cast<Type*>(fBuffer.get()); \
111 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \ 126 SkRecords::Draw(canvas, nullptr, nullptr, 0, nullptr)(*op); \
112 op->~Type(); \ 127 op->~Type(); \
113 } return 128 } return
114 129
115 switch (fState) { 130 switch (fState) {
116 case State::kEmpty: return; 131 case State::kEmpty: return;
132 CASE(DrawBitmapRectToRectFixedSize);
117 CASE(DrawPath); 133 CASE(DrawPath);
118 CASE(DrawRect); 134 CASE(DrawRect);
119 CASE(DrawTextBlob); 135 CASE(DrawTextBlob);
120 } 136 }
121 SkASSERT(false); 137 SkASSERT(false);
122 #undef CASE 138 #undef CASE
123 } 139 }
OLDNEW
« no previous file with comments | « src/core/SkMiniRecorder.h ('k') | src/core/SkRecordDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698