| 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) { |
| 30 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 31 switch (access) { |
| 32 case kFlushRead_TextureHandleAccess: |
| 33 rt->prepareForExternalRead(); // todo: rename to prepareForExterna
lAccess() |
| 34 break; |
| 35 case kFlushWrite_TextureHandleAccess: |
| 36 this->notifyContentWillChange(kRetain_ContentChangeMode); |
| 37 rt->flushWrites(); |
| 38 break; |
| 39 case kDiscardWrite_TextureHandleAccess: |
| 40 this->notifyContentWillChange(kDiscard_ContentChangeMode); |
| 41 rt->discard(); |
| 42 break; |
| 43 } |
| 44 return rt->asTexture()->getTextureHandle(); |
| 45 } |
| 46 |
| 29 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 47 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 30 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 48 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
| 31 // When we think this works... | 49 // When we think this works... |
| 32 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | 50 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
| 33 | 51 |
| 34 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); | 52 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); |
| 35 } | 53 } |
| 36 | 54 |
| 37 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 55 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
| 38 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 56 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 134 } |
| 117 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, | 135 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, |
| 118 SkGpuDevice::kUninit_In
itContents)); | 136 SkGpuDevice::kUninit_In
itContents)); |
| 119 if (!device) { | 137 if (!device) { |
| 120 return NULL; | 138 return NULL; |
| 121 } | 139 } |
| 122 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 140 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 123 } | 141 } |
| 124 | 142 |
| 125 #endif | 143 #endif |
| OLD | NEW |