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_Gpu.h" | 8 #include "SkSurface_Gpu.h" |
9 | 9 |
10 #include "GrResourceProvider.h" | 10 #include "GrResourceProvider.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 case SkSurface::kFlushWrite_BackendHandleAccess: | 33 case SkSurface::kFlushWrite_BackendHandleAccess: |
34 case SkSurface::kDiscardWrite_BackendHandleAccess: | 34 case SkSurface::kDiscardWrite_BackendHandleAccess: |
35 // for now we don't special-case on Discard, but we may in the futur
e. | 35 // for now we don't special-case on Discard, but we may in the futur
e. |
36 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMod
e); | 36 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMod
e); |
37 // legacy: need to dirty the bitmap's genID in our device (curse it) | 37 // legacy: need to dirty the bitmap's genID in our device (curse it) |
38 surface->getDevice()->accessBitmap(false).notifyPixelsChanged(); | 38 surface->getDevice()->accessBitmap(false).notifyPixelsChanged(); |
39 break; | 39 break; |
40 } | 40 } |
41 | 41 |
42 // Grab the render target *after* firing notifications, as it may get switch
ed if CoW kicks in. | 42 // Grab the render target *after* firing notifications, as it may get switch
ed if CoW kicks in. |
43 GrRenderTarget* rt = surface->getDevice()->accessRenderTarget(); | 43 surface->getDevice()->flush(); |
44 rt->prepareForExternalIO(); | 44 GrDrawContext* dc = surface->getDevice()->accessDrawContext(); |
45 return rt; | 45 return dc->accessRenderTarget(); |
46 } | 46 } |
47 | 47 |
48 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { | 48 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { |
49 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); | 49 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
50 GrTexture* texture = rt->asTexture(); | 50 GrTexture* texture = rt->asTexture(); |
51 if (texture) { | 51 if (texture) { |
52 return texture->getTextureHandle(); | 52 return texture->getTextureHandle(); |
53 } | 53 } |
54 return 0; | 54 return 0; |
55 } | 55 } |
(...skipping 13 matching lines...) Expand all Loading... |
69 | 69 |
70 sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 70 sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
71 int sampleCount = fDevice->accessDrawContext()->numColorSamples(); | 71 int sampleCount = fDevice->accessDrawContext()->numColorSamples(); |
72 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. | 72 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. |
73 static const SkBudgeted kBudgeted = SkBudgeted::kNo; | 73 static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
74 return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, samp
leCount, | 74 return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, samp
leCount, |
75 &this->props()); | 75 &this->props()); |
76 } | 76 } |
77 | 77 |
78 sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyM
ode forceCopyMode) { | 78 sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyM
ode forceCopyMode) { |
79 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 79 GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget(); |
80 SkASSERT(rt); | 80 SkASSERT(rt); |
81 GrTexture* tex = rt->asTexture(); | 81 GrTexture* tex = rt->asTexture(); |
82 SkAutoTUnref<GrTexture> copy; | 82 SkAutoTUnref<GrTexture> copy; |
83 // If the original render target is a buffer originally created by the clien
t, then we don't | 83 // If the original render target is a buffer originally created by the clien
t, then we don't |
84 // want to ever retarget the SkSurface at another buffer we create. Force a
copy now to avoid | 84 // want to ever retarget the SkSurface at another buffer we create. Force a
copy now to avoid |
85 // copy-on-write. | 85 // copy-on-write. |
86 if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().refsWr
appedObjects()) { | 86 if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().refsWr
appedObjects()) { |
87 GrSurfaceDesc desc = fDevice->accessDrawContext()->desc(); | 87 GrSurfaceDesc desc = fDevice->accessDrawContext()->desc(); |
88 GrContext* ctx = fDevice->context(); | 88 GrContext* ctx = fDevice->context(); |
89 desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag; | 89 desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag; |
(...skipping 12 matching lines...) Expand all Loading... |
102 image = sk_make_sp<SkImage_Gpu>(info.width(), info.height(), kNeedNewIma
geUniqueID, | 102 image = sk_make_sp<SkImage_Gpu>(info.width(), info.height(), kNeedNewIma
geUniqueID, |
103 info.alphaType(), tex, budgeted); | 103 info.alphaType(), tex, budgeted); |
104 } | 104 } |
105 return image; | 105 return image; |
106 } | 106 } |
107 | 107 |
108 // Create a new render target and, if necessary, copy the contents of the old | 108 // Create a new render target and, if necessary, copy the contents of the old |
109 // render target into it. Note that this flushes the SkGpuDevice but | 109 // render target into it. Note that this flushes the SkGpuDevice but |
110 // doesn't force an OpenGL flush. | 110 // doesn't force an OpenGL flush. |
111 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 111 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
112 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 112 GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget(); |
113 // are we sharing our render target with the image? Note this call should ne
ver create a new | 113 // are we sharing our render target with the image? Note this call should ne
ver create a new |
114 // image because onCopyOnWrite is only called when there is a cached image. | 114 // image because onCopyOnWrite is only called when there is a cached image. |
115 sk_sp<SkImage> image(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique))
; | 115 sk_sp<SkImage> image(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique))
; |
116 SkASSERT(image); | 116 SkASSERT(image); |
117 if (rt->asTexture() == as_IB(image)->peekTexture()) { | 117 if (rt->asTexture() == as_IB(image)->peekTexture()) { |
118 this->fDevice->replaceDrawContext(SkSurface::kRetain_ContentChangeMode =
= mode); | 118 this->fDevice->replaceDrawContext(SkSurface::kRetain_ContentChangeMode =
= mode); |
119 SkTextureImageApplyBudgetedDecision(image.get()); | 119 SkTextureImageApplyBudgetedDecision(image.get()); |
120 } else if (kDiscard_ContentChangeMode == mode) { | 120 } else if (kDiscard_ContentChangeMode == mode) { |
121 this->SkSurface_Gpu::onDiscard(); | 121 this->SkSurface_Gpu::onDiscard(); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 void SkSurface_Gpu::onDiscard() { | 125 void SkSurface_Gpu::onDiscard() { |
126 fDevice->accessDrawContext()->discard(); | 126 fDevice->accessDrawContext()->discard(); |
127 } | 127 } |
128 | 128 |
129 void SkSurface_Gpu::onPrepareForExternalIO() { | 129 void SkSurface_Gpu::onPrepareForExternalIO() { |
130 fDevice->accessRenderTarget()->prepareForExternalIO(); | 130 fDevice->flush(); |
131 } | 131 } |
132 | 132 |
133 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
134 | 134 |
135 sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target, | 135 sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target, |
136 const SkSurfaceProps* props)
{ | 136 const SkSurfaceProps* props)
{ |
137 sk_sp<SkGpuDevice> device( | 137 sk_sp<SkGpuDevice> device( |
138 SkGpuDevice::Make(sk_ref_sp(target), props, SkGpuDevice::kUninit_InitCon
tents)); | 138 SkGpuDevice::Make(sk_ref_sp(target), props, SkGpuDevice::kUninit_InitCon
tents)); |
139 if (!device) { | 139 if (!device) { |
140 return nullptr; | 140 return nullptr; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 205 } |
206 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props, | 206 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props, |
207 SkGpuDevice::kUninit_InitContent
s)); | 207 SkGpuDevice::kUninit_InitContent
s)); |
208 if (!device) { | 208 if (!device) { |
209 return nullptr; | 209 return nullptr; |
210 } | 210 } |
211 return sk_make_sp<SkSurface_Gpu>(std::move(device)); | 211 return sk_make_sp<SkSurface_Gpu>(std::move(device)); |
212 } | 212 } |
213 | 213 |
214 #endif | 214 #endif |
OLD | NEW |