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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" |
12 | 12 |
13 class SkSurface_Gpu : public SkSurface_Base { | 13 class SkSurface_Gpu : public SkSurface_Base { |
14 public: | 14 public: |
15 SK_DECLARE_INST_COUNT(SkSurface_Gpu) | 15 SK_DECLARE_INST_COUNT(SkSurface_Gpu) |
16 | 16 |
17 SkSurface_Gpu(GrRenderTarget*, bool cached); | 17 SkSurface_Gpu(GrRenderTarget*, bool cached); |
18 virtual ~SkSurface_Gpu(); | 18 virtual ~SkSurface_Gpu(); |
19 | 19 |
20 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; | 20 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; |
21 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; | 21 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
22 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; | 22 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; |
23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, | 23 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, |
24 const SkPaint*) SK_OVERRIDE; | 24 const SkPaint*) SK_OVERRIDE; |
25 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; | 25 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; |
| 26 virtual void onDiscard() SK_OVERRIDE; |
26 | 27 |
27 private: | 28 private: |
28 SkGpuDevice* fDevice; | 29 SkGpuDevice* fDevice; |
29 | 30 |
30 typedef SkSurface_Base INHERITED; | 31 typedef SkSurface_Base INHERITED; |
31 }; | 32 }; |
32 | 33 |
33 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
34 | 35 |
35 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached) | 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 fDevice->createCompatibleDevice(fDevice->imageInfo())); | 80 fDevice->createCompatibleDevice(fDevice->imageInfo())); |
80 SkAutoTUnref<SkGpuDevice> aurd(newDevice); | 81 SkAutoTUnref<SkGpuDevice> aurd(newDevice); |
81 if (kRetain_ContentChangeMode == mode) { | 82 if (kRetain_ContentChangeMode == mode) { |
82 fDevice->context()->copyTexture(rt->asTexture(), newDevice->accessRe
nderTarget()); | 83 fDevice->context()->copyTexture(rt->asTexture(), newDevice->accessRe
nderTarget()); |
83 } | 84 } |
84 SkASSERT(NULL != this->getCachedCanvas()); | 85 SkASSERT(NULL != this->getCachedCanvas()); |
85 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); | 86 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); |
86 | 87 |
87 this->getCachedCanvas()->setRootDevice(newDevice); | 88 this->getCachedCanvas()->setRootDevice(newDevice); |
88 SkRefCnt_SafeAssign(fDevice, newDevice); | 89 SkRefCnt_SafeAssign(fDevice, newDevice); |
| 90 } else if (kDiscard_ContentChangeMode == mode) { |
| 91 this->SkSurface_Gpu::onDiscard(); |
89 } | 92 } |
90 } | 93 } |
91 | 94 |
| 95 void SkSurface_Gpu::onDiscard() { |
| 96 fDevice->accessRenderTarget()->discard(); |
| 97 } |
| 98 |
92 /////////////////////////////////////////////////////////////////////////////// | 99 /////////////////////////////////////////////////////////////////////////////// |
93 | 100 |
94 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { | 101 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { |
95 if (NULL == target) { | 102 if (NULL == target) { |
96 return NULL; | 103 return NULL; |
97 } | 104 } |
98 return SkNEW_ARGS(SkSurface_Gpu, (target, false)); | 105 return SkNEW_ARGS(SkSurface_Gpu, (target, false)); |
99 } | 106 } |
100 | 107 |
101 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount) { | 108 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 desc.fSampleCnt = sampleCount; | 142 desc.fSampleCnt = sampleCount; |
136 | 143 |
137 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); | 144 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); |
138 | 145 |
139 if (NULL == tex) { | 146 if (NULL == tex) { |
140 return NULL; | 147 return NULL; |
141 } | 148 } |
142 | 149 |
143 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); | 150 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); |
144 } | 151 } |
OLD | NEW |