| 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" |
| 11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" |
| 12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
| 13 #include "SkImage_Gpu.h" | 13 #include "SkImage_Gpu.h" |
| 14 #include "SkImagePriv.h" | 14 #include "SkImagePriv.h" |
| 15 #include "SkSurface_Base.h" | 15 #include "SkSurface_Base.h" |
| 16 | 16 |
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 | 18 |
| 19 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| 20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) | 20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) |
| 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 GrBackendObject SkSurface_Gpu::onGetTextureHandle(TextureHandleAccess access) { | 29 static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, |
| 30 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 30 SkSurface::BackendHandleAc
cess access) { |
| 31 GrRenderTarget* rt = surface->getDevice()->accessRenderTarget(); |
| 31 switch (access) { | 32 switch (access) { |
| 32 case kFlushRead_TextureHandleAccess: | 33 case SkSurface::kFlushRead_BackendHandleAccess: |
| 33 rt->prepareForExternalRead(); // todo: rename to prepareForExterna
lAccess() | 34 rt->prepareForExternalRead(); // todo: rename to prepareForExterna
lAccess() |
| 34 break; | 35 break; |
| 35 case kFlushWrite_TextureHandleAccess: | 36 case SkSurface::kFlushWrite_BackendHandleAccess: |
| 36 case kDiscardWrite_TextureHandleAccess: | 37 case SkSurface::kDiscardWrite_BackendHandleAccess: |
| 37 // for now we don't special-case on Discard, but we may in the futur
e. | 38 // for now we don't special-case on Discard, but we may in the futur
e. |
| 38 this->notifyContentWillChange(kRetain_ContentChangeMode); | 39 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMod
e); |
| 39 rt->flushWrites(); | 40 rt->flushWrites(); |
| 40 break; | 41 break; |
| 41 } | 42 } |
| 42 return rt->asTexture()->getTextureHandle(); | 43 return rt; |
| 44 } |
| 45 |
| 46 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { |
| 47 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
| 48 if (rt->asTexture()) { |
| 49 return rt->asTexture()->getTextureHandle(); |
| 50 } else { |
| 51 return NULL; |
| 52 } |
| 53 } |
| 54 |
| 55 bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleA
ccess access) { |
| 56 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); |
| 57 *obj = rt->getRenderTargetHandle(); |
| 58 return true; |
| 43 } | 59 } |
| 44 | 60 |
| 45 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 61 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 46 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 62 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
| 47 // When we think this works... | 63 // When we think this works... |
| 48 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | 64 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
| 49 | 65 |
| 50 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); | 66 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); |
| 51 } | 67 } |
| 52 | 68 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 148 } |
| 133 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, | 149 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, |
| 134 SkGpuDevice::kUninit_In
itContents)); | 150 SkGpuDevice::kUninit_In
itContents)); |
| 135 if (!device) { | 151 if (!device) { |
| 136 return NULL; | 152 return NULL; |
| 137 } | 153 } |
| 138 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 154 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 139 } | 155 } |
| 140 | 156 |
| 141 #endif | 157 #endif |
| OLD | NEW |