ec3ed6a5eb
I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
|
|
/*
|
|
* Copyright 2011 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#include "ReaderView.h"
|
|
#include "SkGPipe.h"
|
|
#include "SkCanvas.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#define FILE_PATH "/Users/yangsu/Code/test/test.a"
|
|
ReaderView::ReaderView() {
|
|
fBGColor = 0xFFDDDDDD;
|
|
fFilePos = 0;
|
|
fBufferBitmaps[0].setConfig(SkBitmap::kARGB_8888_Config, 640, 480);
|
|
fBufferBitmaps[0].allocPixels(NULL);
|
|
fBufferBitmaps[1].setConfig(SkBitmap::kARGB_8888_Config, 640, 480);
|
|
fBufferBitmaps[1].allocPixels(NULL);
|
|
fFront = 0;
|
|
fBack = 1;
|
|
}
|
|
|
|
void ReaderView::draw(SkCanvas* canvas) {
|
|
canvas->drawColor(fBGColor);
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
//Create a temporary canvas and reader object that draws into the back
|
|
//bitmap so that the incremental changes or incomplete reads are not shown
|
|
//on screen
|
|
SkCanvas bufferCanvas(fBufferBitmaps[fBack]);
|
|
SkGPipeReader reader(&bufferCanvas);
|
|
|
|
//The file specified by FILE_PATH MUST exist
|
|
FILE* f = fopen(FILE_PATH, "rb");
|
|
SkASSERT(f != NULL);
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
int size = ftell(f) * sizeof(char);
|
|
if (size <= fFilePos) {
|
|
fFilePos = 0;
|
|
}
|
|
|
|
//Resume from the last read location
|
|
fseek(f, fFilePos, SEEK_SET);
|
|
int toBeRead = size - fFilePos;
|
|
if (size > 0 && toBeRead > 0) {
|
|
void* block = sk_malloc_throw(toBeRead);
|
|
fread(block, 1, toBeRead, f);
|
|
|
|
size_t bytesRead;
|
|
SkGPipeReader::Status fStatus = reader.playback(block, toBeRead, &bytesRead);
|
|
SkASSERT(SkGPipeReader::kError_Status != fStatus);
|
|
SkASSERT(toBeRead >= bytesRead);
|
|
|
|
//if the reader reaches a done verb, a frame is complete.
|
|
//Update the file location and swap the front and back bitmaps to show
|
|
//the new frame
|
|
if (SkGPipeReader::kDone_Status == fStatus) {
|
|
fFilePos += bytesRead;
|
|
fFront = fFront ^ 0x1;
|
|
fBack = fBack ^ 0x1;
|
|
}
|
|
sk_free(block);
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
//the front bitmap is always drawn
|
|
canvas->drawBitmap(fBufferBitmaps[fFront], 0, 0, NULL);
|
|
this->inval(NULL);
|
|
} |