OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
| 10 #include "SkImage_Base.h" |
10 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
11 #include "SkGpuDevice.h" | 12 #include "SkGpuDevice.h" |
12 | 13 |
13 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
14 | 15 |
15 class SkSurface_Gpu : public SkSurface_Base { | 16 class SkSurface_Gpu : public SkSurface_Base { |
16 public: | 17 public: |
17 SK_DECLARE_INST_COUNT(SkSurface_Gpu) | 18 SK_DECLARE_INST_COUNT(SkSurface_Gpu) |
18 | 19 |
19 SkSurface_Gpu(GrRenderTarget*, const SkSurfaceProps*, bool doClear); | 20 SkSurface_Gpu(GrRenderTarget*, const SkSurfaceProps*, bool doClear); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); | 60 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); |
60 } | 61 } |
61 | 62 |
62 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 63 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
63 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 64 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
64 int sampleCount = rt->numSamples(); | 65 int sampleCount = rt->numSamples(); |
65 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount, &th
is->props()); | 66 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount, &th
is->props()); |
66 } | 67 } |
67 | 68 |
68 SkImage* SkSurface_Gpu::onNewImageSnapshot() { | 69 SkImage* SkSurface_Gpu::onNewImageSnapshot() { |
69 return SkImage::NewTexture(fDevice->accessBitmap(false)); | 70 const int sampleCount = fDevice->accessRenderTarget()->numSamples(); |
| 71 SkImage* image = SkNewImageFromBitmapTexture(fDevice->accessBitmap(false), s
ampleCount); |
| 72 if (image) { |
| 73 as_IB(image)->initWithProps(this->props()); |
| 74 } |
| 75 return image; |
70 } | 76 } |
71 | 77 |
72 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 78 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
73 const SkPaint* paint) { | 79 const SkPaint* paint) { |
74 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 80 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
75 } | 81 } |
76 | 82 |
77 // Create a new SkGpuDevice and, if necessary, copy the contents of the old | 83 // Create a new SkGpuDevice and, if necessary, copy the contents of the old |
78 // device into it. Note that this flushes the SkGpuDevice but | 84 // device into it. Note that this flushes the SkGpuDevice but |
79 // doesn't force an OpenGL flush. | 85 // doesn't force an OpenGL flush. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 SkAutoTUnref<GrTexture> tex(ctx->refScratchTexture(desc, GrContext::kExact_S
cratchTexMatch)); | 156 SkAutoTUnref<GrTexture> tex(ctx->refScratchTexture(desc, GrContext::kExact_S
cratchTexMatch)); |
151 | 157 |
152 if (NULL == tex) { | 158 if (NULL == tex) { |
153 return NULL; | 159 return NULL; |
154 } | 160 } |
155 | 161 |
156 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), props, true)); | 162 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), props, true)); |
157 } | 163 } |
158 | 164 |
159 #endif | 165 #endif |
OLD | NEW |