| 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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 : INHERITED(device->width(), device->height(), &device->surfaceProps()) | 21 : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
| 22 , fDevice(SkRef(device)) { | 22 , fDevice(SkRef(device)) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 SkSurface_Gpu::~SkSurface_Gpu() { | 25 SkSurface_Gpu::~SkSurface_Gpu() { |
| 26 fDevice->unref(); | 26 fDevice->unref(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, | 29 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, |
| 30 SkSurface::BackendHandleAc
cess access) { | 30 SkSurface::BackendHandleAc
cess access) { |
| 31 GrRenderTarget* rt = surface->getDevice()->accessRenderTarget(); | |
| 32 switch (access) { | 31 switch (access) { |
| 33 case SkSurface::kFlushRead_BackendHandleAccess: | 32 case SkSurface::kFlushRead_BackendHandleAccess: |
| 34 break; | 33 break; |
| 35 case SkSurface::kFlushWrite_BackendHandleAccess: | 34 case SkSurface::kFlushWrite_BackendHandleAccess: |
| 36 case SkSurface::kDiscardWrite_BackendHandleAccess: | 35 case SkSurface::kDiscardWrite_BackendHandleAccess: |
| 37 // for now we don't special-case on Discard, but we may in the futur
e. | 36 // for now we don't special-case on Discard, but we may in the futur
e. |
| 38 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMod
e); | 37 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMod
e); |
| 39 // legacy: need to dirty the bitmap's genID in our device (curse it) | 38 // legacy: need to dirty the bitmap's genID in our device (curse it) |
| 40 surface->getDevice()->accessBitmap(false).notifyPixelsChanged(); | 39 surface->getDevice()->accessBitmap(false).notifyPixelsChanged(); |
| 41 break; | 40 break; |
| 42 } | 41 } |
| 42 |
| 43 // Grab the render target *after* firing notifications, as it may get switch
ed if CoW kicks in. |
| 44 GrRenderTarget* rt = surface->getDevice()->accessRenderTarget(); |
| 43 rt->prepareForExternalIO(); | 45 rt->prepareForExternalIO(); |
| 44 return rt; | 46 return rt; |
| 45 } | 47 } |
| 46 | 48 |
| 47 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { | 49 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { |
| 48 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); | 50 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
| 49 GrTexture* texture = rt->asTexture(); | 51 GrTexture* texture = rt->asTexture(); |
| 50 if (texture) { | 52 if (texture) { |
| 51 return texture->getTextureHandle(); | 53 return texture->getTextureHandle(); |
| 52 } | 54 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 169 } |
| 168 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, | 170 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, |
| 169 SkGpuDevice::kUninit_In
itContents)); | 171 SkGpuDevice::kUninit_In
itContents)); |
| 170 if (!device) { | 172 if (!device) { |
| 171 return NULL; | 173 return NULL; |
| 172 } | 174 } |
| 173 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 175 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 174 } | 176 } |
| 175 | 177 |
| 176 #endif | 178 #endif |
| OLD | NEW |