Better fix for changing the viewport in sample app.
Create a platform description and base the size on the SkWindow
in order to create a RenderTarget, which results in changing the
viewport. This allows us to use only GR calls.
In the Android sample app, fix the problem where nothing is drawn
in the first frame, and default to drawing in GL.
Reviewed at http://codereview.appspot.com/4642043/
git-svn-id: http://skia.googlecode.com/svn/trunk@1615 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 8d5e13d..455559c 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -15,9 +15,7 @@
#include "GrContext.h"
#include "SkTypeface.h"
-#ifdef ANDROID
- #include "gl2.h"
-#endif
+#include "GrGLInterface.h"
#define TEST_GPIPEx
@@ -684,7 +682,20 @@
const SkBitmap& bitmap = device->accessBitmap(true);
GrRenderTarget* renderTarget;
- renderTarget = fGrContext->createRenderTargetFrom3DApiState();
+
+ GrPlatformSurfaceDesc desc;
+ desc.reset();
+ desc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType;
+ desc.fWidth = bitmap.width();
+ desc.fHeight = bitmap.height();
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ desc.fStencilBits = 8;
+ GrGLint buffer;
+ GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer);
+ desc.fPlatformRenderTarget = buffer;
+
+ renderTarget = static_cast<GrRenderTarget*>(
+ fGrContext->createPlatformSurface(desc));
fGpuCanvas = new SkGpuCanvas(fGrContext, renderTarget);
renderTarget->unref();
@@ -1323,12 +1334,8 @@
fZoomCenterX = SkScalarHalf(this->width());
fZoomCenterY = SkScalarHalf(this->height());
-#if defined(SK_BUILD_FOR_UNIX) || defined(ANDROID)
- if (fGrContext) {
- glViewport(0, 0, SkScalarRound(this->width()),
- SkScalarRound(this->height()));
- fGrContext->resetContext();
- }
+#ifdef ANDROID
+ postInvalDelay(this->getSinkID());
#endif
this->updateTitle(); // to refresh our config
}