Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 * | |
| 8 */ | |
| 9 | |
| 10 #include "BaseExample.h" | |
| 11 | |
| 12 #include "gl/GrGLInterface.h" | |
| 13 #include "SkGpuDevice.h" | |
| 14 | |
| 15 BaseExample::BaseExample(void* hWnd, int argc, char** argv) | |
| 16 : INHERITED(hWnd) | |
| 17 { | |
| 18 this->setConfig(SkBitmap::kARGB_8888_Config); | |
| 19 this->setVisibleP(true); | |
| 20 this->setClipToBounds(false); | |
| 21 | |
| 22 // Software rendering by default | |
| 23 fType = kRaster_DeviceType; | |
|
caryclark
2013/06/10 15:48:40
setupBackend also sets fType -- pick one or the ot
sglez
2013/06/11 04:24:38
Removed this and also the call to setupBackend bel
| |
| 24 | |
| 25 setupBackend(fType); | |
| 26 } | |
| 27 | |
| 28 BaseExample::~BaseExample() { | |
| 29 if (fType == kGPU_DeviceType) { | |
|
caryclark
2013/06/10 15:48:40
This style is OK and we (Skia) are not very consis
sglez
2013/06/11 04:24:38
Actually I have been trying to keep to that style,
| |
| 30 SkSafeUnref(fContext); | |
| 31 SkSafeUnref(fInterface); | |
| 32 SkSafeUnref(fRenderTarget); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void BaseExample::setupBackend(DeviceType type) { | |
| 37 fType = type; | |
| 38 if(type == kGPU_DeviceType) { | |
|
caryclark
2013/06/10 15:48:40
for long blocks like this, I'd rather see
if (kGP
| |
| 39 AttachmentInfo attachmentInfo; | |
| 40 bool result = attach(kNativeGL_BackEndType, 0 /*msaa*/, &attachmentInfo) ; | |
| 41 | |
| 42 if (false == result) { | |
| 43 SkDebugf("Not possible to create GL backend. Defaulting to raster.") ; | |
| 44 fType = kRaster_DeviceType; | |
| 45 detach(); | |
| 46 return; | |
|
caryclark
2013/06/10 15:48:40
does the caller need to know that this failed? (e.
sglez
2013/06/11 04:24:38
The caller would probably like to know this.
Chan
| |
| 47 } | |
| 48 | |
| 49 const GrGLInterface* interface = GrGLCreateNativeInterface(); | |
| 50 fInterface = const_cast<GrGLInterface*>(interface); | |
|
caryclark
2013/06/10 15:48:40
Throwing away a const is a red flag. Either the in
sglez
2013/06/11 04:24:38
Sorry about the const_cast, fixed by setting the c
| |
| 51 SkASSERT(NULL != interface); | |
| 52 | |
| 53 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interf ace); | |
| 54 SkASSERT(NULL != fContext); | |
| 55 | |
| 56 GrBackendRenderTargetDesc desc; | |
| 57 desc.fWidth = SkScalarRound(width()); | |
| 58 desc.fHeight = SkScalarRound(height()); | |
| 59 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 60 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | |
| 61 desc.fSampleCnt = attachmentInfo.fSampleCount; | |
| 62 desc.fStencilBits = attachmentInfo.fStencilBits; | |
| 63 | |
| 64 GrGLint buffer; | |
| 65 interface->fGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer); | |
| 66 desc.fRenderTargetHandle = buffer; | |
| 67 | |
| 68 fRenderTarget = fContext->wrapBackendRenderTarget(desc); | |
| 69 | |
| 70 fContext->setRenderTarget(fRenderTarget); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 SkCanvas* BaseExample::createCanvas() { | |
| 75 if (fType == kGPU_DeviceType && | |
| 76 NULL != fContext && NULL != fRenderTarget) { | |
|
caryclark
2013/06/10 15:48:40
indent by 4 more so it doesn't look like the body
caryclark
2013/06/10 15:48:40
When can fContext be NULL?
If fRenderTarget retur
sglez
2013/06/11 04:24:38
Done.
sglez
2013/06/11 04:24:38
The fContext is just a precaution.
You are right.
| |
| 77 SkAutoTUnref<SkDevice> device(new SkGpuDevice(fContext, fRenderTarget)); | |
| 78 return new SkCanvas(device); | |
| 79 } else { | |
| 80 return INHERITED::createCanvas(); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 void BaseExample::draw(SkCanvas* canvas) { | |
| 85 if (getDeviceType() == kGPU_DeviceType) { | |
| 86 present(); | |
|
caryclark
2013/06/10 15:48:40
When draw() is overridden by a child, should prese
sglez
2013/06/11 04:24:38
present() should be called at the end. It is a buf
| |
| 87 } | |
| 88 } | |
| 89 | |
| OLD | NEW |