OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkSurface.h" | 9 #include "SkSurface.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 drawContents(surf, SK_ColorBLUE); | 84 drawContents(surf, SK_ColorBLUE); |
85 | 85 |
86 SkPaint paint; | 86 SkPaint paint; |
87 // paint.setFilterBitmap(true); | 87 // paint.setFilterBitmap(true); |
88 // paint.setAlpha(0x80); | 88 // paint.setAlpha(0x80); |
89 | 89 |
90 imgR->draw(canvas, 0, 0, &paint); | 90 imgR->draw(canvas, 0, 0, &paint); |
91 imgG->draw(canvas, 0, 80, &paint); | 91 imgG->draw(canvas, 0, 80, &paint); |
92 surf->draw(canvas, 0, 160, &paint); | 92 surf->draw(canvas, 0, 160, &paint); |
93 | 93 |
| 94 SkRect src1, src2, src3; |
| 95 src1.set(0, 0, surf->width(), surf->height()); |
| 96 src2.set(-surf->width() / 2, -surf->height() / 2, surf->width(), surf->heigh
t()); |
| 97 src3.set(0, 0, surf->width() / 2, surf->height() / 2); |
| 98 |
| 99 SkRect dst1, dst2, dst3, dst4; |
| 100 dst1.set(0, 240, 65, 305); |
| 101 dst2.set(0, 320, 65, 385); |
| 102 dst3.set(0, 400, 65, 465); |
| 103 dst4.set(0, 480, 65, 545); |
| 104 |
| 105 imgR->draw(canvas, &src1, dst1, &paint); |
| 106 imgG->draw(canvas, &src2, dst2, &paint); |
| 107 imgR->draw(canvas, &src3, dst3, &paint); |
| 108 imgG->draw(canvas, NULL, dst4, &paint); |
| 109 |
94 imgG->unref(); | 110 imgG->unref(); |
95 imgR->unref(); | 111 imgR->unref(); |
96 } | 112 } |
97 | 113 |
98 class ImageGM : public skiagm::GM { | 114 class ImageGM : public skiagm::GM { |
99 void* fBuffer; | 115 void* fBuffer; |
100 size_t fBufferSize; | 116 size_t fBufferSize; |
101 SkSize fSize; | 117 SkSize fSize; |
102 enum { | 118 enum { |
103 W = 64, | 119 W = 64, |
(...skipping 11 matching lines...) Expand all Loading... |
115 sk_free(fBuffer); | 131 sk_free(fBuffer); |
116 } | 132 } |
117 | 133 |
118 | 134 |
119 protected: | 135 protected: |
120 virtual SkString onShortName() { | 136 virtual SkString onShortName() { |
121 return SkString("image-surface"); | 137 return SkString("image-surface"); |
122 } | 138 } |
123 | 139 |
124 virtual SkISize onISize() { | 140 virtual SkISize onISize() { |
125 return SkISize::Make(800, 500); | 141 return SkISize::Make(800, 1200); |
126 } | 142 } |
127 | 143 |
128 virtual void onDraw(SkCanvas* canvas) { | 144 virtual void onDraw(SkCanvas* canvas) { |
129 drawJpeg(canvas, this->getISize()); | 145 drawJpeg(canvas, this->getISize()); |
130 | 146 |
131 canvas->scale(2, 2); | 147 canvas->scale(2, 2); |
132 | 148 |
133 static const char* kLabel1 = "Original Img"; | 149 static const char* kLabel1 = "Original Img"; |
134 static const char* kLabel2 = "Modified Img"; | 150 static const char* kLabel2 = "Modified Img"; |
135 static const char* kLabel3 = "Cur Surface"; | 151 static const char* kLabel3 = "Cur Surface"; |
| 152 static const char* kLabel4 = "Full Crop"; |
| 153 static const char* kLabel5 = "Over-crop"; |
| 154 static const char* kLabel6 = "Upper-left"; |
| 155 static const char* kLabel7 = "No Crop"; |
136 | 156 |
137 static const char* kLabel4 = "Pre-Alloc Img"; | 157 static const char* kLabel8 = "Pre-Alloc Img"; |
138 static const char* kLabel5 = "New Alloc Img"; | 158 static const char* kLabel9 = "New Alloc Img"; |
139 static const char* kLabel6 = "SkPicture"; | 159 static const char* kLabel10 = "SkPicture"; |
140 static const char* kLabel7 = "GPU"; | 160 static const char* kLabel11 = "GPU"; |
141 | 161 |
142 SkPaint textPaint; | 162 SkPaint textPaint; |
143 | 163 |
144 canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint); | 164 canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint); |
145 canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint); | 165 canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint); |
146 canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint); | 166 canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint); |
| 167 canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint); |
| 168 canvas->drawText(kLabel5, strlen(kLabel5), 10, 380, textPaint); |
| 169 canvas->drawText(kLabel6, strlen(kLabel6), 10, 460, textPaint); |
| 170 canvas->drawText(kLabel7, strlen(kLabel7), 10, 540, textPaint); |
147 | 171 |
148 canvas->drawText(kLabel4, strlen(kLabel4), 80, 10, textPaint); | 172 canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint); |
149 canvas->drawText(kLabel5, strlen(kLabel5), 160, 10, textPaint); | 173 canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint); |
150 canvas->drawText(kLabel6, strlen(kLabel6), 250, 10, textPaint); | 174 canvas->drawText(kLabel10, strlen(kLabel10), 250, 10, textPaint); |
151 canvas->drawText(kLabel7, strlen(kLabel7), 340, 10, textPaint); | 175 canvas->drawText(kLabel11, strlen(kLabel11), 340, 10, textPaint); |
152 | 176 |
153 canvas->translate(80, 20); | 177 canvas->translate(80, 20); |
154 | 178 |
155 // since we draw into this directly, we need to start fresh | 179 // since we draw into this directly, we need to start fresh |
156 sk_bzero(fBuffer, fBufferSize); | 180 sk_bzero(fBuffer, fBufferSize); |
157 | 181 |
158 SkImage::Info info; | 182 SkImage::Info info; |
159 | 183 |
160 info.fWidth = W; | 184 info.fWidth = W; |
161 info.fHeight = H; | 185 info.fHeight = H; |
(...skipping 26 matching lines...) Expand all Loading... |
188 } | 212 } |
189 | 213 |
190 private: | 214 private: |
191 typedef skiagm::GM INHERITED; | 215 typedef skiagm::GM INHERITED; |
192 }; | 216 }; |
193 | 217 |
194 ////////////////////////////////////////////////////////////////////////////// | 218 ////////////////////////////////////////////////////////////////////////////// |
195 | 219 |
196 static skiagm::GM* MyFactory(void*) { return new ImageGM; } | 220 static skiagm::GM* MyFactory(void*) { return new ImageGM; } |
197 static skiagm::GMRegistry reg(MyFactory); | 221 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |