Chromium Code Reviews| 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 break; | 34 break; |
| 34 case kFlushWrite_TextureHandleAccess: | 35 case SkSurface::kFlushWrite_BackendHandleAccess: |
| 35 case kDiscardWrite_TextureHandleAccess: | 36 case SkSurface::kDiscardWrite_BackendHandleAccess: |
| 36 // for now we don't special-case on Discard, but we may in the futur e. | 37 // for now we don't special-case on Discard, but we may in the futur e. |
| 37 this->notifyContentWillChange(kRetain_ContentChangeMode); | 38 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMod e); |
| 38 // legacy: need to dirty the bitmap's genID in our device (curse it) | 39 // legacy: need to dirty the bitmap's genID in our device (curse it) |
| 39 fDevice->fLegacyBitmap.notifyPixelsChanged(); | 40 surface->getDevice()->accessBitmap(false).notifyPixelsChanged(); |
| 40 break; | 41 break; |
| 41 } | 42 } |
| 42 rt->prepareForExternalIO(); | 43 rt->prepareForExternalIO(); |
| 43 return rt->asTexture()->getTextureHandle(); | 44 return rt; |
| 45 } | |
| 46 | |
| 47 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { | |
| 48 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); | |
| 49 if (rt->asTexture()) { | |
|
bsalomon
2015/07/08 17:21:46
save var rather than double call?
| |
| 50 return rt->asTexture()->getTextureHandle(); | |
| 51 } | |
| 52 return 0; | |
| 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; | |
| 44 } | 59 } |
| 45 | 60 |
| 46 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 61 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 47 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 62 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
| 48 // When we think this works... | 63 // When we think this works... |
| 49 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | 64 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
| 50 | 65 |
| 51 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); | 66 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); |
| 52 } | 67 } |
| 53 | 68 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 166 } |
| 152 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, | 167 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, |
| 153 SkGpuDevice::kUninit_In itContents)); | 168 SkGpuDevice::kUninit_In itContents)); |
| 154 if (!device) { | 169 if (!device) { |
| 155 return NULL; | 170 return NULL; |
| 156 } | 171 } |
| 157 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 172 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 158 } | 173 } |
| 159 | 174 |
| 160 #endif | 175 #endif |
| OLD | NEW |