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

Side by Side Diff: gm/image.cpp

Issue 834903003: fix labels on image-surface gm (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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 | « no previous file | no next file » | 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 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ImageGM() { 113 ImageGM() {
114 fBufferSize = RB * H; 114 fBufferSize = RB * H;
115 fBuffer = sk_malloc_throw(fBufferSize); 115 fBuffer = sk_malloc_throw(fBufferSize);
116 fSize.set(SkIntToScalar(W), SkIntToScalar(H)); 116 fSize.set(SkIntToScalar(W), SkIntToScalar(H));
117 } 117 }
118 118
119 virtual ~ImageGM() { 119 virtual ~ImageGM() {
120 sk_free(fBuffer); 120 sk_free(fBuffer);
121 } 121 }
122 122
123
124 protected: 123 protected:
125 virtual SkString onShortName() { 124 SkString onShortName() SK_OVERRIDE {
126 return SkString("image-surface"); 125 return SkString("image-surface");
127 } 126 }
128 127
129 virtual SkISize onISize() { 128 SkISize onISize() SK_OVERRIDE {
130 return SkISize::Make(960, 1200); 129 return SkISize::Make(960, 1200);
131 } 130 }
132 131
133 virtual void onDraw(SkCanvas* canvas) { 132 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
134 drawJpeg(canvas, this->getISize()); 133 drawJpeg(canvas, this->getISize());
135 134
136 canvas->scale(2, 2); 135 canvas->scale(2, 2);
137 136
138 static const char* kLabel1 = "Original Img"; 137 static const char* kLabel1 = "Original Img";
139 static const char* kLabel2 = "Modified Img"; 138 static const char* kLabel2 = "Modified Img";
140 static const char* kLabel3 = "Cur Surface"; 139 static const char* kLabel3 = "Cur Surface";
141 static const char* kLabel4 = "Full Crop"; 140 static const char* kLabel4 = "Full Crop";
142 static const char* kLabel5 = "Over-crop"; 141 static const char* kLabel5 = "Over-crop";
143 static const char* kLabel6 = "Upper-left"; 142 static const char* kLabel6 = "Upper-left";
144 static const char* kLabel7 = "No Crop"; 143 static const char* kLabel7 = "No Crop";
145 144
146 static const char* kLabel8 = "Pre-Alloc Img"; 145 static const char* kLabel8 = "Pre-Alloc Img";
147 static const char* kLabel9 = "New Alloc Img"; 146 static const char* kLabel9 = "New Alloc Img";
148 static const char* kLabel10 = "Null Paint"; 147 static const char* kLabel10 = "GPU";
149 static const char* kLabel11 = "GPU";
150 148
151 SkPaint textPaint; 149 SkPaint textPaint;
152 textPaint.setAntiAlias(true); 150 textPaint.setAntiAlias(true);
153 sk_tool_utils::set_portable_typeface(&textPaint); 151 sk_tool_utils::set_portable_typeface(&textPaint);
154 textPaint.setTextSize(8); 152 textPaint.setTextSize(8);
155 153
156 canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint); 154 canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint);
157 canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint); 155 canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint);
158 canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint); 156 canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint);
159 canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint); 157 canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint);
160 canvas->drawText(kLabel5, strlen(kLabel5), 10, 380, textPaint); 158 canvas->drawText(kLabel5, strlen(kLabel5), 10, 380, textPaint);
161 canvas->drawText(kLabel6, strlen(kLabel6), 10, 460, textPaint); 159 canvas->drawText(kLabel6, strlen(kLabel6), 10, 460, textPaint);
162 canvas->drawText(kLabel7, strlen(kLabel7), 10, 540, textPaint); 160 canvas->drawText(kLabel7, strlen(kLabel7), 10, 540, textPaint);
163 161
164 canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint); 162 canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint);
165 canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint); 163 canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint);
166 canvas->drawText(kLabel10, strlen(kLabel10), 250, 10, textPaint); 164 canvas->drawText(kLabel10, strlen(kLabel10), 265, 10, textPaint);
167 canvas->drawText(kLabel11, strlen(kLabel11), 320, 10, textPaint);
168 165
169 canvas->translate(80, 20); 166 canvas->translate(80, 20);
170 167
171 // since we draw into this directly, we need to start fresh 168 // since we draw into this directly, we need to start fresh
172 sk_bzero(fBuffer, fBufferSize); 169 sk_bzero(fBuffer, fBufferSize);
173 170
174 SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); 171 SkImageInfo info = SkImageInfo::MakeN32Premul(W, H);
175 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB)); 172 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB));
176 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); 173 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info));
174 SkAutoTUnref<SkSurface> surf2; // gpu
175
177 #if SK_SUPPORT_GPU 176 #if SK_SUPPORT_GPU
178 GrContext* ctx = canvas->getGrContext(); 177 surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(),
179 178 SkSurface::kNo_Budgeted, info));
180 SkAutoTUnref<SkSurface> surf4(SkSurface::NewRenderTarget(
181 ctx, SkSurface::kNo_Budgeted, info));
182 #endif 179 #endif
183 180
184 test_surface(canvas, surf0, true); 181 test_surface(canvas, surf0, true);
185 canvas->translate(80, 0); 182 canvas->translate(80, 0);
186 test_surface(canvas, surf1, true); 183 test_surface(canvas, surf1, true);
187 #if SK_SUPPORT_GPU 184 if (surf2) {
188 if (ctx) {
189 canvas->translate(80, 0); 185 canvas->translate(80, 0);
190 test_surface(canvas, surf4, true); 186 test_surface(canvas, surf2, true);
191 } 187 }
192 #endif
193 } 188 }
194 189
195 uint32_t onGetFlags() const SK_OVERRIDE { 190 uint32_t onGetFlags() const SK_OVERRIDE {
196 return GM::kSkipPicture_Flag | GM::kSkipPipe_Flag; 191 return GM::kSkipPicture_Flag | GM::kSkipPipe_Flag;
197 } 192 }
198 193
199 private: 194 private:
200 typedef skiagm::GM INHERITED; 195 typedef skiagm::GM INHERITED;
201 }; 196 };
197 DEF_GM( return new ImageGM; )
202 198
203 //////////////////////////////////////////////////////////////////////////////
204
205 static skiagm::GM* MyFactory(void*) { return new ImageGM; }
206 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698