OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 y += H; | 98 y += H; |
99 } | 99 } |
100 x += W; | 100 x += W; |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 private: | 105 private: |
106 typedef GM INHERITED; | 106 typedef GM INHERITED; |
107 }; | 107 }; |
| 108 DEF_GM( return new SurfacePropsGM ) |
108 | 109 |
109 DEF_GM( return new SurfacePropsGM ) | 110 |
| 111 static bool equal(const SkSurfaceProps& a, const SkSurfaceProps& b) { |
| 112 return a.flags() == b.flags() && a.pixelGeometry() == b.pixelGeometry(); |
| 113 } |
| 114 |
| 115 class NewSurfaceGM : public skiagm::GM { |
| 116 public: |
| 117 NewSurfaceGM() {} |
| 118 |
| 119 protected: |
| 120 SkString onShortName() SK_OVERRIDE { |
| 121 return SkString("surfacenew"); |
| 122 } |
| 123 |
| 124 virtual SkISize onISize() SK_OVERRIDE { |
| 125 return SkISize::Make(300, 140); |
| 126 } |
| 127 |
| 128 static void drawInto(SkCanvas* canvas) { |
| 129 canvas->drawColor(SK_ColorRED); |
| 130 } |
| 131 |
| 132 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 133 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 134 |
| 135 SkAutoTUnref<SkSurface> surf(canvas->newSurface(info, NULL)); |
| 136 if (!surf.get()) { |
| 137 surf.reset(SkSurface::NewRaster(info)); |
| 138 } |
| 139 drawInto(surf->getCanvas()); |
| 140 |
| 141 SkAutoTUnref<SkImage> image(surf->newImageSnapshot()); |
| 142 canvas->drawImage(image, 10, 10, NULL); |
| 143 |
| 144 SkAutoTUnref<SkSurface> surf2(image->newSurface(info, NULL)); |
| 145 drawInto(surf2->getCanvas()); |
| 146 |
| 147 // Assert that the props were communicated transitively through the firs
t image |
| 148 SkASSERT(equal(surf->props(), surf2->props())); |
| 149 |
| 150 SkAutoTUnref<SkImage> image2(surf2->newImageSnapshot()); |
| 151 canvas->drawImage(image2, 10 + image->width() + 10, 10, NULL); |
| 152 } |
| 153 |
| 154 private: |
| 155 typedef GM INHERITED; |
| 156 }; |
| 157 DEF_GM( return new NewSurfaceGM ) |
| 158 |
OLD | NEW |