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 #ifdef SK_DEBUG |
| 111 static bool equal(const SkSurfaceProps& a, const SkSurfaceProps& b) { |
| 112 return a.flags() == b.flags() && a.pixelGeometry() == b.pixelGeometry(); |
| 113 } |
| 114 #endif |
| 115 |
| 116 class NewSurfaceGM : public skiagm::GM { |
| 117 public: |
| 118 NewSurfaceGM() {} |
| 119 |
| 120 protected: |
| 121 SkString onShortName() SK_OVERRIDE { |
| 122 return SkString("surfacenew"); |
| 123 } |
| 124 |
| 125 virtual SkISize onISize() SK_OVERRIDE { |
| 126 return SkISize::Make(300, 140); |
| 127 } |
| 128 |
| 129 static void drawInto(SkCanvas* canvas) { |
| 130 canvas->drawColor(SK_ColorRED); |
| 131 } |
| 132 |
| 133 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 134 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 135 |
| 136 SkAutoTUnref<SkSurface> surf(canvas->newSurface(info, NULL)); |
| 137 if (!surf.get()) { |
| 138 surf.reset(SkSurface::NewRaster(info)); |
| 139 } |
| 140 drawInto(surf->getCanvas()); |
| 141 |
| 142 SkAutoTUnref<SkImage> image(surf->newImageSnapshot()); |
| 143 canvas->drawImage(image, 10, 10, NULL); |
| 144 |
| 145 SkAutoTUnref<SkSurface> surf2(image->newSurface(info, NULL)); |
| 146 drawInto(surf2->getCanvas()); |
| 147 |
| 148 // Assert that the props were communicated transitively through the firs
t image |
| 149 SkASSERT(equal(surf->props(), surf2->props())); |
| 150 |
| 151 SkAutoTUnref<SkImage> image2(surf2->newImageSnapshot()); |
| 152 canvas->drawImage(image2, 10 + SkIntToScalar(image->width()) + 10, 10, N
ULL); |
| 153 } |
| 154 |
| 155 private: |
| 156 typedef GM INHERITED; |
| 157 }; |
| 158 DEF_GM( return new NewSurfaceGM ) |
| 159 |
OLD | NEW |