| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 | 8 |
| 9 #include <SkSurface.h> | 9 #include <SkSurface.h> |
| 10 #include "gm.h" | 10 #include "gm.h" |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
| 13 #include "SkImage.h" | 13 #include "SkImage.h" |
| 14 | 14 |
| 15 static SkImage* create_image(GrContext* context, int width, int height) { | 15 static sk_sp<SkImage> create_image(GrContext* context, int width, int height) { |
| 16 SkAutoTUnref<SkSurface> surface; | 16 SkAutoTUnref<SkSurface> surface; |
| 17 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 17 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 18 if (context) { | 18 if (context) { |
| 19 surface.reset(SkSurface::NewRenderTarget(context, SkBudgeted::kYes, inf
o, 0)); | 19 surface.reset(SkSurface::NewRenderTarget(context, SkBudgeted::kYes, inf
o, 0)); |
| 20 } else { | 20 } else { |
| 21 surface.reset(SkSurface::NewRaster(info)); | 21 surface.reset(SkSurface::NewRaster(info)); |
| 22 } | 22 } |
| 23 if (!surface) { | 23 if (!surface) { |
| 24 return nullptr; | 24 return nullptr; |
| 25 } | 25 } |
| 26 // Create an RGB image from which we will extract planes | 26 // Create an RGB image from which we will extract planes |
| 27 SkPaint paint; | 27 SkPaint paint; |
| 28 static const SkColor kColors[] = | 28 static const SkColor kColors[] = |
| 29 { SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE }; | 29 { SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE }; |
| 30 SkScalar r = (width + height) / 4.f; | 30 SkScalar r = (width + height) / 4.f; |
| 31 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), r, kColors, | 31 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), r, kColors, |
| 32 nullptr, SK_ARRAY_COUNT(kColors
), | 32 nullptr, SK_ARRAY_COUNT(kColors
), |
| 33 SkShader::kMirror_TileMode)); | 33 SkShader::kMirror_TileMode)); |
| 34 | 34 |
| 35 surface->getCanvas()->drawPaint(paint); | 35 surface->getCanvas()->drawPaint(paint); |
| 36 return surface->newImageSnapshot(); | 36 return surface->makeImageSnapshot(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 DEF_SIMPLE_GM(image_to_yuv_planes, canvas, 120, 525) { | 39 DEF_SIMPLE_GM(image_to_yuv_planes, canvas, 120, 525) { |
| 40 static const SkScalar kPad = 5.f; | 40 static const SkScalar kPad = 5.f; |
| 41 static const int kImageSize = 32; | 41 static const int kImageSize = 32; |
| 42 | 42 |
| 43 GrContext *context = canvas->getGrContext(); | 43 GrContext *context = canvas->getGrContext(); |
| 44 SkAutoTUnref<SkImage> rgbImage(create_image(context, kImageSize, kImageSize)
); | 44 sk_sp<SkImage> rgbImage(create_image(context, kImageSize, kImageSize)); |
| 45 if (!rgbImage) { | 45 if (!rgbImage) { |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 canvas->drawImage(rgbImage, kPad, kPad); | 49 canvas->drawImage(rgbImage.get(), kPad, kPad); |
| 50 // Test cases where all three planes are the same size, where just u and v a
re the same size, | 50 // Test cases where all three planes are the same size, where just u and v a
re the same size, |
| 51 // and where all differ. | 51 // and where all differ. |
| 52 static const SkISize kSizes[][3] = { | 52 static const SkISize kSizes[][3] = { |
| 53 {{kImageSize, kImageSize}, {kImageSize , kImageSize }, {kImageSize,
kImageSize }}, | 53 {{kImageSize, kImageSize}, {kImageSize , kImageSize }, {kImageSize,
kImageSize }}, |
| 54 {{kImageSize, kImageSize}, {kImageSize/2, kImageSize/2}, {kImageSize/2,
kImageSize/2}}, | 54 {{kImageSize, kImageSize}, {kImageSize/2, kImageSize/2}, {kImageSize/2,
kImageSize/2}}, |
| 55 {{kImageSize, kImageSize}, {kImageSize/2, kImageSize/2}, {kImageSize/3,
kImageSize/3}} | 55 {{kImageSize, kImageSize}, {kImageSize/2, kImageSize/2}, {kImageSize/3,
kImageSize/3}} |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // A mix of rowbytes triples to go with the above sizes. | 58 // A mix of rowbytes triples to go with the above sizes. |
| 59 static const size_t kRowBytes[][3] { | 59 static const size_t kRowBytes[][3] { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 for (int i = 0; i < 3; ++i) { | 102 for (int i = 0; i < 3; ++i) { |
| 103 canvas->drawBitmap(yuvBmps[i], x, y); | 103 canvas->drawBitmap(yuvBmps[i], x, y); |
| 104 y += kPad + yuvBmps[i].height(); | 104 y += kPad + yuvBmps[i].height(); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 x += rgbImage->width() + kPad; | 109 x += rgbImage->width() + kPad; |
| 110 } | 110 } |
| 111 } | 111 } |
| OLD | NEW |