OLD | NEW |
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 "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 EmptyGenerator(const SkImageInfo& info) : SkImageGenerator(info) {} | 204 EmptyGenerator(const SkImageInfo& info) : SkImageGenerator(info) {} |
205 }; | 205 }; |
206 | 206 |
207 #if SK_SUPPORT_GPU | 207 #if SK_SUPPORT_GPU |
208 class TextureGenerator : public SkImageGenerator { | 208 class TextureGenerator : public SkImageGenerator { |
209 public: | 209 public: |
210 TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic) | 210 TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic) |
211 : SkImageGenerator(info) | 211 : SkImageGenerator(info) |
212 , fCtx(SkRef(ctx)) | 212 , fCtx(SkRef(ctx)) |
213 { | 213 { |
214 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudget
ed::kNo, | 214 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurfac
e::kNo_Budgeted, |
215 info, 0)); | 215 info, 0)); |
216 surface->getCanvas()->clear(0); | 216 surface->getCanvas()->clear(0); |
217 surface->getCanvas()->translate(-100, -100); | 217 surface->getCanvas()->translate(-100, -100); |
218 surface->getCanvas()->drawPicture(pic); | 218 surface->getCanvas()->drawPicture(pic); |
219 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 219 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
220 fTexture.reset(SkRef(image->getTexture())); | 220 fTexture.reset(SkRef(image->getTexture())); |
221 } | 221 } |
222 protected: | 222 protected: |
223 GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override
{ | 223 GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override
{ |
224 if (ctx) { | 224 if (ctx) { |
225 SkASSERT(ctx == fCtx.get()); | 225 SkASSERT(ctx == fCtx.get()); |
226 } | 226 } |
227 | 227 |
228 if (!subset) { | 228 if (!subset) { |
229 return SkRef(fTexture.get()); | 229 return SkRef(fTexture.get()); |
230 } | 230 } |
231 // need to copy the subset into a new texture | 231 // need to copy the subset into a new texture |
232 GrSurfaceDesc desc = fTexture->desc(); | 232 GrSurfaceDesc desc = fTexture->desc(); |
233 desc.fWidth = subset->width(); | 233 desc.fWidth = subset->width(); |
234 desc.fHeight = subset->height(); | 234 desc.fHeight = subset->height(); |
235 | 235 |
236 GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted
::kNo); | 236 GrTexture* dst = fCtx->textureProvider()->createTexture(desc, false); |
237 fCtx->copySurface(dst, fTexture, *subset, SkIPoint::Make(0, 0)); | 237 fCtx->copySurface(dst, fTexture, *subset, SkIPoint::Make(0, 0)); |
238 return dst; | 238 return dst; |
239 } | 239 } |
240 private: | 240 private: |
241 SkAutoTUnref<GrContext> fCtx; | 241 SkAutoTUnref<GrContext> fCtx; |
242 SkAutoTUnref<GrTexture> fTexture; | 242 SkAutoTUnref<GrTexture> fTexture; |
243 }; | 243 }; |
244 static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) { | 244 static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) { |
245 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 245 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
246 | 246 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(cache->info().width(
)), | 319 SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(cache->info().width(
)), |
320 SkIntToScalar(cache->info().width())); | 320 SkIntToScalar(cache->info().width())); |
321 canvas->drawRect(r, paint); | 321 canvas->drawRect(r, paint); |
322 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); | 322 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); |
323 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); | 323 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); |
324 return; | 324 return; |
325 } | 325 } |
326 // No API to draw a GrTexture directly, so we cheat and create a private
image subclass | 326 // No API to draw a GrTexture directly, so we cheat and create a private
image subclass |
327 SkAutoTUnref<SkImage> image(new SkImage_Gpu(cache->info().width(), cache
->info().height(), | 327 SkAutoTUnref<SkImage> image(new SkImage_Gpu(cache->info().width(), cache
->info().height(), |
328 cache->uniqueID(), kPremul_S
kAlphaType, texture, | 328 cache->uniqueID(), kPremul_S
kAlphaType, texture, |
329 SkBudgeted::kNo)); | 329 SkSurface::kNo_Budgeted)); |
330 canvas->drawImage(image, x, y); | 330 canvas->drawImage(image, x, y); |
331 #endif | 331 #endif |
332 } | 332 } |
333 | 333 |
334 void drawSet(SkCanvas* canvas) const { | 334 void drawSet(SkCanvas* canvas) const { |
335 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100); | 335 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100); |
336 canvas->drawPicture(fPicture, &matrix, nullptr); | 336 canvas->drawPicture(fPicture, &matrix, nullptr); |
337 | 337 |
338 // Draw the tex first, so it doesn't hit a lucky cache from the raster v
ersion. This | 338 // Draw the tex first, so it doesn't hit a lucky cache from the raster v
ersion. This |
339 // way we also can force the generateTexture call. | 339 // way we also can force the generateTexture call. |
(...skipping 30 matching lines...) Expand all Loading... |
370 }; | 370 }; |
371 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) | 371 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) |
372 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) | 372 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) |
373 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) | 373 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) |
374 #if SK_SUPPORT_GPU | 374 #if SK_SUPPORT_GPU |
375 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) | 375 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) |
376 #endif | 376 #endif |
377 | 377 |
378 | 378 |
379 | 379 |
OLD | NEW |