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 } |
43 return rt; | |
44 } | |
45 | |
46 GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { | |
47 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); | |
42 return rt->asTexture()->getTextureHandle(); | 48 return rt->asTexture()->getTextureHandle(); |
bsalomon
2015/06/30 15:49:58
Eek... this is an existing bug I should have caugh
| |
43 } | 49 } |
44 | 50 |
51 bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleA ccess access) { | |
52 GrRenderTarget* rt = prepare_rt_for_external_access(this, access); | |
53 *obj = rt->getRenderTargetHandle(); | |
54 return true; | |
55 } | |
56 | |
45 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 57 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
46 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 58 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
47 // When we think this works... | 59 // When we think this works... |
48 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | 60 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
49 | 61 |
50 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); | 62 return SkNEW_ARGS(SkCanvas, (fDevice, flags)); |
51 } | 63 } |
52 | 64 |
53 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 65 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
54 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 66 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 144 } |
133 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget (), props, | 145 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget (), props, |
134 SkGpuDevice::kUninit_In itContents)); | 146 SkGpuDevice::kUninit_In itContents)); |
135 if (!device) { | 147 if (!device) { |
136 return NULL; | 148 return NULL; |
137 } | 149 } |
138 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 150 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
139 } | 151 } |
140 | 152 |
141 #endif | 153 #endif |
OLD | NEW |