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

Side by Side Diff: tests/ImageTest.cpp

Issue 1631053003: Add SkImage factory method that forces image to be resolved to a texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static->class method Created 4 years, 10 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/image/SkImage_Gpu.cpp ('k') | 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 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 <functional>
9 #include "DMGpuSupport.h"
10
8 #include "SkBitmap.h" 11 #include "SkBitmap.h"
9 #include "SkCanvas.h" 12 #include "SkCanvas.h"
10 #include "SkData.h" 13 #include "SkData.h"
11 #include "SkDevice.h" 14 #include "SkDevice.h"
12 #include "SkImageEncoder.h" 15 #include "SkImageEncoder.h"
13 #include "SkImageGenerator.h" 16 #include "SkImageGenerator.h"
14 #include "SkImage_Base.h" 17 #include "SkImage_Base.h"
15 #include "SkPicture.h" 18 #include "SkPicture.h"
16 #include "SkPictureRecorder.h" 19 #include "SkPictureRecorder.h"
17 #include "SkPixelSerializer.h" 20 #include "SkPixelSerializer.h"
18 #include "SkRRect.h" 21 #include "SkRRect.h"
19 #include "SkStream.h" 22 #include "SkStream.h"
20 #include "SkSurface.h" 23 #include "SkSurface.h"
21 #include "SkUtils.h" 24 #include "SkUtils.h"
22 #include "Test.h" 25 #include "Test.h"
23 26
24 #if SK_SUPPORT_GPU
25 #include "GrContext.h"
26 #include "gl/GrGLInterface.h"
27 #include "gl/GrGLUtil.h"
28 #endif
29
30 static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect * subsetA, 27 static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect * subsetA,
31 SkImage* b) { 28 SkImage* b) {
32 const int widthA = subsetA ? subsetA->width() : a->width(); 29 const int widthA = subsetA ? subsetA->width() : a->width();
33 const int heightA = subsetA ? subsetA->height() : a->height(); 30 const int heightA = subsetA ? subsetA->height() : a->height();
34 31
35 REPORTER_ASSERT(reporter, widthA == b->width()); 32 REPORTER_ASSERT(reporter, widthA == b->width());
36 REPORTER_ASSERT(reporter, heightA == b->height()); 33 REPORTER_ASSERT(reporter, heightA == b->height());
37 #if 0 34 #if 0
38 // see https://bug.skia.org/3965 35 // see https://bug.skia.org/3965
39 bool AO = a->isOpaque(); 36 bool AO = a->isOpaque();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 SkCanvas canvas(bm); 77 SkCanvas canvas(bm);
81 draw_image_test_pattern(&canvas); 78 draw_image_test_pattern(&canvas);
82 } 79 }
83 return data.release(); 80 return data.release();
84 } 81 }
85 static SkImage* create_data_image() { 82 static SkImage* create_data_image() {
86 SkImageInfo info; 83 SkImageInfo info;
87 SkAutoTUnref<SkData> data(create_image_data(&info)); 84 SkAutoTUnref<SkData> data(create_image_data(&info));
88 return SkImage::NewRasterData(info, data, info.minRowBytes()); 85 return SkImage::NewRasterData(info, data, info.minRowBytes());
89 } 86 }
87 #if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests
88 static SkImage* create_picture_image() {
89 SkPictureRecorder recorder;
90 SkCanvas* canvas = recorder.beginRecording(10, 10);
91 canvas->clear(SK_ColorCYAN);
92 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
93 return SkImage::NewFromPicture(picture, SkISize::Make(10, 10), nullptr, null ptr);
94 };
95 #endif
90 // Want to ensure that our Release is called when the owning image is destroyed 96 // Want to ensure that our Release is called when the owning image is destroyed
91 struct RasterDataHolder { 97 struct RasterDataHolder {
92 RasterDataHolder() : fReleaseCount(0) {} 98 RasterDataHolder() : fReleaseCount(0) {}
93 SkAutoTUnref<SkData> fData; 99 SkAutoTUnref<SkData> fData;
94 int fReleaseCount; 100 int fReleaseCount;
95 static void Release(const void* pixels, void* context) { 101 static void Release(const void* pixels, void* context) {
96 RasterDataHolder* self = static_cast<RasterDataHolder*>(context); 102 RasterDataHolder* self = static_cast<RasterDataHolder*>(context);
97 self->fReleaseCount++; 103 self->fReleaseCount++;
98 self->fData.reset(); 104 self->fData.reset();
99 } 105 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 SkDebugf("SkImage_Gpu2Cpu : cachedBitmap was already purged\n"); 375 SkDebugf("SkImage_Gpu2Cpu : cachedBitmap was already purged\n");
370 } 376 }
371 } 377 }
372 378
373 image.reset(nullptr); 379 image.reset(nullptr);
374 { 380 {
375 SkBitmap cachedBitmap; 381 SkBitmap cachedBitmap;
376 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)) ; 382 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)) ;
377 } 383 }
378 } 384 }
385
386 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_newTextureImage, reporter, context, glCon text) {
387 GrContextFactory otherFactory;
388 GrContextFactory::ContextInfo otherContextInfo =
389 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType);
390 glContext->makeCurrent();
391
392 std::function<SkImage*()> imageFactories[] = {
393 create_image,
394 create_codec_image,
395 create_data_image,
396 // Create an image from a picture.
397 create_picture_image,
398 // Create a texture image.
399 [context] { return create_gpu_image(context); },
400 // Create a texture image in a another GrContext.
401 [glContext, otherContextInfo] {
402 otherContextInfo.fGLContext->makeCurrent();
403 SkImage* otherContextImage = create_gpu_image(otherContextInfo.fGrCo ntext);
404 glContext->makeCurrent();
405 return otherContextImage;
406 }
407 };
408
409 for (auto factory : imageFactories) {
410 SkAutoTUnref<SkImage> image(factory());
411 if (!image) {
412 ERRORF(reporter, "Error creating image.");
413 continue;
414 }
415 GrTexture* origTexture = as_IB(image)->peekTexture();
416
417 SkAutoTUnref<SkImage> texImage(image->newTextureImage(context));
418 if (!texImage) {
419 // We execpt to fail if image comes from a different GrContext.
420 if (!origTexture || origTexture->getContext() == context) {
421 ERRORF(reporter, "newTextureImage failed.");
422 }
423 continue;
424 }
425 GrTexture* copyTexture = as_IB(texImage)->peekTexture();
426 if (!copyTexture) {
427 ERRORF(reporter, "newTextureImage returned non-texture image.");
428 continue;
429 }
430 if (origTexture) {
431 if (origTexture != copyTexture) {
432 ERRORF(reporter, "newTextureImage made unnecessary texture copy. ");
433 }
434 }
435 if (image->width() != texImage->width() || image->height() != texImage-> height()) {
436 ERRORF(reporter, "newTextureImage changed the image size.");
437 }
438 if (image->isOpaque() != texImage->isOpaque()) {
439 ERRORF(reporter, "newTextureImage changed image opaqueness.");
440 }
441 }
442 }
379 #endif 443 #endif
380 444
381 // https://bug.skia.org/4390 445 // https://bug.skia.org/4390
382 DEF_TEST(ImageFromIndex8Bitmap, r) { 446 DEF_TEST(ImageFromIndex8Bitmap, r) {
383 SkPMColor pmColors[1] = {SkPreMultiplyColor(SK_ColorWHITE)}; 447 SkPMColor pmColors[1] = {SkPreMultiplyColor(SK_ColorWHITE)};
384 SkBitmap bm; 448 SkBitmap bm;
385 SkAutoTUnref<SkColorTable> ctable( 449 SkAutoTUnref<SkColorTable> ctable(
386 new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors))); 450 new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors)));
387 SkImageInfo info = 451 SkImageInfo info =
388 SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType); 452 SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 check_image_color(reporter, refImg, expected1); 731 check_image_color(reporter, refImg, expected1);
668 #endif 732 #endif
669 check_image_color(reporter, cpyImg, expected0); 733 check_image_color(reporter, cpyImg, expected0);
670 734
671 // Now exercise the release proc 735 // Now exercise the release proc
672 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); 736 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
673 refImg.reset(nullptr); // force a release of the image 737 refImg.reset(nullptr); // force a release of the image
674 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); 738 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
675 } 739 }
676 #endif 740 #endif
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698